8000 closes bpo-32460: ensure all non-static globals have initializers (#5… · python/cpython@0a37a30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a37a30

Browse files
authored
closes bpo-32460: ensure all non-static globals have initializers (#5061)
1 parent 6c6d3a4 commit 0a37a30

File tree

9 files changed

+60
-61
lines changed

9 files changed

+60
-61
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ bytes(cdata)
116116
#endif
117117
#include "ctypes.h"
118118

119-
PyObject *PyExc_ArgError;
119+
PyObject *PyExc_ArgError = NULL;
120120

121121
/* This dict maps ctypes types to POINTER types */
122-
PyObject *_ctypes_ptrtype_cache;
122+
PyObject *_ctypes_ptrtype_cache = NULL;
123123

124124
static PyTypeObject Simple_Type;
125125

Modules/_ctypes/_ctypes_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct {
6363
} TestReg;
6464

6565

66-
EXPORT(TestReg) last_tfrsuv_arg;
66+
EXPORT(TestReg) last_tfrsuv_arg = {0};
6767

6868

6969
EXPORT(void)
@@ -410,8 +410,8 @@ EXPORT(void) _py_func(void)
410410
{
411411
}
412412

413-
EXPORT(long long) last_tf_arg_s;
414-
EXPORT(unsigned long long) last_tf_arg_u;
413+
EXPORT(long long) last_tf_arg_s = 0;
414+
EXPORT(unsigned long long) last_tf_arg_u = 0;
415415

416416
struct BITS {
417417
int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;

Modules/_io/_iomodule.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@
2626

2727
/* Various interned strings */
2828

29-
PyObject *_PyIO_str_close;
30-
PyObject *_PyIO_str_closed;
31-
PyObject *_PyIO_str_decode;
32-
PyObject *_PyIO_str_encode;
33-
PyObject *_PyIO_str_fileno;
34-
PyObject *_PyIO_str_flush;
35-
PyObject *_PyIO_str_getstate;
36-
PyObject *_PyIO_str_isatty;
37-
PyObject *_PyIO_str_newlines;
38-
PyObject *_PyIO_str_nl;
39-
PyObject *_PyIO_str_read;
40-
PyObject *_PyIO_str_read1;
41-
PyObject *_PyIO_str_readable;
42-
PyObject *_PyIO_str_readall;
43-
PyObject *_PyIO_str_readinto;
44-
PyObject *_PyIO_str_readline;
45-
PyObject *_PyIO_str_reset;
46-
PyObject *_PyIO_str_seek;
47-
PyObject *_PyIO_str_seekable;
48-
PyObject *_PyIO_str_setstate;
49-
PyObject *_PyIO_str_tell;
50-
PyObject *_PyIO_str_truncate;
51-
PyObject *_PyIO_str_writable;
52-
PyObject *_PyIO_str_write;
53-
54-
PyObject *_PyIO_empty_str;
55-
PyObject *_PyIO_empty_bytes;
29+
PyObject *_PyIO_str_close = NULL;
30+
PyObject *_PyIO_str_closed = NULL;
31+
PyObject *_PyIO_str_decode = NULL;
32+
PyObject *_PyIO_str_encode = NULL;
33+
PyObject *_PyIO_str_fileno = NULL;
34+
PyObject *_PyIO_str_flush = NULL;
35+
PyObject *_PyIO_str_getstate = NULL;
36+
PyObject *_PyIO_str_isatty = NULL;
37+
PyObject *_PyIO_str_newlines = NULL;
38+
PyObject *_PyIO_str_nl = NULL;
39+
PyObject *_PyIO_str_read = NULL;
40+
PyObject *_PyIO_str_read1 = NULL;
41+
PyObject *_PyIO_str_readable = NULL;
42+
PyObject *_PyIO_str_readall = NULL;
43+
PyObject *_PyIO_str_readinto = NULL;
44+
PyObject *_PyIO_str_readline = NULL;
45+
PyObject *_PyIO_str_reset = NULL;
46+
PyObject *_PyIO_str_seek = NULL;
47+
PyObject *_PyIO_str_seekable = NULL;
48+
PyObject *_PyIO_str_setstate = NULL;
49+
PyObject *_PyIO_str_tell = NULL;
50+
PyObject *_PyIO_str_truncate = NULL;
51+
PyObject *_PyIO_str_writable = NULL;
52+
PyObject *_PyIO_str_write = NULL;
53+
54+
PyObject *_PyIO_empty_str = NULL;
55+
PyObject *_PyIO_empty_bytes = NULL;
5656

5757
PyDoc_STRVAR(module_doc,
5858
"The io module provides the Python interfaces to stream handling. The\n"

Modules/_sqlite/microprotocols.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
/** the adapters registry **/
3535

36-
PyObject *psyco_adapters;
36+
static PyObject *psyco_adapters = NULL;
3737

3838
/* pysqlite_microprotocols_init - initialize the adapters dictionary */
3939

Modules/_sqlite/microprotocols.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828

2929
#include <Python.h>
3030

31-
/** adapters registry **/
32-
33-
extern PyObject *psyco_adapters;
34-
3531
/** the names of the three mandatory methods **/
3632

3733
#define MICROPROTOCOLS_GETQUOTED_NAME "getquoted"

Modules/_sqlite/module.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@
3535

3636
/* static objects at module-level */
3737

38-
PyObject* pysqlite_Error, *pysqlite_Warning, *pysqlite_InterfaceError, *pysqlite_DatabaseError,
39-
*pysqlite_InternalError, *pysqlite_OperationalError, *pysqlite_ProgrammingError,
40-
*pysqlite_IntegrityError, *pysqlite_DataError, *pysqlite_NotSupportedError;
41-
42-
PyObject* converters;
43-
int _enable_callback_tracebacks;
44-
int pysqlite_BaseTypeAdapted;
38+
PyObject *pysqlite_Error = NULL;
39+
PyObject *pysqlite_Warning = NULL;
40+
PyObject *pysqlite_InterfaceError = NULL;
41+
PyObject *pysqlite_DatabaseError = NULL;
42+
PyObject *pysqlite_InternalError = NULL;
43+
PyObject *pysqlite_OperationalError = NULL;
44+
PyObject *pysqlite_ProgrammingError = NULL;
45+
PyObject *pysqlite_IntegrityError = NULL;
46+
PyObject *pysqlite_DataError = NULL;
47+
PyObject *pysqlite_NotSupportedError = NULL;
48+
49+
PyObject* converters = NULL;
50+
int _enable_callback_tracebacks = 0;
51+
int pysqlite_BaseTypeAdapted = 0;
4552

4653
static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
4754
kwargs)
@@ -461,10 +468,6 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
461468
/* initialize the default converters */
462469
converters_init(dict);
463470

464-
_enable_callback_tracebacks = 0;
465-
466-
pysqlite_BaseTypeAdapted = 0;
467-
468471
error:
469472
if (PyErr_Occurred())
470473
{

Parser/myreadline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif /* MS_WINDOWS */
1818

1919

20-
PyThreadState* _PyOS_ReadlineTState;
20+
PyThreadState* _PyOS_ReadlineTState = NULL;
2121

2222
#include "pythread.h"
2323
static PyThread_type_lock _PyOS_ReadlineLock = NULL;
@@ -284,7 +284,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
284284
285285
Note: Python expects in return a buffer allocated with PyMem_Malloc. */
286286

287-
char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *);
287+
char *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, const char *) = NULL;
288288

289289

290290
/* Interface used by tokenizer.c and bltinmodule.c */

Python/pyhash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
extern "C" {
1818
#endif
1919

20-
_Py_HashSecret_t _Py_HashSecret;
20+
_Py_HashSecret_t _Py_HashSecret = {0};
2121

2222
#if Py_HASH_ALGORITHM == Py_HASH_EXTERNAL
2323
extern PyHash_FuncDef PyHash_Func;

Python/pylifecycle.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ _Py_IsFinalizing(void)
108108

109109
/* Global configuration variable declarations are in pydebug.h */
110110
/* XXX (ncoghlan): move those declarations to pylifecycle.h? */
111-
int Py_DebugFlag; /* Needed by parser.c */
112-
int Py_VerboseFlag; /* Needed by import.c */
113-
int Py_QuietFlag; /* Needed by sysmodule.c */
114-
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
115-
int Py_InspectFlag; /* Needed to determine whether to exit at SystemExit */
111+
int Py_DebugFlag = 0; /* Needed by parser.c */
112+
int Py_VerboseFlag = 0; /* Needed by import.c */
113+
int Py_QuietFlag = 0; /* Needed by sysmodule.c */
114+
int Py_InteractiveFlag = 0; /* Needed by Py_FdIsInteractive() below */
115+
int Py_InspectFlag = 0; /* Needed to determine whether to exit at SystemExit */
116116
int Py_OptimizeFlag = 0; /* Needed by compile.c */
117-
int Py_NoSiteFlag; /* Suppress 'import site' */
118-
int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
119-
int Py_FrozenFlag; /* Needed by getpath.c */
120-
int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
121-
int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.pyc) */
117+
int Py_NoSiteFlag = 0; /* Suppress 'import site' */
118+
int Py_BytesWarningFlag = 0; /* Warn on str(bytes) and str(buffer) */
119+
int Py_FrozenFlag = 0; /* Needed by getpath.c */
120+
int Py_IgnoreEnvironmentFlag = 0; /* e.g. PYTHONPATH, PYTHONHOME */
121+
int Py_DontWriteBytecodeFlag = 0; /* Suppress writing bytecode files (*.pyc) */
122122
int Py_NoUserSiteDirectory = 0; /* for -s and site.py */
123123
int Py_UnbufferedStdioFlag = 0; /* Unbuffered binary std{in,out,err} */
124124
int Py_HashRandomizationFlag = 0; /* for -R and PYTHONHASHSEED */

0 commit comments

Comments
 (0)
0