Nick Glencross wrote:

Guys,

As mentioned on the list yesterday I started evaluating ffcall as a way of providing NCI functionality.

I seem to be seeing rather strange, and it's probably a misunderstanding on my part.

I've pinched the GET_NCI_x(n) macros and accompanying get_nci_x functions from nci.c, but they don't seem to be working consistently.

In particular, where I have a signature "pp" I often seem to be getting the same pointer twice.


If the following line is added as line 267 in nci_ffcall.c after applying the patch:

printf ("Pointer is %p\n", nci_args->args[i]._pointer);

and the following script run:

.sub test :main

   .local pmc libnci_test
   libnci_test = loadlib "libnci_test"

   .local pmc nci_cb_C1
   nci_cb_C1 = dlfunc libnci_test, "nci_cb_C1", "vpp"

   .local pmc user_data
   user_data = new .Integer
   user_data = -99

   .local pmc cb
   cb = newsub _call_back
   .local pmc cb_wrapped
   cb_wrapped = new_callback cb, user_data, "iii"

   nci_cb_C1 (user_data, cb_wrapped)

.end

.sub _call_back
       print "Hello world!\n"
.end

then you get

Pointer is 0x84a33d0
Pointer is 0x84a33d0
[probably a segfault!]

while these are meant to be different addresses (corresponding to user_data and cb_wrapped). From what I've seen you get the second address twice.

I must be doing something wrong as it works in nci.c.

Any thoughts would be appreciated as I can't see the wood from the trees anymore,

Cheers,

Nick

p.s. Since posting the patch, I've realised that I probably need another

   Parrot_init_arg_nci(interpreter, &st, nci_args->signature_parrot);

before reading back the values, and probably a 'default' in the switch which steps over skipped items. This only enables one extra test to succeed though.

Reply via email to