File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -315,6 +315,9 @@ C-API
315315Library
316316-------
317317
318+ - Issue #8394: _ctypes.dlopen() accepts bytes, bytearray and str with
319+ surrogates.
320+
318321- Issue #850728: Add a *timeout* parameter to the `acquire()` method of
319322 `threading.Semaphore` objects. Original patch by Torsten Landschoff.
320323
Original file line number Diff line number Diff line change @@ -1371,18 +1371,31 @@ copy_com_pointer(PyObject *self, PyObject *args)
13711371
13721372static PyObject * py_dl_open (PyObject * self , PyObject * args )
13731373{
1374- char * name ;
1374+ PyObject * name , * name2 ;
1375+ char * name_str ;
13751376 void * handle ;
13761377#ifdef RTLD_LOCAL
13771378 int mode = RTLD_NOW | RTLD_LOCAL ;
13781379#else
13791380 /* cygwin doesn't define RTLD_LOCAL */
13801381 int mode = RTLD_NOW ;
13811382#endif
1382- if (!PyArg_ParseTuple (args , "z |i:dlopen" , & name , & mode ))
1383+ if (!PyArg_ParseTuple (args , "O |i:dlopen" , & name , & mode ))
13831384 return NULL ;
13841385 mode |= RTLD_NOW ;
1385- handle = ctypes_dlopen (name , mode );
1386+ if (name != Py_None ) {
1387+ if (PyUnicode_FSConverter (name , & name2 ) == 0 )
1388+ return NULL ;
1389+ if (PyBytes_Check (name2 ))
1390+ name_str = PyBytes_AS_STRING (name2 );
1391+ else
1392+ name_str = PyByteArray_AS_STRING (name2 );
1393+ } else {
1394+ name_str = NULL ;
1395+ name2 = NULL ;
1396+ }
1397+ handle = ctypes_dlopen (name_str , mode );
1398+ Py_XDECREF (name2 );
13861399 if (!handle ) {
13871400 char * errmsg = ctypes_dlerror ();
13881401 if (!errmsg )
You can’t perform that action at this time.
0 commit comments