[Python-checkins] cpython: Issue #13226: Add RTLD_xxx constants to the os module. These constants can by

victor.stinner python-checkins at python.org
Tue Oct 25 13:34:07 CEST 2011


http://hg.python.org/cpython/rev/c75427c0da06
changeset:   73127:c75427c0da06
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Tue Oct 25 13:34:04 2011 +0200
summary:
  Issue #13226: Add RTLD_xxx constants to the os module. These constants can by
used with sys.setdlopenflags().

files:
  Doc/library/os.rst     |  13 +++++++++++++
  Doc/library/sys.rst    |  10 +++++-----
  Lib/test/test_posix.py |   7 +++++++
  Misc/NEWS              |   3 +++
  Modules/posixmodule.c  |  26 ++++++++++++++++++++++++++
  5 files changed, 54 insertions(+), 5 deletions(-)


diff --git a/Doc/library/os.rst b/Doc/library/os.rst
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1393,6 +1393,19 @@
    the C library.
 
 
+.. data:: RTLD_LAZY
+          RTLD_NOW
+          RTLD_GLOBAL
+          RTLD_LOCAL
+          RTLD_NODELETE
+          RTLD_NOLOAD
+          RTLD_DEEPBIND
+
+   See the Unix manual page :manpage:`dlopen(3)`.
+
+   .. versionadded:: 3.3
+
+
 .. _os-file-dir:
 
 Files and Directories
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -801,11 +801,11 @@
    the interpreter loads extension modules.  Among other things, this will enable a
    lazy resolving of symbols when importing a module, if called as
    ``sys.setdlopenflags(0)``.  To share symbols across extension modules, call as
-   ``sys.setdlopenflags(ctypes.RTLD_GLOBAL)``.  Symbolic names for the
-   flag modules can be either found in the :mod:`ctypes` module, or in the :mod:`DLFCN`
-   module. If :mod:`DLFCN` is not available, it can be generated from
-   :file:`/usr/include/dlfcn.h` using the :program:`h2py` script. Availability:
-   Unix.
+   ``sys.setdlopenflags(os.RTLD_GLOBAL)``.  Symbolic names for the flag modules
+   can be found in the :mod:`os` module (``RTLD_xxx`` constants, e.g.
+   :data:`os.RTLD_LAZY`).
+
+   Availability: Unix.
 
 .. function:: setprofile(profilefunc)
 
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -984,6 +984,13 @@
         self.assertIs(b, l)
         self.assertEqual(l.count(), 3)
 
+    def test_rtld_constants(self):
+        # check presence of major RTLD_* constants
+        posix.RTLD_LAZY
+        posix.RTLD_NOW
+        posix.RTLD_GLOBAL
+        posix.RTLD_LOCAL
+
 class PosixGroupsTester(unittest.TestCase):
 
     def setUp(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -341,6 +341,9 @@
 Library
 -------
 
+- Issue #13226: Add RTLD_xxx constants to the os module. These constants can by
+  used with sys.setdlopenflags().
+
 - Issue #10278: Add clock_getres(), clock_gettime() and CLOCK_xxx constants to
   the time module. time.clock_gettime(time.CLOCK_MONOTONIC) provides a
   monotonic clock
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -121,6 +121,10 @@
 #endif
 #endif
 
+#ifdef HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
 /* Various compilers have only certain posix functions */
 /* XXX Gosh I wish these were all moved into pyconfig.h */
 #if defined(PYCC_VACPP) && defined(PYOS_OS2)
@@ -11423,6 +11427,28 @@
     if (ins(d, "XATTR_SIZE_MAX", (long)XATTR_SIZE_MAX)) return -1;
 #endif
 
+#ifdef RTLD_LAZY
+    if (PyModule_AddIntMacro(d, RTLD_LAZY)) return -1;
+#endif
+#ifdef RTLD_NOW
+    if (PyModule_AddIntMacro(d, RTLD_NOW)) return -1;
+#endif
+#ifdef RTLD_GLOBAL
+    if (PyModule_AddIntMacro(d, RTLD_GLOBAL)) return -1;
+#endif
+#ifdef RTLD_LOCAL
+    if (PyModule_AddIntMacro(d, RTLD_LOCAL)) return -1;
+#endif
+#ifdef RTLD_NODELETE
+    if (PyModule_AddIntMacro(d, RTLD_NODELETE)) return -1;
+#endif
+#ifdef RTLD_NOLOAD
+    if (PyModule_AddIntMacro(d, RTLD_NOLOAD)) return -1;
+#endif
+#ifdef RTLD_DEEPBIND
+    if (PyModule_AddIntMacro(d, RTLD_DEEPBIND)) return -1;
+#endif
+
 #if defined(PYOS_OS2)
     if (insertvalues(d)) return -1;
 #endif

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list