Some problems with my Neko/C++ externs for LibJIT

64 views
Skip to first unread message

TopHattedCoder

unread,
Aug 25, 2013, 9:29:29 PM8/25/13
to haxe...@googlegroups.com
Hi all,
I'm working on some LibJIT externs (source here), and they only seem to work Neko, which is odd because I include all the standard C++/Neko headers:
[project/common/ExternalInterface.cpp]
#define IMPLEMENT_API

#if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX)
#define NEKO_COMPATIBLE
#endif

#include <hx/CFFI.h>
#include <jit/jit.h>
Full source is on Github
And the binding:
[libjit/Context.hx]
package libjit;
abstract Context(Dynamic) {
   
public inline function new()
       
this = create_context();
   
public inline function lock():Bool
       
try {
            context_build_start
(this);
           
return true;
       
} catch(e:Dynamic)
           
return false;
   
public inline function unlock():Bool
       
try {
            context_build_end
(this);
           
return true;
       
} catch(e:Dynamic)
           
return false;
   
public inline function destroy():Void
         context_destroy
(this);
   
static var create_context:Void -> Dynamic = Lib.load("jit", "hx_jit_create_context", 0);
   
static var context_build_start:Dynamic -> Void = Lib.load("jit", "hx_jit_context_build_start", 1);
   
static var context_build_end:Dynamic -> Void = Lib.load("jit", "hx_jit_context_build_end", 1);
   
static var context_destroy:Dynamic -> Void = Lib.load("jit", "hx_jit_context_destroy", 1);
}
Now, I'm getting the following error:
Error : Null Function Pointer
Even with -debug, no useful output is generated. Any advice? Thanks.

Cauê Waneck

unread,
Aug 25, 2013, 9:35:38 PM8/25/13
to haxe...@googlegroups.com
It seems that either the ndll / symbol wasn't found by hxcpp, or you're calling a "new Context()" into a static initialization context (e.g. static var ctx = new Context()), which may lead to a wrong static variable initialization order in some cases.


2013/8/25 TopHattedCoder <tophatt...@gmail.com>

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

Hugh

unread,
Aug 26, 2013, 12:51:21 AM8/26/13
to haxe...@googlegroups.com
Hi,
Perhaps the statics of the abstracts are not even getting processed.  You could try putting them in a helper class, like

class ContextHelper // not abstract
{
  static var create_context = ...
}
abstract Context(Dynamic) {
    public inline function new()
    this = ContextHelper.create_context();

You can also try setting HXCPP_LOAD_DEBUG=1 for some cffi logging, and try "trace(context.create_contest)" to see if it is null.

Hugh

Hugh

TopHattedCoder

unread,
Aug 26, 2013, 5:27:15 AM8/26/13
to haxe...@googlegroups.com
If I run the debug build, I get this output (from my cpp.Lib wrapper):
Lib.hx:9: Loading jit.hx_jit_create_context with 0 args
Lib.hx:9: Loading jit.hx_jit_context_build_start with 1 args
Lib.hx:9: Loading jit.hx_jit_context_build_end with 1 args
Lib.hx:9: Loading jit.hx_jit_context_destroy with 1 args
Lib.hx:9: Loading jit.hx_jit_insn_add with 3 args
Lib.hx:9: Loading jit.hx_jit_insn_load with 2 args
Lib.hx:9: Loading jit.hx_jit_insn_store with 3 args
Lib.hx:9: Loading jit.hx_jit_insn_return with 2 args
Called from CFunction
Error : Null Function Pointer
The definition of hx_jit_insn_return looks like this:
value hx_jit_insn_return(value f, value a) {
   
if(val_is_null(f))
        hx_failure
("Function is null");
   
else if(val_is_null(a))
        hx_failure
("Value is null");
   
return alloc_int(jit_insn_return((jit_function_t) val_get_handle(f, k_function), (jit_value_t) val_get_handle(a, k_value)));
}
DEFINE_PRIM
(hx_jit_insn_return, 2);
I'll carry on looking into it.
Reply all
Reply to author
Forward
0 new messages