-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
bpo-29881: Add new C API for static variables #770
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
* New type: _Py_StaticVar * New macro _Py_STATICVAR(var) to declare a variable * New macro _PY_STATICVAR_INIT(var, expr) to initialize a variable once * New function _PyStaticVar_Set() to explicitly set a variable once to initialize it * New _PyStaticVar_Fini() function clearing all references at exit
@Haypo, thanks for your PR! By analyzing the history of the files in this pull request, we identified @loewis, @benjaminp and @larryhastings to be potential reviewers. |
long protocol; | ||
_Py_IDENTIFIER(_array_reconstructor); | ||
_Py_IDENTIFIER(__dict__); | ||
|
||
if (array_reconstructor == NULL) { | ||
if (array_reconstructor.obj == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_PY_STATICVAR_INIT()
can be used if extract the code for getting array._array_reconstructor
into a separate function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in PR #780.
@@ -213,7 +213,7 @@ static int compiler_async_comprehension_generator( | |||
expr_ty elt, expr_ty val, int type); | |||
|
|||
static PyCodeObject *assemble(struct compiler *, int addNone); | |||
static PyObject *__doc__; | |||
_Py_STATICVAR(__doc__); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Py_IDENTIFIER()
can be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I know, it was more to show how the API can be used.
module = PyUnicode_InternFromString("<module>"); | ||
if (!module) | ||
return NULL; | ||
_Py_STATICVAR(module); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Py_static_string()
can be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -2639,12 +2637,10 @@ compiler_from_import(struct compiler *c, stmt_ty s) | |||
|
|||
PyObject *names = PyTuple_New(n); | |||
PyObject *level; | |||
static PyObject *empty_string; | |||
_Py_STATICVAR(empty_string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Py_static_string()
can be used.
@@ -162,7 +162,7 @@ sys_displayhook(PyObject *self, PyObject *o) | |||
PyInterpreterState *interp = PyThreadState_GET()->interp; | |||
PyObject *modules = interp->modules; | |||
PyObject *builtins; | |||
static PyObject *newline = NULL; | |||
_Py_STATICVAR(newline); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Py_static_string()
can be used.
@@ -2709,17 +2705,18 @@ compiler_from_import(struct compiler *c, stmt_ty s) | |||
static int | |||
compiler_assert(struct compiler *c, stmt_ty s) | |||
{ | |||
static PyObject *assertion_error = NULL; | |||
_Py_STATICVAR(assertion_error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Py_IDENTIFIER()
can be used.
static PyObject *builtins_str = NULL; | ||
static PyObject *import_str = NULL; | ||
_Py_STATICVAR(empty_list); | ||
_Py_STATICVAR(builtins_str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Py_IDENTIFIER()
can be used.
static PyObject *import_str = NULL; | ||
_Py_STATICVAR(empty_list); | ||
_Py_STATICVAR(builtins_str); | ||
_Py_STATICVAR(import_str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_Py_IDENTIFIER()
can be used.
Abandonned in favor PR #780 which has a simpler API. |
once
to initialize it