Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-108512: Add and use new replacements for PySys_GetObject()#111035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
4d0f508eb42b392d4588d2eb95339fc2f3d65713cee6ecf118a0f5f2516829e9503aafe2857efdc26ec2104dcc2cf75fc3943465956639d8b40a66503b9c0a5d793c509869ed439bc3c93ab31b154a82a81c7605File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,12 @@ | ||
| extern"C" { | ||
| #endif | ||
| #if !defined(Py_LIMITED_API)||Py_LIMITED_API+0 >=0x030f0000 | ||
| PyAPI_FUNC(PyObject*)PySys_GetAttr(PyObject*); | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| PyAPI_FUNC(PyObject*)PySys_GetAttrString(constchar*); | ||
| PyAPI_FUNC(int)PySys_GetOptionalAttr(PyObject*,PyObject**); | ||
| PyAPI_FUNC(int)PySys_GetOptionalAttrString(constchar*,PyObject**); | ||
| #endif | ||
| PyAPI_FUNC(PyObject*)PySys_GetObject(constchar*); | ||
| PyAPI_FUNC(int)PySys_SetObject(constchar*,PyObject*); | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add functions :c:func:`PySys_GetAttr`, :c:func:`PySys_GetAttrString`, | ||
| :c:func:`PySys_GetOptionalAttr` and :c:func:`PySys_GetOptionalAttrString`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,76 @@ | ||
| #include "pyconfig.h" // Py_GIL_DISABLED | ||
| // Need limited C API version 3.15 for PySys_GetAttr() etc | ||
vstinner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| #if !defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API) | ||
| # define Py_LIMITED_API 0x030f0000 | ||
| #endif | ||
| #include "parts.h" | ||
| #include "util.h" | ||
| static PyObject * | ||
| sys_getattr(PyObject *Py_UNUSED(module), PyObject *name) | ||
| { | ||
| NULLABLE(name); | ||
| return PySys_GetAttr(name); | ||
| } | ||
| static PyObject * | ||
| sys_getattrstring(PyObject *Py_UNUSED(module), PyObject *arg) | ||
| { | ||
| const char *name; | ||
| Py_ssize_t size; | ||
| if (!PyArg_Parse(arg, "z#", &name, &size)) { | ||
| return NULL; | ||
| } | ||
| return PySys_GetAttrString(name); | ||
| } | ||
| static PyObject * | ||
| sys_getoptionalattr(PyObject *Py_UNUSED(module), PyObject *name) | ||
| { | ||
| PyObject *value = UNINITIALIZED_PTR; | ||
| NULLABLE(name); | ||
| switch (PySys_GetOptionalAttr(name, &value)) { | ||
| case -1: | ||
| assert(value == NULL); | ||
| assert(PyErr_Occurred()); | ||
| return NULL; | ||
| case 0: | ||
| assert(value == NULL); | ||
| return Py_NewRef(PyExc_AttributeError); | ||
| case 1: | ||
| return value; | ||
| default: | ||
| Py_FatalError("PySys_GetOptionalAttr() returned invalid code"); | ||
| } | ||
| } | ||
| static PyObject * | ||
| sys_getoptionalattrstring(PyObject *Py_UNUSED(module), PyObject *arg) | ||
| { | ||
| PyObject *value = UNINITIALIZED_PTR; | ||
| const char *name; | ||
| Py_ssize_t size; | ||
| if (!PyArg_Parse(arg, "z#", &name, &size)) { | ||
| return NULL; | ||
| } | ||
| switch (PySys_GetOptionalAttrString(name, &value)) { | ||
| case -1: | ||
| assert(value == NULL); | ||
| assert(PyErr_Occurred()); | ||
| return NULL; | ||
| case 0: | ||
| assert(value == NULL); | ||
| return Py_NewRef(PyExc_AttributeError); | ||
| case 1: | ||
| return value; | ||
| default: | ||
| Py_FatalError("PySys_GetOptionalAttrString() returned invalid code"); | ||
| } | ||
| } | ||
| static PyObject * | ||
| sys_getobject(PyObject *Py_UNUSED(module), PyObject *arg) | ||
| { | ||
| @@ -39,6 +108,10 @@ sys_getxoptions(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(ignored)) | ||
| static PyMethodDef test_methods[] = { | ||
| {"sys_getattr", sys_getattr, METH_O}, | ||
| {"sys_getattrstring", sys_getattrstring, METH_O}, | ||
| {"sys_getoptionalattr", sys_getoptionalattr, METH_O}, | ||
| {"sys_getoptionalattrstring", sys_getoptionalattrstring, METH_O}, | ||
| {"sys_getobject", sys_getobject, METH_O}, | ||
| {"sys_setobject", sys_setobject, METH_VARARGS}, | ||
| {"sys_getxoptions", sys_getxoptions, METH_NOARGS}, | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.