Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-36876: Avoid static locals.#13372

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

Closed
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
11 commits
Select commitHold shift + click to select a range
5c7ad09
Fix static locals in helper modules.
ericsnowcurrentlyMay 15, 2019
df8c0d4
Fix static locals in testing modules.
ericsnowcurrentlyMay 15, 2019
a9cfc15
Fix static locals in builtin modules.
ericsnowcurrentlyMay 15, 2019
c4689e0
Fix static locals in stdlib extension modules.
ericsnowcurrentlyMay 15, 2019
6e9289c
Verify static locals in the parser code.
ericsnowcurrentlyMay 15, 2019
6dc09fa
Fix static locals for objects.
ericsnowcurrentlyMay 15, 2019
e21b68f
Fix static locals for core runtime code.
ericsnowcurrentlyMay 16, 2019
b1afab1
Move local _Py_IDENTIFER to global for modules.
ericsnowcurrentlyMay 16, 2019
6902106
Move local _Py_IDENTIFER to global for objects.
ericsnowcurrentlyMay 17, 2019
055fa11
Move local _Py_IDENTIFER to global for core files.
ericsnowcurrentlyMay 17, 2019
f9aca0c
Add a NEWS entry.
ericsnowcurrentlyMay 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Fix static locals for core runtime code.
  • Loading branch information
@ericsnowcurrently
ericsnowcurrently committedMay 17, 2019
commite21b68f69162b7a36548288c8b8747fe548bee61
3 changes: 2 additions & 1 deletionPython/Python-ast.c
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

13 changes: 7 additions & 6 deletionsPython/_warnings.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -751,11 +751,12 @@ warn_explicit(PyObject *category, PyObject *message,
return result; /* Py_None or NULL. */
}

static PyObject *importlib_string = NULL;
static PyObject *bootstrap_string = NULL;

static int
is_internal_frame(PyFrameObject *frame)
{
static PyObject *importlib_string = NULL;
static PyObject *bootstrap_string = NULL;
PyObject *filename;
int contains;

Expand DownExpand Up@@ -1024,9 +1025,9 @@ get_source_line(PyObject *module_globals, int lineno)
static PyObject *
warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwd_list[] = {"message", "category", "filename", "lineno",
"module", "registry", "module_globals",
"source", 0};
static char *kwlist[] = {"message", "category", "filename", "lineno",
"module", "registry", "module_globals",
"source", 0};
PyObject *message;
PyObject *category;
PyObject *filename;
Expand All@@ -1039,7 +1040,7 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *returned;

if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOUi|OOOO:warn_explicit",
kwd_list, &message, &category, &filename, &lineno, &module,
kwlist, &message, &category, &filename, &lineno, &module,
&registry, &module_globals, &sourceobj))
return NULL;

