[Python-checkins] CVS: python/dist/src/Python dynload_shlib.c,2.8,2.8.6.1 pystate.c,2.16.6.1,2.16.6.2 sysmodule.c,2.85.4.1,2.85.4.2

Tim Peters tim_one@users.sourceforge.net
Fri, 20 Jul 2001 23:07:16 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv27169/descr/dist/src/Python

Modified Files:
      Tag: descr-branch
	dynload_shlib.c pystate.c sysmodule.c 
Log Message:
Merge of trunk delta date2001-07-17b to date2001-07-21.  See PLAN.txt.


Index: dynload_shlib.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/dynload_shlib.c,v
retrieving revision 2.8
retrieving revision 2.8.6.1
diff -C2 -r2.8 -r2.8.6.1
*** dynload_shlib.c	2001/01/10 21:17:27	2.8
--- dynload_shlib.c	2001/07/21 06:07:14	2.8.6.1
***************
*** 23,30 ****
  #endif
  
- #ifndef RTLD_LAZY
- #define RTLD_LAZY 1
- #endif
- 
  
  const struct filedescr _PyImport_DynLoadFiletab[] = {
--- 23,26 ----
***************
*** 54,57 ****
--- 50,54 ----
  	char funcname[258];
  	char pathbuf[260];
+         int dlopenflags=0;
  
  	if (strchr(pathname, '/') == NULL) {
***************
*** 81,94 ****
  	}
  
! #ifdef RTLD_NOW
! 	/* RTLD_NOW: resolve externals now
! 	   (i.e. core dump now if some are missing) */
! 	handle = dlopen(pathname, RTLD_NOW);
! #else
  	if (Py_VerboseFlag)
! 		printf("dlopen(\"%s\", %d);\n", pathname,
! 		       RTLD_LAZY);
! 	handle = dlopen(pathname, RTLD_LAZY);
! #endif /* RTLD_NOW */
  	if (handle == NULL) {
  		PyErr_SetString(PyExc_ImportError, dlerror());
--- 78,88 ----
  	}
  
!         dlopenflags = PyThreadState_Get()->interp->dlopenflags;
! 
  	if (Py_VerboseFlag)
! 		printf("dlopen(\"%s\", %x);\n", pathname, dlopenflags);
! 
! 	handle = dlopen(pathname, dlopenflags);
! 
  	if (handle == NULL) {
  		PyErr_SetString(PyExc_ImportError, dlerror());

Index: pystate.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pystate.c,v
retrieving revision 2.16.6.1
retrieving revision 2.16.6.2
diff -C2 -r2.16.6.1 -r2.16.6.2
*** pystate.c	2001/07/07 22:55:31	2.16.6.1
--- pystate.c	2001/07/21 06:07:14	2.16.6.2
***************
*** 4,7 ****
--- 4,17 ----
  #include "Python.h"
  
+ #ifdef HAVE_DLOPEN
+ #ifdef HAVE_DLFCN_H
+ #include <dlfcn.h>
+ #endif
+ #ifndef RTLD_LAZY
+ #define RTLD_LAZY 1
+ #endif
+ #endif
+ 
+ 
  #define ZAP(x) { \
  	PyObject *tmp = (PyObject *)(x); \
***************
*** 40,43 ****
--- 50,60 ----
  		interp->checkinterval = 10;
  		interp->tstate_head = NULL;
+ #ifdef HAVE_DLOPEN
+ #ifdef RTLD_NOW
+                 interp->dlopenflags = RTLD_NOW;
+ #else
+ 		interp->dlopenflags = RTLD_LAZY;
+ #endif
+ #endif
  
  		HEAD_LOCK();
***************
*** 247,249 ****
--- 264,291 ----
  		_PyThreadState_Current->dict = PyDict_New();
  	return _PyThreadState_Current->dict;
+ }
+ 
+ 
+ /* Routines for advanced debuggers, requested by David Beazley.
+    Don't use unless you know what you are doing! */
+ 
+ PyInterpreterState *
+ PyInterpreterState_Head(void)
+ {
+ 	return interp_head;
+ }
+ 
+ PyInterpreterState *
+ PyInterpreterState_Next(PyInterpreterState *interp) {
+ 	return interp->next;
+ }
+ 
+ PyThreadState *
+ PyInterpreterState_ThreadHead(PyInterpreterState *interp) {
+ 	return interp->tstate_head;
+ }
+ 
+ PyThreadState *
+ PyThreadState_Next(PyThreadState *tstate) {
+ 	return tstate->next;
  }

Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.85.4.1
retrieving revision 2.85.4.2
diff -C2 -r2.85.4.1 -r2.85.4.2
*** sysmodule.c	2001/07/07 22:55:31	2.85.4.1
--- sysmodule.c	2001/07/21 06:07:14	2.85.4.2
***************
*** 395,398 ****
--- 395,440 ----
  recursion from causing an overflow of the C stack and crashing Python.";
  
+ #ifdef HAVE_DLOPEN
+ static PyObject *
+ sys_setdlopenflags(PyObject *self, PyObject *args)
+ {
+ 	int new_val;
+         PyThreadState *tstate = PyThreadState_Get();
+ 	if (!PyArg_ParseTuple(args, "i:setdlopenflags", &new_val))
+ 		return NULL;
+         if (!tstate)
+ 		return NULL;
+         tstate->interp->dlopenflags = new_val;
+ 	Py_INCREF(Py_None);
+ 	return Py_None;
+ }
+ 
+ static char setdlopenflags_doc[] =
+ "setdlopenflags(n) -> None\n\
+ \n\
+ Set the flags that will be used for dlopen() calls. Among other\n\
+ things, this will enable a lazy resolving of symbols when imporing\n\
+ a module, if called as sys.setdlopenflags(0)\n\
+ To share symols across extension modules, call as\n\
+ sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)";
+ 
+ static PyObject *
+ sys_getdlopenflags(PyObject *self, PyObject *args)
+ {
+         PyThreadState *tstate = PyThreadState_Get();
+ 	if (!PyArg_ParseTuple(args, ":getdlopenflags"))
+ 		return NULL;
+         if (!tstate)
+ 		return NULL;
+         return PyInt_FromLong(tstate->interp->dlopenflags);
+ }
+ 
+ static char getdlopenflags_doc[] =
+ "getdlopenflags() -> int\n\
+ \n\
+ Return the current value of the flags that are used for dlopen()\n\
+ calls. The flag constants are defined in the dl module.";
+ #endif
+ 
  #ifdef USE_MALLOPT
  /* Link with -lmalloc (or -lmpc) on an SGI */
***************
*** 502,505 ****
--- 544,551 ----
  	{"getdefaultencoding", sys_getdefaultencoding, 1,
  	 getdefaultencoding_doc}, 
+ #ifdef HAVE_DLOPEN
+         {"getdlopenflags", sys_getdlopenflags, 1, 
+          getdlopenflags_doc},
+ #endif
  #ifdef COUNT_ALLOCS
  	{"getcounts",	sys_getcounts, 1},
***************
*** 523,526 ****
--- 569,576 ----
  	{"setcheckinterval",	sys_setcheckinterval, 1,
  	 setcheckinterval_doc}, 
+ #ifdef HAVE_DLOPEN
+         {"setdlopenflags", sys_setdlopenflags, 1, 
+          setdlopenflags_doc},
+ #endif
  	{"setprofile",	sys_setprofile, 0, setprofile_doc},
  	{"setrecursionlimit", sys_setrecursionlimit, 1,
***************
*** 660,666 ****
--- 710,718 ----
  exc_info() -- return thread-safe information about the current exception\n\
  exit() -- exit the interpreter by raising SystemExit\n\
+ getdlopenflags() -- returns flags to be used for dlopen() calls\n\
  getrefcount() -- return the reference count for an object (plus one :-)\n\
  getrecursionlimit() -- return the max recursion depth for the interpreter\n\
  setcheckinterval() -- control how often the interpreter checks for events\n\
+ setdlopenflags() -- set the flags to be used for dlopen() calls\n\
  setprofile() -- set the global profiling function\n\
  setrecursionlimit() -- set the max recursion depth for the interpreter\n\