On Mon, Aug 24, 2015 at 11:11:32PM +0200, David Naylor wrote: > Hi list, > > Please see the correspondence below from the pypy team about some failing > tests. Specifically, why is test.py producing None whereas test.c is > producing the desired results?
Because dlopen symbol is magic. It is provided by the shared libc.so to satisfy the static linker, but real definition comes from the dynamic linker. The libc.so dlopen() is a null stub. You are asking for the dlopen symbol from libc, which is returned to you in faith, and which cannot load a library for real. While in the C example, you use normal symbol resolution and get the dlopen from the loader. To get a handle to real dlopen with dlopen/dlsym, you should do in C: dlopenX = dlsym(RTLD_DEFAULT, "dlopen"); I briefly looked at the python 2.7.8 documentation for ctypes, but I do not see a way to express this with the module. Most clean way for ctypes to offer the missing functionality would be to provide a phabricated object, access to the symbols of which would do dlsym(RTLD_DEFAULT, XXX) instead of dlsym(some handle, XXX). A complete working C example is below. #include <dlfcn.h> #include <stdio.h> #include <stdlib.h> int main(void) { void *(*dlopen1)(const char *path, int mode); void *libm_handle; dlopen1 = dlsym(RTLD_DEFAULT, "dlopen"); if (dlopen1 == NULL) { fprintf(stderr, "dlsym %s\n", dlerror()); exit(1); } libm_handle = dlopen1("libm.so", RTLD_LOCAL /* why local ? */); if (libm_handle == NULL) { fprintf(stderr, "dlopen1 %s\n", dlerror()); exit(1); } printf("libm.so %p\n", libm_handle); return (0); } _______________________________________________ freebsd-python@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/freebsd-python To unsubscribe, send any mail to "freebsd-python-unsubscr...@freebsd.org"