From 707137b8637feef37b2e06a851fdca9d1b945861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry-Joseph=20Aud=C3=A9oud?= Date: Fri, 10 Sep 2021 14:26:16 +0200 Subject: bpo-40563: Support pathlike objects on dbm/shelve (GH-21849) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Hakan Çelik --- Modules/_gdbmmodule.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Modules/_gdbmmodule.c') diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 3c9a0e98e4..efbf331ca3 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -590,7 +590,7 @@ static PyType_Spec gdbmtype_spec = { /*[clinic input] _gdbm.open as dbmopen - filename: unicode + filename: object flags: str="r" mode: int(py_default="0o666") = 0o666 / @@ -622,7 +622,7 @@ when the database has to be created. It defaults to octal 0o666. static PyObject * dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, int mode) -/*[clinic end generated code: output=9527750f5df90764 input=812b7d74399ceb0e]*/ +/*[clinic end generated code: output=9527750f5df90764 input=bca6ec81dc49292c]*/ { int iflags; _gdbm_state *state = get_gdbm_state(module); @@ -672,10 +672,11 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags, } } - PyObject *filenamebytes = PyUnicode_EncodeFSDefault(filename); - if (filenamebytes == NULL) { + PyObject *filenamebytes; + if (!PyUnicode_FSConverter(filename, &filenamebytes)) { return NULL; } + const char *name = PyBytes_AS_STRING(filenamebytes); if (strlen(name) != (size_t)PyBytes_GET_SIZE(filenamebytes)) { Py_DECREF(filenamebytes); -- cgit v1.2.1