]> granicus.if.org Git - python/commitdiff
Issue #8394: _ctypes.dlopen() accepts bytes, bytearray and str with
authorVictor Stinner <victor.stinner@haypocalc.com>
Sun, 18 Apr 2010 00:00:44 +0000 (00:00 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sun, 18 Apr 2010 00:00:44 +0000 (00:00 +0000)
surrogates.

Misc/NEWS
Modules/_ctypes/callproc.c

index 62de9cb3634b51f1638a3eb33edfca958740b9ee..89e2bf65af7a5ffd2cba91020335e6c150a2b151 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -315,6 +315,9 @@ C-API
 Library
 -------
 
+- Issue #8394: _ctypes.dlopen() accepts bytes, bytearray and str with
+  surrogates.
+
 - Issue #850728: Add a *timeout* parameter to the `acquire()` method of
   `threading.Semaphore` objects.  Original patch by Torsten Landschoff.
 
index 2a75fb108485c2278e57459177639842169de513..022cceb4c327262b97badb69c2c9356d934a31d3 100644 (file)
@@ -1371,7 +1371,8 @@ copy_com_pointer(PyObject *self, PyObject *args)
 
 static PyObject *py_dl_open(PyObject *self, PyObject *args)
 {
-       char *name;
+       PyObject *name, *name2;
+       char *name_str;
        void * handle;
 #ifdef RTLD_LOCAL      
        int mode = RTLD_NOW | RTLD_LOCAL;
@@ -1379,10 +1380,22 @@ static PyObject *py_dl_open(PyObject *self, PyObject *args)
        /* cygwin doesn't define RTLD_LOCAL */
        int mode = RTLD_NOW;
 #endif
-       if (!PyArg_ParseTuple(args, "z|i:dlopen", &name, &mode))
+       if (!PyArg_ParseTuple(args, "O|i:dlopen", &name, &mode))
                return NULL;
        mode |= RTLD_NOW;
-       handle = ctypes_dlopen(name, mode);
+       if (name != Py_None) {
+               if (PyUnicode_FSConverter(name, &name2) == 0)
+                       return NULL;
+               if (PyBytes_Check(name2))
+                       name_str = PyBytes_AS_STRING(name2);
+               else
+                       name_str = PyByteArray_AS_STRING(name2);
+       } else {
+               name_str = NULL;
+               name2 = NULL;
+       }
+       handle = ctypes_dlopen(name_str, mode);
+       Py_XDECREF(name2);
        if (!handle) {
                char *errmsg = ctypes_dlerror();
                if (!errmsg)