summaryrefslogtreecommitdiffstats
path: root/Modules/_testlimitedcapi/sys.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2024-03-11 10:28:16 (GMT)
committerGitHub <noreply@github.com>2024-03-11 10:28:16 (GMT)
commit1cc02ca063f50b8c527fbdde9957b03c145c1575 (patch)
tree84cd4d2d13c8ca869749827d8f91d592e8a01ca2 /Modules/_testlimitedcapi/sys.c
parentd8712fa0c75ad5ea56543903fa45674ab47cc647 (diff)
downloadcpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.zip
cpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.tar.gz
cpython-1cc02ca063f50b8c527fbdde9957b03c145c1575.tar.bz2
gh-116417: Move 4 limited C API test files to _testlimitedcapi (#116571)
Move the following files from Modules/_testcapi/ to Modules/_testlimitedcapi/: * bytearray.c * bytes.c * pyos.c * sys.c Changes: * Replace PyBytes_AS_STRING() with PyBytes_AsString(). * Replace PyBytes_GET_SIZE() with PyBytes_Size(). * Update related test_capi tests. * Copy Modules/_testcapi/util.h to Modules/_testlimitedcapi/util.h.
Diffstat (limited to 'Modules/_testlimitedcapi/sys.c')
-rw-r--r--Modules/_testlimitedcapi/sys.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/Modules/_testlimitedcapi/sys.c b/Modules/_testlimitedcapi/sys.c
new file mode 100644
index 0000000..aa40e3c
--- /dev/null
+++ b/Modules/_testlimitedcapi/sys.c
@@ -0,0 +1,56 @@
+#include "parts.h"
+#include "util.h"
+
+
+static PyObject *
+sys_getobject(PyObject *Py_UNUSED(module), PyObject *arg)
+{
+ const char *name;
+ Py_ssize_t size;
+ if (!PyArg_Parse(arg, "z#", &name, &size)) {
+ return NULL;
+ }
+ PyObject *result = PySys_GetObject(name);
+ if (result == NULL) {
+ result = PyExc_AttributeError;
+ }
+ return Py_NewRef(result);
+}
+
+static PyObject *
+sys_setobject(PyObject *Py_UNUSED(module), PyObject *args)
+{
+ const char *name;
+ Py_ssize_t size;
+ PyObject *value;
+ if (!PyArg_ParseTuple(args, "z#O", &name, &size, &value)) {
+ return NULL;
+ }
+ NULLABLE(value);
+ RETURN_INT(PySys_SetObject(name, value));
+}
+
+static PyObject *
+sys_getxoptions(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(ignored))
+{
+ PyObject *result = PySys_GetXOptions();
+ return Py_XNewRef(result);
+}
+
+
+static PyMethodDef test_methods[] = {
+ {"sys_getobject", sys_getobject, METH_O},
+ {"sys_setobject", sys_setobject, METH_VARARGS},
+ {"sys_getxoptions", sys_getxoptions, METH_NOARGS},
+ {NULL},
+};
+
+int
+_PyTestCapi_Init_Sys(PyObject *m)
+{
+ if (PyModule_AddFunctions(m, test_methods) < 0) {
+ return -1;
+ }
+
+ return 0;
+}