Skip to content

bpo-29881: Add new C API for static variables#770

Closed
vstinner wants to merge 1 commit intopython:masterfrom
vstinner:staticvar
Closed

bpo-29881: Add new C API for static variables#770
vstinner wants to merge 1 commit intopython:masterfrom
vstinner:staticvar

Conversation

@vstinner
Copy link
Copy Markdown
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
Copy Markdown

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


static PyCodeObject *assemble(struct compiler *, int addNone);
static PyObject *__doc__;
_Py_STATICVAR(__doc__);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

PyObject *names = PyTuple_New(n);
PyObject *level;
static PyObject *empty_string;
_Py_STATICVAR(empty_string);
Copy link
Copy Markdown
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.

PyObject *modules = interp->modules;
PyObject *builtins;
static PyObject *newline = NULL;
_Py_STATICVAR(newline);
Copy link
Copy Markdown
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.

compiler_assert(struct compiler *c, stmt_ty s)
{
static PyObject *assertion_error = NULL;
_Py_STATICVAR(assertion_error);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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