libffi and longs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
I've had troubles in the FFI module I'm building when dealing with (unsigned) 
longs, what happens is that the second unsigned long argument never reached 
the function I'm calling with ffi_call.
I've built a small test (attached) to show this particular problem (in the 
hope that the problem would disappear, but that didn't happen). I've checked 
and re-checked how I pass the arguments to ffi_call, I couldn't find anything 
wrong (debugging libffi internals is not easy :( ).
Any hints are helpful.
Thanks.
- -- 
Pupeno: pupeno@xxxxxxxxxx - http://pupeno.com
Reading Science Fiction ? http://sfreaders.com.ar
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCbBHbfW48a9PWGkURAreSAKCQh4GuO5z1oFG+Li7d6wgd/p8JVACeOxbP
Y3VqhfC6N8HIqiREC+pscMs=
=jltr
-----END PGP SIGNATURE-----
#include <stdio.h>

unsigned long uLongSum(unsigned long a, unsigned long b){
	printf("Summing unsigned long %ld to unsigned long %ld. Resulting in %ld.\n", a, b, a + b);
	return a + b;
}

signed long sLongSum(signed long a, signed long b){
	printf("Summing signed long %ld to signed long %ld. Resulting in %ld.\n", a, b, a + b);
	return a + b;
}
CC=gcc

all: libffitarget.so testffi

ffitarget.o: ffitarget.c
	$(CC) -fPIC -Wall -g -ggdb -c ffitarget.c

libffitarget.so: ffitarget.o
	gcc -g -ggdb -shared -Wl,-soname,libffitarget.so.0 -o libffitarget.so ffitarget.o -lc 

testffi: testffi.c
	gcc testffi.c -o testffi -ldl -lffi -g -ggdb
clean:
	-rm libffitarget.so ffitarget.o testffi
#include <stdio.h>
#include <ffi.h>
#include <dlfcn.h>

int main(){
	unsigned long a = 150;
	unsigned long b = 345;
	unsigned long rc;
	void *libHandle;
	void *funcHandle;
	void *values[2];
	ffi_type *args[2];
	ffi_cif cif;

	/* Initialize the argument info vectors */
	args[0] = &ffi_type_ulong;
	args[1] = &ffi_type_ulong;
	values[0] = &a;
	values[1] = &b;

	libHandle = dlopen("./libffitarget.so", RTLD_LAZY);
	funcHandle = dlsym(libHandle, "uLongSum");

	/* Initialize the cif */
	if(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_uint, args) == FFI_OK){
		ffi_call(&cif, funcHandle, &rc, values);
		printf("It returned %ld.\n", rc);
	}

	return 0;
}

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux