Skip to content

Conversation

vstinner
Copy link
Member

  • 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

* 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
@mention-bot
Copy link

@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) {
Copy link
Member

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.

Copy link
Member Author

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__);
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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);
Copy link
Member

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.

@vstinner
Copy link
Member Author

Abandonned in favor PR #780 which has a simpler API.

@vstinner vstinner closed this Mar 23, 2017
@vstinner vstinner deleted the staticvar branch March 23, 2017 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants