forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys.c
56 lines (48 loc) · 1.19 KB
/
sys.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
_PyTestLimitedCAPI_Init_Sys(PyObject *m)
{
if (PyModule_AddFunctions(m, test_methods) < 0) {
return -1;
}
return 0;
}