public synchronized void fail() throws Fail { int err = GetLastError(); Memory buffer = new Memory(2048); int res = FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, null, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, (int) buffer.size(), null); log = log && log( 1, "fail() %s, Windows GetLastError()= %d, %s\n", lineno(1), err, buffer.getString(0, true)); // FIXME here convert from Windows error code to 'posix' error code Fail f = new Fail(); throw f; }
public static File getTempDir() { Memory buf = new Memory(1024); if (Kernel32.INSTANCE.GetTempPathW(1024, buf) != 0) { return new File(buf.getString(0, true)); } else { return null; } }
/** * String representation of the buffer. * * @return Unicode string. */ public String getString() { byte[] data = Buffer.getByteArray(0, Length); if (data.length < 2 || data[data.length - 1] != 0) { Memory newdata = new Memory(data.length + 2); newdata.write(0, data, 0, data.length); return newdata.getString(0, true); } return Buffer.getString(0, true); }
/** Returns the context of this program */ public synchronized CLProgram build() throws CLBuildException { if (built) throw new IllegalThreadStateException("Program was already built !"); String contentSignature = null; File cacheFile = null; boolean readBinaries = false; if (isCached()) { try { contentSignature = computeCacheSignature(); byte[] sha = java.security.MessageDigest.getInstance("MD5") .digest(contentSignature.getBytes(textEncoding)); StringBuilder shab = new StringBuilder(); for (byte b : sha) shab.append(Integer.toHexString(b & 0xff)); String hash = shab.toString(); cacheFile = new File(JavaCL.userCacheDir, hash); if (cacheFile.exists()) { Pair<Map<CLDevice, byte[]>, String> bins = readBinaries( Arrays.asList(getDevices()), contentSignature, new FileInputStream(cacheFile)); setBinaries(bins.getFirst()); this.source = bins.getSecond(); assert log(Level.INFO, "Read binaries cache from '" + cacheFile + "'"); readBinaries = true; } } catch (Exception ex) { assert log(Level.WARNING, "Failed to load cached program", ex); entity = null; } } if (entity == null) allocate(); Runnable deleteTempFiles = null; if (!readBinaries) try { deleteTempFiles = copyIncludesToTemporaryDirectory(); } catch (IOException ex) { throw new CLBuildException(this, ex.toString(), Collections.EMPTY_LIST); } int nDevices = devices.length; cl_device_id[] deviceIds = null; if (nDevices != 0) { deviceIds = new cl_device_id[nDevices]; for (int i = 0; i < nDevices; i++) deviceIds[i] = devices[i].getEntity(); } int err = CL.clBuildProgram( getEntity(), nDevices, deviceIds, readBinaries ? null : getOptionsString(), null, null); // int err = CL.clBuildProgram(getEntity(), 0, null, getOptionsString(), null, null); if (err != CL_SUCCESS) { // BUILD_PROGRAM_FAILURE) { NativeSizeByReference len = new NativeSizeByReference(); int bufLen = 2048 * 32; // TODO find proper size Memory buffer = new Memory(bufLen); HashSet<String> errs = new HashSet<String>(); if (deviceIds == null) { error( CL.clGetProgramBuildInfo( getEntity(), null, CL_PROGRAM_BUILD_LOG, toNS(bufLen), buffer, len)); String s = buffer.getString(0); errs.add(s); } else for (cl_device_id device : deviceIds) { error( CL.clGetProgramBuildInfo( getEntity(), device, CL_PROGRAM_BUILD_LOG, toNS(bufLen), buffer, len)); String s = buffer.getString(0); errs.add(s); } throw new CLBuildException(this, "Compilation failure : " + errorString(err), errs); } built = true; if (deleteTempFiles != null) deleteTempFiles.run(); if (isCached() && !readBinaries) { JavaCL.userCacheDir.mkdirs(); try { Map<CLDevice, byte[]> binaries = getBinaries(); if (!binaries.isEmpty()) { writeBinaries( getBinaries(), getSource(), contentSignature, new FileOutputStream(cacheFile)); assert log(Level.INFO, "Wrote binaries cache to '" + cacheFile + "'"); } } catch (Exception ex) { new IOException("[JavaCL] Failed to cache program", ex).printStackTrace(); } } return this; }
// TODO: this method isn't very safe to leave public, perhaps some // setPropertyData[String/UInt32/etc.] methods would be better // hansi: i like having as much as possible public. it's nice for people who know what they're // doing. @SuppressWarnings("unchecked") public static <T> T getPropertyDataAdvanced( final EdsBaseRef ref, final EdsPropertyID property, final long param) throws IllegalArgumentException, IllegalStateException { final int size = (int) CanonUtils.getPropertySize(ref, property, param); final EdsDataType type = CanonUtils.getPropertyType(ref, property, param); final Memory memory = new Memory(size > 0 ? size : 1); final EdsError err = CanonUtils.getPropertyData(ref, property, param, size, memory); if (err == EdsError.EDS_ERR_OK) { switch (type) { case kEdsDataType_Unknown: // Unknown return null; case kEdsDataType_String: // EdsChar[] return (T) memory.getString(0); case kEdsDataType_Int8: // EdsInt8 case kEdsDataType_UInt8: // EdsUInt8 return (T) Byte.valueOf(memory.getByte(0)); case kEdsDataType_Int16: // EdsInt16 case kEdsDataType_UInt16: // EdsUInt16 return (T) Short.valueOf(memory.getShort(0)); case kEdsDataType_Int32: // EdsInt32 case kEdsDataType_UInt32: // EdsUInt32 return (T) Long.valueOf(memory.getNativeLong(0).longValue()); case kEdsDataType_Int64: // EdsInt64 case kEdsDataType_UInt64: // EdsUInt64 return (T) Long.valueOf(memory.getLong(0)); case kEdsDataType_Float: // EdsFloat return (T) Float.valueOf(memory.getFloat(0)); case kEdsDataType_Double: // EdsDouble return (T) Double.valueOf(memory.getDouble(0)); case kEdsDataType_ByteBlock: // Byte Block // TODO: According to API, is either EdsInt8[] or // EdsUInt32[], but perhaps former is a typo or an old value return (T) memory.getIntArray(0, size / 4); case kEdsDataType_Rational: // EdsRational return (T) new EdsRational(memory); case kEdsDataType_Point: // EdsPoint return (T) new EdsPoint(memory); case kEdsDataType_Rect: // EdsRect return (T) new EdsRect(memory); case kEdsDataType_Time: // EdsTime return (T) new EdsTime(memory); case kEdsDataType_FocusInfo: // EdsFocusInfo return (T) new EdsFocusInfo(memory); case kEdsDataType_PictureStyleDesc: // EdsPictureStyleDesc return (T) new EdsPictureStyleDesc(memory); case kEdsDataType_Int8_Array: // EdsInt8[] case kEdsDataType_UInt8_Array: // EdsUInt8[] return (T) memory.getByteArray(0, size); case kEdsDataType_Int16_Array: // EdsInt16[] case kEdsDataType_UInt16_Array: // EdsUInt16[] return (T) memory.getShortArray(0, size / 2); case kEdsDataType_Int32_Array: // EdsInt32[] case kEdsDataType_UInt32_Array: // EdsUInt32[] return (T) memory.getIntArray(0, size / 4); case kEdsDataType_Bool: // EdsBool // TODO: implement case kEdsDataType_Bool_Array: // EdsBool[] // TODO: implement case kEdsDataType_Rational_Array: // EdsRational[] // TODO: implement default: throw new IllegalStateException( type.description() + " (" + type.name() + ") is not currently supported by GetPropertyCommand"); } } throw new IllegalArgumentException( "An error occurred while getting " + property.name() + " data (error " + err.value() + ": " + err.name() + " - " + err.description() + ")"); }