summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-12-04 09:09:06 (GMT)
committerGitHub <noreply@github.com>2023-12-04 09:09:06 (GMT)
commitdee7beeb4f9d28fec945c8c495027cc22a512328 (patch)
treec41df7d57757f57cdd2f74a0fbd10925315508f4 /Python
parent0e732d0997cff08855d98c17af4dd5527f10e419 (diff)
downloadcpython-dee7beeb4f9d28fec945c8c495027cc22a512328.zip
cpython-dee7beeb4f9d28fec945c8c495027cc22a512328.tar.gz
cpython-dee7beeb4f9d28fec945c8c495027cc22a512328.tar.bz2
bpo-34392: Add sys. _is_interned() (GH-8755)
Diffstat (limited to 'Python')
-rw-r--r--Python/clinic/sysmodule.c.h36
-rw-r--r--Python/sysmodule.c18
2 files changed, 53 insertions, 1 deletions
diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h
index 98717ec..93b8385 100644
--- a/Python/clinic/sysmodule.c.h
+++ b/Python/clinic/sysmodule.c.h
@@ -289,6 +289,40 @@ exit:
return return_value;
}
+PyDoc_STRVAR(sys__is_interned__doc__,
+"_is_interned($module, string, /)\n"
+"--\n"
+"\n"
+"Return True if the given string is \"interned\".");
+
+#define SYS__IS_INTERNED_METHODDEF \
+ {"_is_interned", (PyCFunction)sys__is_interned, METH_O, sys__is_interned__doc__},
+
+static int
+sys__is_interned_impl(PyObject *module, PyObject *string);
+
+static PyObject *
+sys__is_interned(PyObject *module, PyObject *arg)
+{
+ PyObject *return_value = NULL;
+ PyObject *string;
+ int _return_value;
+
+ if (!PyUnicode_Check(arg)) {
+ _PyArg_BadArgument("_is_interned", "argument", "str", arg);
+ goto exit;
+ }
+ string = arg;
+ _return_value = sys__is_interned_impl(module, string);
+ if ((_return_value == -1) && PyErr_Occurred()) {
+ goto exit;
+ }
+ return_value = PyBool_FromLong((long)_return_value);
+
+exit:
+ return return_value;
+}
+
PyDoc_STRVAR(sys__settraceallthreads__doc__,
"_settraceallthreads($module, arg, /)\n"
"--\n"
@@ -1452,4 +1486,4 @@ exit:
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
#define SYS_GETANDROIDAPILEVEL_METHODDEF
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
-/*[clinic end generated code: output=f36d45c829250775 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3dc3b2cb0ce38ebb input=a9049054013a1b77]*/
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index c17de44..46878c7 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -989,6 +989,23 @@ sys_intern_impl(PyObject *module, PyObject *s)
}
+/*[clinic input]
+sys._is_interned -> bool
+
+ string: unicode
+ /
+
+Return True if the given string is "interned".
+[clinic start generated code]*/
+
+static int
+sys__is_interned_impl(PyObject *module, PyObject *string)
+/*[clinic end generated code: output=c3678267b4e9d7ed input=039843e17883b606]*/
+{
+ return PyUnicode_CHECK_INTERNED(string);
+}
+
+
/*
* Cached interned string objects used for calling the profile and
* trace functions.
@@ -2462,6 +2479,7 @@ static PyMethodDef sys_methods[] = {
SYS_GETWINDOWSVERSION_METHODDEF
SYS__ENABLELEGACYWINDOWSFSENCODING_METHODDEF
SYS_INTERN_METHODDEF
+ SYS__IS_INTERNED_METHODDEF
SYS_IS_FINALIZING_METHODDEF
SYS_MDEBUG_METHODDEF
SYS_SETSWITCHINTERVAL_METHODDEF