bpo-29881: Add new C API for static variables#770
bpo-29881: Add new C API for static variables#770vstinner wants to merge 1 commit intopython:masterfrom vstinner:staticvar
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. |
| _Py_IDENTIFIER(__dict__); | ||
|
|
||
| if (array_reconstructor == NULL) { | ||
| if (array_reconstructor.obj == NULL) { |
There was a problem hiding this comment.
_PY_STATICVAR_INIT() can be used if extract the code for getting array._array_reconstructor into a separate function.
|
|
||
| static PyCodeObject *assemble(struct compiler *, int addNone); | ||
| static PyObject *__doc__; | ||
| _Py_STATICVAR(__doc__); |
There was a problem hiding this comment.
_Py_IDENTIFIER() can be used.
There was a problem hiding this comment.
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.
_Py_static_string() can be used.
| PyObject *names = PyTuple_New(n); | ||
| PyObject *level; | ||
| static PyObject *empty_string; | ||
| _Py_STATICVAR(empty_string); |
There was a problem hiding this comment.
Py_static_string() can be used.
| PyObject *modules = interp->modules; | ||
| PyObject *builtins; | ||
| static PyObject *newline = NULL; | ||
| _Py_STATICVAR(newline); |
There was a problem hiding this comment.
Py_static_string() can be used.
| compiler_assert(struct compiler *c, stmt_ty s) | ||
| { | ||
| static PyObject *assertion_error = NULL; | ||
| _Py_STATICVAR(assertion_error); |
There was a problem hiding this comment.
_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.
_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.
_Py_IDENTIFIER() can be used.
|
Abandonned in favor PR #780 which has a simpler API. |
once
to initialize it