package lwjgl.tests; import java.nio.ByteBuffer; import org.lwjgl.*; import org.lwjgl.system.*; import org.lwjgl.llvm.*; import static org.lwjgl.system.MemoryStack.*; import static org.lwjgl.system.MemoryUtil.*; import static org.lwjgl.llvm.LLVMCore.*; import static org.lwjgl.llvm.ClangIndex.*; public class CXStringTest { public static void main(String[] args) { if (Configuration.LLVM_LIBRARY_NAME.get() == null) { throw new IllegalStateException("Please configure the LLVM shared library path with -Dorg.lwjgl.llvm.libname="); } if (Configuration.LLVM_CLANG_LIBRARY_NAME.get() == null) { throw new IllegalStateException("Please configure the clang shared library path with -Dorg.lwjgl.llvm.clang.libname="); } //needed this to force loading of llvm lib before clang System.out.println("LLVM is multithreaded? " + LLVMIsMultithreaded()); System.out.println("Got past loading LLVM and Clang native libs... WooHoo!"); clang_enableStackTraces(); CXString cxstr = null; try (MemoryStack stack = stackPush()) { String testString = "Some Test String"; ByteBuffer strbuf = stack.ASCII(testString); long strbufAddress = memAddress(strbuf); cxstr = CXString.callocStack(stack); memPutLong(cxstr.address(), strbufAddress); String garbage_cstr = clang_getCString(cxstr); System.out.println("Got garbage java String from cxstring using clang_getCString: " + garbage_cstr + ". garbage_cst == testString? "+ (garbage_cstr.equals(testString))); String cstr = memUTF8Safe(memGetAddress(cxstr.address())); System.out.println("Got correct java String from cxstring using ptr->ptr access: " + cstr + ". cst == testString? "+ (cstr.equals(testString))); } clang_disposeString(cxstr); } }