use of org.graalvm.nativeimage.c.type.CCharPointer in project graal by oracle.
the class JavaUtilZipSubstitutions method updateByteBuffer.
// Adler32.c-Java_java_util_zip_Adler32_updateByteBuffer(JNIEnv *env, jclass cls, jint adler,
@Substitute
private static int updateByteBuffer(int adler, long addr, int off, int len) {
CCharPointer bytes = WordFactory.pointer(addr);
CCharPointer bytesAtOffset = bytes.addressOf(off);
return (int) ZLib.adler32(WordFactory.unsigned(adler), bytesAtOffset, len).rawValue();
}
use of org.graalvm.nativeimage.c.type.CCharPointer in project graal by oracle.
the class RealLog method rawString.
private void rawString(char[] value) {
int length = value.length;
/*
* Stack allocation needs an allocation size that is a compile time constant, so we split
* the string up in multiple chunks and write them separately.
*/
final int chunkSize = 256;
final CCharPointer bytes = StackValue.get(chunkSize);
int chunkOffset = 0;
while (length > 0) {
int chunkLength = Math.min(length, chunkSize);
for (int i = 0; i < chunkLength; i++) {
char c = value[chunkOffset + i];
bytes.write(i, (byte) c);
}
rawBytes(bytes, WordFactory.unsigned(chunkLength));
chunkOffset += chunkLength;
length -= chunkLength;
}
}
use of org.graalvm.nativeimage.c.type.CCharPointer in project graal by oracle.
the class CInterfaceTutorial method javaEntryPoint2.
@CEntryPoint(name = "java_entry_point2")
protected static void javaEntryPoint2(@SuppressWarnings("unused") IsolateThread thread, Substruct1 s1, Substruct2 s2) {
System.out.println("*** In Java, demonstrating inheritance with @CStruct class");
CCharPointer tp1 = s1.typePtr();
CCharPointer tp2 = s2.header().typePtr();
System.out.println("tp1 = 0x" + Long.toHexString(tp1.rawValue()) + " tp2 = 0x" + Long.toHexString(tp2.rawValue()));
System.out.println("&s1.header = 0x" + Long.toHexString(s1.header().rawValue()) + " &s2.header = 0x" + Long.toHexString(s2.header().rawValue()));
System.out.println("s1.f1 = " + s1.f1() + " s2.f2 = " + s2.f1());
System.out.println("&s1.f1 = 0x" + Long.toHexString(s1.addressOff1().rawValue()));
System.out.println("*&s1.f1 = " + s1.addressOff1().read());
System.out.println("offset_of(s1.f1) = " + s1.offsetOff1());
System.out.println("s1.header.type = " + s1.type() + " ((Header) s2).type = " + s2.header().type());
System.out.println("*** In Java, demonstrating @CFieldOffset");
System.out.println("offset_of(s1.header) = " + Substruct1.offsetOfHeader());
System.out.println("offset_of(s2.header) = " + s2.offsetOfHeader());
System.out.println("offset_of(s2.f1) = " + s2.offsetOff1().rawValue());
/*
* Accessing elements of an array of struct. Say that s1 is the first element of subdata_t
* s[10].
*/
// ps1 = &s[0]
Substruct1 ps1 = s1.addressOf(0);
// ps2 = &s[1]
Substruct1 ps2 = s1.addressOf(1);
long s = ps2.rawValue() - ps1.rawValue();
System.out.print("sizeof(s1) =" + SizeOf.get(Substruct1.class));
System.out.print(" s1 = 0x" + Long.toHexString(s1.rawValue()));
System.out.print(" ps1 = 0x" + Long.toHexString(ps1.rawValue()));
System.out.println(" ps2 = 0x" + Long.toHexString(ps2.rawValue()));
System.out.println(" ps2 - ps1 " + (s == SizeOf.get(Substruct1.class) ? "=" : "!=") + " sizeof(substruct1)");
}
use of org.graalvm.nativeimage.c.type.CCharPointer in project graal by oracle.
the class PolyglotNativeAPI method polyglot_available_languages.
@CEntryPoint(name = "polyglot_available_languages")
public static PolyglotStatus polyglot_available_languages(IsolateThread isolate_thread, PolyglotEnginePointer engine_handle, CCharPointerPointer lang_array) {
return withHandledErrors(() -> {
String[] langs = sortedLangs(ObjectHandles.getGlobal().get(engine_handle));
for (int i = 0; i < langs.length; i++) {
CCharPointer name = lang_array.read(i);
CTypeConversion.toCString(langs[i], UTF8_CHARSET, name, WordFactory.unsigned(langs[i].getBytes(UTF8_CHARSET).length));
}
});
}
use of org.graalvm.nativeimage.c.type.CCharPointer in project graal by oracle.
the class PolyglotNativeAPI method handleThrowable.
private static PolyglotStatus handleThrowable(Throwable t) {
PolyglotStatus errorCode = t instanceof PolyglotNativeAPIError ? ((PolyglotNativeAPIError) t).getCode() : polyglot_generic_failure;
String message = t.getMessage();
PolyglotExtendedErrorInfo unmanagedErrorInfo = UnmanagedMemory.malloc(SizeOf.get(PolyglotExtendedErrorInfo.class));
unmanagedErrorInfo.setErrorCode(errorCode.getCValue());
CCharPointerHolder holder = CTypeConversion.toCString(message);
CCharPointer value = holder.get();
unmanagedErrorInfo.setErrorMessage(value);
errorInfo.set(new ErrorInfoHolder(unmanagedErrorInfo, holder));
return errorCode;
}
Aggregations