summaryrefslogtreecommitdiff
path: root/c/_cffi_backend.c
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2020-06-16 14:13:02 +0200
committerArmin Rigo <arigo@tunes.org>2020-06-16 14:13:02 +0200
commit7fdc30c2cc119fafe7a571739d75527533fad727 (patch)
tree05385201c617d52512ec08be0357aa0fabf8f206 /c/_cffi_backend.c
parent03700246095f6494a20b8ef0ffd217c45062ecfb (diff)
downloadcffi-7fdc30c2cc119fafe7a571739d75527533fad727.tar.gz
(untested) don't use deprecated "u" in PyArg_ParseTuple()
Diffstat (limited to 'c/_cffi_backend.c')
-rw-r--r--c/_cffi_backend.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
index f647d39..6f2f59e 100644
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -4451,8 +4451,8 @@ static void *b_do_dlopen(PyObject *args, const char **p_printable_filename,
{
PyObject *s = PyTuple_GET_ITEM(args, 0);
#ifdef MS_WIN32
- Py_UNICODE *filenameW;
- if (PyArg_ParseTuple(args, "u|i:load_library", &filenameW, &flags))
+ PyObject *filename_unicode;
+ if (PyArg_ParseTuple(args, "U|i:load_library", &filename_unicode, &flags))
{
#if PY_MAJOR_VERSION < 3
s = PyUnicode_AsUTF8String(s);
@@ -4464,7 +4464,14 @@ static void *b_do_dlopen(PyObject *args, const char **p_printable_filename,
if (*p_printable_filename == NULL)
return NULL;
- handle = dlopenW(filenameW);
+ Py_ssize_t sz1 = PyUnicode_GetSize(filename_unicode) + 1;
+ sz1 *= 2; /* should not be needed, but you never know */
+ wchar_t *w1 = alloca(sizeof(wchar_t) * sz1);
+ sz1 = PyUnicode_AsWideChar(filename_unicode, w1, sz1 - 1);
+ if (sz1 < 0)
+ return NULL;
+ w1[sz1] = 0;
+ handle = dlopenW(w1);
goto got_handle;
}
PyErr_Clear();