Expand Down
2 changes: 1 addition & 1 deletionPython/ast.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3178,7 +3178,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func,
// To remain LL(1), the grammar accepts any test (basically, any
// expression) in the keyword slot of a call site. So, we need
// to manually enforce that the keyword is a NAME here.
static const int name_tree[] = {
static const int name_tree[] = { // Static is okay here (immutable data).
test,
or_test,
and_test,
Expand Down
2 changes: 1 addition & 1 deletionPython/ast_opt.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,7 +75,7 @@ fold_unaryop(expr_ty node, PyArena *arena, int optimize)
}

typedef PyObject *(*unary_op)(PyObject*);
static const unary_op ops[] = {
static const unary_op ops[] = { // Static is okay here (immutable data).
[Invert] = PyNumber_Invert,
[Not] = unary_not,
[UAdd] = PyNumber_Positive,
Expand Down
4 changes: 2 additions & 2 deletionsPython/bltinmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1851,8 +1851,8 @@ builtin_pow_impl(PyObject *module, PyObject *x, PyObject *y, PyObject *z)
static PyObject *
builtin_print(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
static const char * const_keywords[] = {"sep", "end", "file", "flush", 0};
static struct _PyArg_Parser _parser = {"|OOOO:print",_keywords, 0};
static const char * const_kwlist[] = {"sep", "end", "file", "flush", 0};
static struct _PyArg_Parser _parser = {"|OOOO:print",_kwlist, 0}; // Static is okay here (immutable data).
PyObject *sep = NULL, *end = NULL, *file = NULL, *flush = NULL;
int i, err;

Expand Down
4 changes: 2 additions & 2 deletionsPython/bootstrap_hash.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,7 +102,7 @@ py_getrandom(void *buffer, Py_ssize_t size, int blocking, int raise)
/* Is getrandom() supported by the running kernel? Set to 0 if getrandom()
failed with ENOSYS or EPERM. Need Linux kernel 3.17 or newer, or Solaris
11.3 or newer */
static int getrandom_works = 1;
static int getrandom_works = 1; // Static is okay here (process-global).
int flags;
char *dest;
long n;
Expand DownExpand Up@@ -212,7 +212,7 @@ py_getentropy(char *buffer, Py_ssize_t size, int raise)
{
/* Is getentropy() supported by the running kernel? Set to 0 if
getentropy() failed with ENOSYS or EPERM. */
static int getentropy_works = 1;
static int getentropy_works = 1; // Static is okay here (process-global).

if (!getentropy_works) {
return 0;
Expand Down
12 changes: 6 additions & 6 deletionsPython/ceval.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -479,21 +479,21 @@ handle_signals(_PyRuntimeState *runtime)
return 0;
}

static int pending_calls_busy = 0;

static int
make_pending_calls(_PyRuntimeState *runtime)
{
static int busy = 0;

/* only service pending calls on main thread */
if (PyThread_get_thread_ident() != runtime->main_thread) {
return 0;
}

/* don't perform recursive pending calls */
if (busy) {
if (pending_calls_busy) {
return 0;
}
busy = 1;
pending_calls_busy = 1;
struct _ceval_runtime_state *ceval = &runtime->ceval;
/* unsignal before starting to call callbacks, so that any callback
added in-between re-signals */
Expand DownExpand Up@@ -521,11 +521,11 @@ make_pending_calls(_PyRuntimeState *runtime)
}
}

busy = 0;
pending_calls_busy = 0;
return res;

error:
busy = 0;
pending_calls_busy = 0;
SIGNAL_PENDING_CALLS(ceval);
return res;
}
Expand Down
2 changes: 1 addition & 1 deletionPython/codecs.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1414,7 +1414,7 @@ static PyObject *surrogateescape_errors(PyObject *self, PyObject *exc)

static int _PyCodecRegistry_Init(void)
{
static struct {
static struct { // Static is okay here (immutable data).
char *name;
PyMethodDef def;
} methods[] =
Expand Down
83 changes: 46 additions & 37 deletionsPython/compile.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1717,19 +1717,20 @@ compiler_body(struct compiler *c, asdl_seq *stmts)
return 1;
}

static PyObject *cached_name_module = NULL;

static PyCodeObject *
compiler_mod(struct compiler *c, mod_ty mod)
{
PyCodeObject *co;
int addNone = 1;
static PyObject *module;
if (!module) {
module = PyUnicode_InternFromString("<module>");
if (!module)
if (!cached_name_module) {
cached_name_module = PyUnicode_InternFromString("<module>");
if (!cached_name_module)
return NULL;
}
/* Use 0 for firstlineno initially, will fixup in assemble(). */
if (!compiler_enter_scope(c,module, COMPILER_SCOPE_MODULE, mod, 0))
if (!compiler_enter_scope(c,cached_name_module, COMPILER_SCOPE_MODULE, mod, 0))
return NULL;
switch (mod->kind) {
case Module_kind:
Expand DownExpand Up@@ -1973,6 +1974,8 @@ compiler_visit_argannotations(struct compiler *c, asdl_seq* args,
return 1;
}

static identifier return_str = NULL;

static int
compiler_visit_annotations(struct compiler *c, arguments_ty args,
expr_ty returns)
Expand All@@ -1982,7 +1985,6 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args,

Return 0 on error, -1 if no dict pushed, 1 if a dict is pushed.
*/
static identifier return_str;
PyObject *names;
Py_ssize_t len;
names = PyList_New(0);
Expand DownExpand Up@@ -2481,19 +2483,20 @@ compiler_ifexp(struct compiler *c, expr_ty e)
return 1;
}

static identifier cached_name_lambda;

static int
compiler_lambda(struct compiler *c, expr_ty e)
{
PyCodeObject *co;
PyObject *qualname;
static identifier name;
Py_ssize_t funcflags;
arguments_ty args = e->v.Lambda.args;
assert(e->kind == Lambda_kind);

if (!name) {
name = PyUnicode_InternFromString("<lambda>");
if (!name)
if (!cached_name_lambda) {
cached_name_lambda = PyUnicode_InternFromString("<lambda>");
if (!cached_name_lambda)
return 0;
}

Expand All@@ -2502,7 +2505,7 @@ compiler_lambda(struct compiler *c, expr_ty e)
return 0;
}

if (!compiler_enter_scope(c,name, COMPILER_SCOPE_LAMBDA,
if (!compiler_enter_scope(c,cached_name_lambda, COMPILER_SCOPE_LAMBDA,
(void *)e, e->lineno))
return 0;

Expand DownExpand Up@@ -3082,12 +3085,13 @@ compiler_import(struct compiler *c, stmt_ty s)
return 1;
}

static PyObject *empty_string;

static int
compiler_from_import(struct compiler *c, stmt_ty s)
{
Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names);
PyObject *names;
static PyObject *empty_string;

if (!empty_string) {
empty_string = PyUnicode_FromString("");
Expand DownExpand Up@@ -3146,17 +3150,18 @@ compiler_from_import(struct compiler *c, stmt_ty s)
return 1;
}

static PyObject *cached_name_assertion_error = NULL;

static int
compiler_assert(struct compiler *c, stmt_ty s)
{
static PyObject *assertion_error = NULL;
basicblock *end;

if (c->c_optimize)
return 1;
if (assertion_error == NULL) {
assertion_error = PyUnicode_InternFromString("AssertionError");
if (assertion_error == NULL)
if (cached_name_assertion_error == NULL) {
cached_name_assertion_error = PyUnicode_InternFromString("AssertionError");
if (cached_name_assertion_error == NULL)
return 0;
}
if (s->v.Assert.test->kind == Tuple_kind &&
Expand All@@ -3173,7 +3178,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
return 0;
if (!compiler_jump_if(c, s->v.Assert.test, end, 1))
return 0;
ADDOP_O(c, LOAD_GLOBAL,assertion_error, names);
ADDOP_O(c, LOAD_GLOBAL,cached_name_assertion_error, names);
if (s->v.Assert.msg) {
VISIT(c, expr, s->v.Assert.msg);
ADDOP_I(c, CALL_FUNCTION, 1);
Expand DownExpand Up@@ -4449,63 +4454,67 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type,
return 0;
}

static identifier cached_name_getexpr;

static int
compiler_genexp(struct compiler *c, expr_ty e)
{
static identifier name;
if (!name) {
name = PyUnicode_InternFromString("<genexpr>");
if (!name)
if (!cached_name_getexpr) {
cached_name_getexpr = PyUnicode_InternFromString("<genexpr>");
if (!cached_name_getexpr)
return 0;
}
assert(e->kind == GeneratorExp_kind);
return compiler_comprehension(c, e, COMP_GENEXP,name,
return compiler_comprehension(c, e, COMP_GENEXP,cached_name_getexpr,
e->v.GeneratorExp.generators,
e->v.GeneratorExp.elt, NULL);
}

static identifier cached_name_listcomp;

static int
compiler_listcomp(struct compiler *c, expr_ty e)
{
static identifier name;
if (!name) {
name = PyUnicode_InternFromString("<listcomp>");
if (!name)
if (!cached_name_listcomp) {
cached_name_listcomp = PyUnicode_InternFromString("<listcomp>");
if (!cached_name_listcomp)
return 0;
}
assert(e->kind == ListComp_kind);
return compiler_comprehension(c, e, COMP_LISTCOMP,name,
return compiler_comprehension(c, e, COMP_LISTCOMP,cached_name_listcomp,
e->v.ListComp.generators,
e->v.ListComp.elt, NULL);
}

static identifier cached_name_setcomp;

static int
compiler_setcomp(struct compiler *c, expr_ty e)
{
static identifier name;
if (!name) {
name = PyUnicode_InternFromString("<setcomp>");
if (!name)
if (!cached_name_setcomp) {
cached_name_setcomp = PyUnicode_InternFromString("<setcomp>");
if (!cached_name_setcomp)
return 0;
}
assert(e->kind == SetComp_kind);
return compiler_comprehension(c, e, COMP_SETCOMP,name,
return compiler_comprehension(c, e, COMP_SETCOMP,cached_name_setcomp,
e->v.SetComp.generators,
e->v.SetComp.elt, NULL);
}


static identifier cached_name_dictcomp;

static int
compiler_dictcomp(struct compiler *c, expr_ty e)
{
static identifier name;
if (!name) {
name = PyUnicode_InternFromString("<dictcomp>");
if (!name)
if (!cached_name_dictcomp) {
cached_name_dictcomp = PyUnicode_InternFromString("<dictcomp>");
if (!cached_name_dictcomp)
return 0;
}
assert(e->kind == DictComp_kind);
return compiler_comprehension(c, e, COMP_DICTCOMP,name,
return compiler_comprehension(c, e, COMP_DICTCOMP,cached_name_dictcomp,
e->v.DictComp.generators,
e->v.DictComp.key, e->v.DictComp.value);
}
Expand Down
4 changes: 2 additions & 2 deletionsPython/dtoa.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -686,7 +686,7 @@ pow5mult(Bigint *b, int k)
{
Bigint *b1, *p5, *p51;
int i;
static const int p05[3] = { 5, 25, 125 };
static const int p05[3] = { 5, 25, 125 }; // Static is okay here (immutable data).

if ((i = k & 3)) {
b = multadd(b, p05[i-1], 0);
Expand DownExpand Up@@ -742,7 +742,7 @@ pow5mult(Bigint *b, int k)
{
Bigint *b1, *p5, *p51;
int i;
static const int p05[3] = { 5, 25, 125 };
static const int p05[3] = { 5, 25, 125 }; // Static is okay here (immutable data).

if ((i = k & 3)) {
b = multadd(b, p05[i-1], 0);
Expand Down
2 changes: 1 addition & 1 deletionPython/dynamic_annotations.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,7 @@ static int GetRunningOnValgrind(void) {

/* See the comments in dynamic_annotations.h */
int RunningOnValgrind(void) {
static volatile int running_on_valgrind = -1;
static volatile int running_on_valgrind = -1; // Static is okay here (process-global).
/* C doesn't have thread-safe initialization of statics, and we
don't want to depend on pthread_once here, so hack it. */
int local_running_on_valgrind = running_on_valgrind;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp