summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorHenry-Joseph Audéoud <h.audeoud@gmail.com>2021-09-10 12:26:16 (GMT)
committerGitHub <noreply@github.com>2021-09-10 12:26:16 (GMT)
commit707137b8637feef37b2e06a851fdca9d1b945861 (patch)
treeeedd9bec5c0b98b244438e120ee12d8143906c19 /Modules
parent62fa613f6a6e872723505ee9d56242c31a654a9d (diff)
downloadcpython-707137b8637feef37b2e06a851fdca9d1b945861.zip
cpython-707137b8637feef37b2e06a851fdca9d1b945861.tar.gz
cpython-707137b8637feef37b2e06a851fdca9d1b945861.tar.bz2
bpo-40563: Support pathlike objects on dbm/shelve (GH-21849)
Co-authored-by: Hakan Çelik <hakancelik96@outlook.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_dbmmodule.c9
-rw-r--r--Modules/_gdbmmodule.c9
-rw-r--r--Modules/clinic/_dbmmodule.c.h9
-rw-r--r--Modules/clinic/_gdbmmodule.c.h9
4 files changed, 12 insertions, 24 deletions
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index 3fe97ef..4cbbac3 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -433,7 +433,7 @@ static PyType_Spec dbmtype_spec = {
_dbm.open as dbmopen
- filename: unicode
+ filename: object
The filename to open.
flags: str="r"
@@ -452,7 +452,7 @@ Return a database object.
static PyObject *
dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
int mode)
-/*[clinic end generated code: output=9527750f5df90764 input=376a9d903a50df59]*/
+/*[clinic end generated code: output=9527750f5df90764 input=d8cf50a9f81218c8]*/
{
int iflags;
_dbm_state *state = get_dbm_state(module);
@@ -479,10 +479,11 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
return NULL;
}
- 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);
diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c
index 3c9a0e9..efbf331 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);
diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h
index b50db5d..f0b8220 100644
--- a/Modules/clinic/_dbmmodule.c.h
+++ b/Modules/clinic/_dbmmodule.c.h
@@ -149,13 +149,6 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (!_PyArg_CheckPositional("open", nargs, 1, 3)) {
goto exit;
}
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("open", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
filename = args[0];
if (nargs < 2) {
goto skip_optional;
@@ -186,4 +179,4 @@ skip_optional:
exit:
return return_value;
}
-/*[clinic end generated code: output=13b6d821416be228 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=32ef6c0f8f2d3db9 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h
index 15baf52..a40e80d 100644
--- a/Modules/clinic/_gdbmmodule.c.h
+++ b/Modules/clinic/_gdbmmodule.c.h
@@ -303,13 +303,6 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (!_PyArg_CheckPositional("open", nargs, 1, 3)) {
goto exit;
}
- if (!PyUnicode_Check(args[0])) {
- _PyArg_BadArgument("open", "argument 1", "str", args[0]);
- goto exit;
- }
- if (PyUnicode_READY(args[0]) == -1) {
- goto exit;
- }
filename = args[0];
if (nargs < 2) {
goto skip_optional;
@@ -340,4 +333,4 @@ skip_optional:
exit:
return return_value;
}
-/*[clinic end generated code: output=1fed9ed50ad23551 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=63c507f93d84a3a4 input=a9049054013a1b77]*/