bpo-40563: Support pathlike objects on dbm/shelve (GH-21849)

Co-authored-by: Hakan Çelik <hakancelik96@outlook.com>
This commit is contained in:
Henry-Joseph Audéoud 2021-09-10 14:26:16 +02:00 • committed by GitHub
parent 62fa613f6a
commit 707137b863
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 124 additions and 68 deletions

View file

@ -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);