@@ -394,6 +394,48 @@ Return the current value of the recursion limit, the maximum depth\n\
394394of the Python interpreter stack. This limit prevents infinite\n\
395395recursion from causing an overflow of the C stack and crashing Python." ;
396396
397+ #ifdef HAVE_DLOPEN
398+ static PyObject *
399+ sys_setdlopenflags (PyObject * self , PyObject * args )
400+ {
401+ int new_val ;
402+ PyThreadState * tstate = PyThreadState_Get ();
403+ if (!PyArg_ParseTuple (args , "i:setdlopenflags" , & new_val ))
404+ return NULL ;
405+ if (!tstate )
406+ return NULL ;
407+ tstate -> interp -> dlopenflags = new_val ;
408+ Py_INCREF (Py_None );
409+ return Py_None ;
410+ }
411+
412+ static char setdlopenflags_doc [] =
413+ "setdlopenflags(n) -> None\n\
414+ \n\
415+ Set the flags that will be used for dlopen() calls. Among other\n\
416+ things, this will enable a lazy resolving of symbols when imporing\n\
417+ a module, if called as sys.setdlopenflags(0)\n\
418+ To share symols across extension modules, call as\n\
419+ sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)" ;
420+
421+ static PyObject *
422+ sys_getdlopenflags (PyObject * self , PyObject * args )
423+ {
424+ PyThreadState * tstate = PyThreadState_Get ();
425+ if (!PyArg_ParseTuple (args , ":getdlopenflags" ))
426+ return NULL ;
427+ if (!tstate )
428+ return NULL ;
429+ return PyInt_FromLong (tstate -> interp -> dlopenflags );
430+ }
431+
432+ static char getdlopenflags_doc [] =
433+ "getdlopenflags() -> int\n\
434+ \n\
435+ Return the current value of the flags that are used for dlopen()\n\
436+ calls. The flag constants are defined in the dl module." ;
437+ #endif
438+
397439#ifdef USE_MALLOPT
398440/* Link with -lmalloc (or -lmpc) on an SGI */
399441#include <malloc.h>
@@ -501,6 +543,10 @@ static PyMethodDef sys_methods[] = {
501543 {"exit" , sys_exit , 0 , exit_doc },
502544 {"getdefaultencoding" , sys_getdefaultencoding , 1 ,
503545 getdefaultencoding_doc },
546+ #ifdef HAVE_DLOPEN
547+ {"getdlopenflags" , sys_getdlopenflags , 1 ,
548+ getdlopenflags_doc },
549+ #endif
504550#ifdef COUNT_ALLOCS
505551 {"getcounts" , sys_getcounts , 1 },
506552#endif
@@ -522,6 +568,10 @@ static PyMethodDef sys_methods[] = {
522568 setdefaultencoding_doc },
523569 {"setcheckinterval" , sys_setcheckinterval , 1 ,
524570 setcheckinterval_doc },
571+ #ifdef HAVE_DLOPEN
572+ {"setdlopenflags" , sys_setdlopenflags , 1 ,
573+ setdlopenflags_doc },
574+ #endif
525575 {"setprofile" , sys_setprofile , 0 , setprofile_doc },
526576 {"setrecursionlimit" , sys_setrecursionlimit , 1 ,
527577 setrecursionlimit_doc },
@@ -659,9 +709,11 @@ displayhook() -- print an object to the screen, and save it in __builtin__._\n\
659709excepthook() -- print an exception and its traceback to sys.stderr\n\
660710exc_info() -- return thread-safe information about the current exception\n\
661711exit() -- exit the interpreter by raising SystemExit\n\
712+ getdlopenflags() -- returns flags to be used for dlopen() calls\n\
662713getrefcount() -- return the reference count for an object (plus one :-)\n\
663714getrecursionlimit() -- return the max recursion depth for the interpreter\n\
664715setcheckinterval() -- control how often the interpreter checks for events\n\
716+ setdlopenflags() -- set the flags to be used for dlopen() calls\n\
665717setprofile() -- set the global profiling function\n\
666718setrecursionlimit() -- set the max recursion depth for the interpreter\n\
667719settrace() -- set the global debug tracing function\n\
0 commit comments