Files
Python3-Win9x/compat/msvc600/cpython-3.11.16-vc6-headers.patch
T

8559 lines
316 KiB
Diff

diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index b018dab..8691994 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -45,7 +45,11 @@ typedef struct _Py_Identifier {
// For now we are keeping _Py_IDENTIFIER for continued use
// in non-builtin extensions (and naughty PyPI modules).
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define _Py_static_string_init(value) { value, -1 }
+#else
#define _Py_static_string_init(value) { .string = value, .index = -1 }
+#endif
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
diff --git a/Include/internal/pycore_atomic.h b/Include/internal/pycore_atomic.h
index 425d69f..748de28 100644
--- a/Include/internal/pycore_atomic.h
+++ b/Include/internal/pycore_atomic.h
@@ -16,7 +16,21 @@ extern "C" {
#endif
-#if defined(_MSC_VER)
+/* Visual C++ 6.0 (_MSC_VER 1200) predates <intrin.h> and the _Interlocked*
+ * compiler intrinsics (both introduced in Visual Studio 2005, _MSC_VER
+ * 1400) as well as <immintrin.h>. This port only targets 32-bit x86 under
+ * VC6, so gate the modern-MSVC include on that combination and give VC6/x86
+ * a project-local branch below (_Py_ATOMIC_VC6_X86) built on the Win32
+ * Interlocked* API instead. Every other compiler/version keeps the
+ * unmodified upstream behavior.
+ */
+#if defined(_MSC_VER) && _MSC_VER < 1300 && defined(_M_IX86)
+# define _Py_ATOMIC_VC6_X86 1
+ /* Declares InterlockedExchange()/InterlockedCompareExchange(), used by
+ * the _Py_ATOMIC_VC6_X86 branch below in place of the _Interlocked*
+ * intrinsics the modern-MSVC branch gets from <intrin.h>. */
+# include <windows.h>
+#elif defined(_MSC_VER)
#include <intrin.h>
#if defined(_M_IX86) || defined(_M_X64)
# include <immintrin.h>
@@ -238,7 +252,87 @@ _Py_ANNOTATE_MEMORY_ORDER(const volatile void *address, _Py_memory_order order)
This might affect performance but likely only in some very specific and
hard to measure scenario.
*/
-#if defined(_M_IX86) || defined(_M_X64)
+#if defined(_Py_ATOMIC_VC6_X86)
+/* VC6 / Windows 9x, 32-bit x86 only (_M_X64 is never defined by VC6).
+ VC6 has neither <intrin.h>/_Interlocked* compiler intrinsics (Visual
+ Studio 2005+) nor the _HLEAcquire/_HLERelease hardware-lock-elision
+ variants (Visual Studio 2013+) used by the modern-MSVC branch below.
+ Substitute the plain Win32 InterlockedExchange/InterlockedCompareExchange
+ functions, which are exported by KERNEL32.DLL on Windows 98 (this VC6
+ SDK's WINBASE.H declares them for _M_IX86 as compiler-intrinsic-backed
+ APIs, not the newer MRx000/Alpha-only intrinsic path above them in that
+ header). Like the modern-MSVC intrinsics, these give a full memory
+ barrier, so -- as with the HLE fallback described above -- every
+ _Py_memory_order maps to the same fully-fenced operation; there is no
+ separate acquire/release-only path to take.
+
+ _Py_atomic_address (uintptr_t) and _Py_atomic_int (int) are both 4
+ bytes on this 32-bit-only target, so the 64-bit store/load paths used
+ by the modern-MSVC branch below (guarded there by `sizeof(...) == 8`)
+ are unreachable here and are intentionally not implemented: this port
+ has no Win9x-era substitute for CMPXCHG8B-based 64-bit atomics. Fail
+ loudly at compile time rather than silently mishandling a 64-bit
+ target if this header is ever pulled into a VC6 build configured for
+ one (VC6 itself never defines _M_X64, so this should not trigger).
+*/
+#if defined(_M_X64)
+#error "VC6 64-bit atomics are not implemented; this port only targets 32-bit x86 (_M_IX86)."
+#endif
+
+typedef enum _Py_memory_order {
+ _Py_memory_order_relaxed,
+ _Py_memory_order_acquire,
+ _Py_memory_order_release,
+ _Py_memory_order_acq_rel,
+ _Py_memory_order_seq_cst
+} _Py_memory_order;
+
+typedef struct _Py_atomic_address {
+ volatile uintptr_t _value;
+} _Py_atomic_address;
+
+typedef struct _Py_atomic_int {
+ volatile int _value;
+} _Py_atomic_int;
+
+static __inline long
+_Py_vc6_InterlockedExchange(volatile long *target, long value)
+{
+ return InterlockedExchange((LPLONG)target, value);
+}
+
+static __inline long
+_Py_vc6_InterlockedCompareExchange(volatile long *destination, long exchange, long comperand)
+{
+ return (long)InterlockedCompareExchange(
+ (PVOID *)destination, (PVOID)exchange, (PVOID)comperand);
+}
+
+#define _Py_atomic_store_32bit(ATOMIC_VAL, NEW_VAL, ORDER) \
+ ((void)_Py_vc6_InterlockedExchange( \
+ (volatile long *)&((ATOMIC_VAL)->_value), (long)(NEW_VAL)))
+
+static __inline int
+_Py_atomic_load_32bit_impl(volatile int *value, int order)
+{
+ long old;
+ (void)order;
+ do {
+ old = *(volatile long *)value;
+ } while (_Py_vc6_InterlockedCompareExchange((volatile long *)value, old, old) != old);
+ return (int)old;
+}
+
+#define _Py_atomic_load_32bit(ATOMIC_VAL, ORDER) \
+ _Py_atomic_load_32bit_impl((volatile int *)&((ATOMIC_VAL)->_value), (ORDER))
+
+#define _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, ORDER) \
+ _Py_atomic_store_32bit((ATOMIC_VAL), (NEW_VAL), (ORDER))
+
+#define _Py_atomic_load_explicit(ATOMIC_VAL, ORDER) \
+ _Py_atomic_load_32bit((ATOMIC_VAL), (ORDER))
+
+#elif defined(_M_IX86) || defined(_M_X64)
typedef enum _Py_memory_order {
_Py_memory_order_relaxed,
_Py_memory_order_acquire,
diff --git a/Include/internal/pycore_call.h b/Include/internal/pycore_call.h
index 3ccacfa..3098e1e 100644
--- a/Include/internal/pycore_call.h
+++ b/Include/internal/pycore_call.h
@@ -38,18 +38,21 @@ extern PyObject * _PyObject_CallMethodFormat(
static inline vectorcallfunc
_PyVectorcall_FunctionInline(PyObject *callable)
{
+ PyTypeObject *tp;
+ Py_ssize_t offset;
+ vectorcallfunc ptr;
+
assert(callable != NULL);
- PyTypeObject *tp = Py_TYPE(callable);
+ tp = Py_TYPE(callable);
if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL)) {
return NULL;
}
assert(PyCallable_Check(callable));
- Py_ssize_t offset = tp->tp_vectorcall_offset;
+ offset = tp->tp_vectorcall_offset;
assert(offset > 0);
- vectorcallfunc ptr;
memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
return ptr;
}
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index 3a24a65..4db8abc 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -149,18 +149,20 @@ typedef unsigned char _PyLocals_Kind;
static inline _PyLocals_Kind
_PyLocals_GetKind(PyObject *kinds, int i)
{
+ char *ptr;
assert(PyBytes_Check(kinds));
assert(0 <= i && i < PyBytes_GET_SIZE(kinds));
- char *ptr = PyBytes_AS_STRING(kinds);
+ ptr = PyBytes_AS_STRING(kinds);
return (_PyLocals_Kind)(ptr[i]);
}
static inline void
_PyLocals_SetKind(PyObject *kinds, int i, _PyLocals_Kind kind)
{
+ char *ptr;
assert(PyBytes_Check(kinds));
assert(0 <= i && i < PyBytes_GET_SIZE(kinds));
- char *ptr = PyBytes_AS_STRING(kinds);
+ ptr = PyBytes_AS_STRING(kinds);
ptr[i] = (char) kind;
}
@@ -520,11 +522,12 @@ adaptive_counter_start(void) {
static inline uint16_t
adaptive_counter_backoff(uint16_t counter) {
unsigned int backoff = counter & ((1<<ADAPTIVE_BACKOFF_BITS)-1);
+ unsigned int value;
backoff++;
if (backoff > MAX_BACKOFF_VALUE) {
backoff = MAX_BACKOFF_VALUE;
}
- unsigned int value = (1 << backoff) - 1;
+ value = (1 << backoff) - 1;
return adaptive_counter_bits(value, backoff);
}
diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h
index dc308fe..16feaf3 100644
--- a/Include/internal/pycore_dict.h
+++ b/Include/internal/pycore_dict.h
@@ -163,9 +163,11 @@ extern PyObject *_PyDict_FromItems(
static inline void
_PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
{
+ uint8_t *size_ptr;
+ int size;
assert(ix < SHARED_KEYS_MAX_SIZE);
- uint8_t *size_ptr = ((uint8_t *)values)-2;
- int size = *size_ptr;
+ size_ptr = ((uint8_t *)values)-2;
+ size = *size_ptr;
assert(size+2 < ((uint8_t *)values)[-1]);
size++;
size_ptr[-size] = (uint8_t)ix;
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
index 4866ea2..17ca4f8 100644
--- a/Include/internal/pycore_frame.h
+++ b/Include/internal/pycore_frame.h
@@ -162,9 +162,10 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame);
static inline PyFrameObject *
_PyFrame_GetFrameObject(_PyInterpreterFrame *frame)
{
+ PyFrameObject *res;
assert(!_PyFrame_IsIncomplete(frame));
- PyFrameObject *res = frame->frame_obj;
+ res = frame->frame_obj;
if (res != NULL) {
return res;
}
@@ -211,7 +212,9 @@ static inline _PyInterpreterFrame *
_PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
{
if (_PyThreadState_HasStackSpace(tstate, size)) {
- _PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->datastack_top;
+ _PyInterpreterFrame *res;
+
+ res = (_PyInterpreterFrame *)tstate->datastack_top;
tstate->datastack_top += size;
return res;
}
@@ -229,8 +232,10 @@ int _PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame);
static inline
PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame)
{
+ size_t offset_in_gen;
+
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
- size_t offset_in_gen = offsetof(PyGenObject, gi_iframe);
+ offset_in_gen = offsetof(PyGenObject, gi_iframe);
return (PyGenObject *)(((char *)frame) - offset_in_gen);
}
diff --git a/Include/internal/pycore_initconfig.h b/Include/internal/pycore_initconfig.h
index d765600..dcdd359 100644
--- a/Include/internal/pycore_initconfig.h
+++ b/Include/internal/pycore_initconfig.h
@@ -14,22 +14,56 @@ struct pyruntimestate;
/* --- PyStatus ----------------------------------------------- */
/* Almost all errors causing Python initialization to fail */
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ /* VC6 has neither C99 __func__ nor later MSVC __FUNCTION__. */
+# define _PyStatus_GET_FUNC() NULL
+#elif defined(_MSC_VER)
/* Visual Studio 2015 doesn't implement C99 __func__ in C */
# define _PyStatus_GET_FUNC() __FUNCTION__
#else
# define _PyStatus_GET_FUNC() __func__
#endif
-#define _PyStatus_OK() \
+#if defined(_MSC_VER) && _MSC_VER < 1300
+/* VC6 cannot parse the C99 compound literals/designated initializers below.
+ Keep the helpers local to this internal header and construct the status
+ objects field-by-field so PyStatus_Ok() can safely return _PyStatus_OK()
+ without recursing back into itself. */
+static PyStatus
+_PyStatus_OK_VC6(void)
+{
+ PyStatus status;
+ status._type = _PyStatus_TYPE_OK;
+ status.func = NULL;
+ status.err_msg = NULL;
+ status.exitcode = 0;
+ return status;
+}
+
+static PyStatus
+_PyStatus_ERR_VC6(const char *err_msg)
+{
+ PyStatus status;
+ status._type = _PyStatus_TYPE_ERROR;
+ status.func = _PyStatus_GET_FUNC();
+ status.err_msg = err_msg;
+ status.exitcode = 0;
+ return status;
+}
+
+# define _PyStatus_OK() _PyStatus_OK_VC6()
+# define _PyStatus_ERR(ERR_MSG) _PyStatus_ERR_VC6(ERR_MSG)
+#else
+# define _PyStatus_OK() \
(PyStatus){._type = _PyStatus_TYPE_OK,}
/* other fields are set to 0 */
-#define _PyStatus_ERR(ERR_MSG) \
+# define _PyStatus_ERR(ERR_MSG) \
(PyStatus){ \
._type = _PyStatus_TYPE_ERROR, \
.func = _PyStatus_GET_FUNC(), \
.err_msg = (ERR_MSG)}
/* other fields are set to 0 */
+#endif
#define _PyStatus_NO_MEMORY() _PyStatus_ERR("memory allocation failed")
#define _PyStatus_EXIT(EXITCODE) \
(PyStatus){ \
diff --git a/Include/internal/pycore_list.h b/Include/internal/pycore_list.h
index 860dce1..da38ee6 100644
--- a/Include/internal/pycore_list.h
+++ b/Include/internal/pycore_list.h
@@ -43,10 +43,12 @@ _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem);
static inline int
_PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)
{
+ Py_ssize_t len;
+ Py_ssize_t allocated;
assert(self != NULL && newitem != NULL);
assert(PyList_Check(self));
- Py_ssize_t len = PyList_GET_SIZE(self);
- Py_ssize_t allocated = self->allocated;
+ len = PyList_GET_SIZE(self);
+ allocated = self->allocated;
assert((size_t)len + 1 < PY_SSIZE_T_MAX);
if (allocated > len) {
PyList_SET_ITEM(self, len, newitem);
diff --git a/Include/internal/pycore_moduleobject.h b/Include/internal/pycore_moduleobject.h
index 76361b8..2b9861b 100644
--- a/Include/internal/pycore_moduleobject.h
+++ b/Include/internal/pycore_moduleobject.h
@@ -29,8 +29,10 @@ static inline void* _PyModule_GetState(PyObject* mod) {
}
static inline PyObject* _PyModule_GetDict(PyObject *mod) {
+ PyObject *dict;
+
assert(PyModule_Check(mod));
- PyObject *dict = ((PyModuleObject *)mod) -> md_dict;
+ dict = ((PyModuleObject *)mod) -> md_dict;
// _PyModule_GetDict(mod) must not be used after calling module_clear(mod)
assert(dict != NULL);
return dict;
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index f022f82..d1c55ae 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -14,6 +14,14 @@ extern "C" {
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_runtime.h" // _PyRuntime
+/* Visual C++ 6.0 predates C99's __func__ predefined identifier. It also
+ lacks MSVC's later __FUNCTION__ extension, so provide a VC6-only fallback
+ for debug/fatal diagnostics in this header without changing any other
+ compiler's function-name reporting. */
+#if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(__func__)
+# define __func__ "<unknown>"
+#endif
+
#define _PyObject_IMMORTAL_INIT(type) \
{ \
.ob_refcnt = 999999999, \
@@ -125,19 +133,24 @@ static inline void _PyObject_GC_TRACK(
#endif
PyObject *op)
{
+ PyGC_Head *gc;
+ PyInterpreterState *interp;
+ PyGC_Head *generation0;
+ PyGC_Head *last;
+
_PyObject_ASSERT_FROM(op, !_PyObject_GC_IS_TRACKED(op),
"object already tracked by the garbage collector",
filename, lineno, __func__);
- PyGC_Head *gc = _Py_AS_GC(op);
+ gc = _Py_AS_GC(op);
_PyObject_ASSERT_FROM(op,
(gc->_gc_prev & _PyGC_PREV_MASK_COLLECTING) == 0,
"object is in generation which is garbage collected",
filename, lineno, __func__);
- PyInterpreterState *interp = _PyInterpreterState_GET();
- PyGC_Head *generation0 = interp->gc.generation0;
- PyGC_Head *last = (PyGC_Head*)(generation0->_gc_prev);
+ interp = _PyInterpreterState_GET();
+ generation0 = interp->gc.generation0;
+ last = (PyGC_Head*)(generation0->_gc_prev);
_PyGCHead_SET_NEXT(last, gc);
_PyGCHead_SET_PREV(gc, last);
_PyGCHead_SET_NEXT(gc, generation0);
@@ -161,13 +174,17 @@ static inline void _PyObject_GC_UNTRACK(
#endif
PyObject *op)
{
+ PyGC_Head *gc;
+ PyGC_Head *prev;
+ PyGC_Head *next;
+
_PyObject_ASSERT_FROM(op, _PyObject_GC_IS_TRACKED(op),
"object not tracked by the garbage collector",
filename, lineno, __func__);
- PyGC_Head *gc = _Py_AS_GC(op);
- PyGC_Head *prev = _PyGCHead_PREV(gc);
- PyGC_Head *next = _PyGCHead_NEXT(gc);
+ gc = _Py_AS_GC(op);
+ prev = _PyGCHead_PREV(gc);
+ next = _PyGCHead_NEXT(gc);
_PyGCHead_SET_NEXT(prev, next);
_PyGCHead_SET_PREV(next, prev);
gc->_gc_next = 0;
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index 13eae1e..91faff4 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -14,6 +14,11 @@ extern "C" {
/* The static initializers defined here should only be used
in the runtime init code (in pystate.c and pylifecycle.c). */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+/* VC6 does not support the nested C99 designated initializers below.
+ pystate.c provides a field-by-field initializer for the same defaults. */
+extern void _PyRuntimeState_InitStaticDefaults(_PyRuntimeState *runtime);
+#else
#define _PyRuntimeState_INIT \
{ \
@@ -72,6 +77,8 @@ extern "C" {
.context_ver = 1, \
}
+#endif /* !(defined(_MSC_VER) && _MSC_VER < 1300) */
+
// global objects
diff --git a/Include/longobject.h b/Include/longobject.h
index 778cb62..d25edf7 100644
--- a/Include/longobject.h
+++ b/Include/longobject.h
@@ -81,12 +81,12 @@ PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
-PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
-PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
-PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
-PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
-PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
-PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
+PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
+PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);
+PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
+PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
+PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
+PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
diff --git a/Include/pyexpat.h b/Include/pyexpat.h
index a676e16..017e86d 100644
--- a/Include/pyexpat.h
+++ b/Include/pyexpat.h
@@ -54,12 +54,12 @@ struct PyExpat_CAPI
XML_Bool (*SetReparseDeferralEnabled)(XML_Parser parser, XML_Bool enabled);
/* might be NULL for expat < 2.7.2 */
XML_Bool (*SetAllocTrackerActivationThreshold)(
- XML_Parser parser, unsigned long long activationThresholdBytes);
+ XML_Parser parser, unsigned PY_LONG_LONG activationThresholdBytes);
XML_Bool (*SetAllocTrackerMaximumAmplification)(
XML_Parser parser, float maxAmplificationFactor);
/* might be NULL for expat < 2.4.0 */
XML_Bool (*SetBillionLaughsAttackProtectionActivationThreshold)(
- XML_Parser parser, unsigned long long activationThresholdBytes);
+ XML_Parser parser, unsigned PY_LONG_LONG activationThresholdBytes);
XML_Bool (*SetBillionLaughsAttackProtectionMaximumAmplification)(
XML_Parser parser, float maxAmplificationFactor);
/* might be NULL for expat < 2.8.0 */
diff --git a/Include/pymath.h b/Include/pymath.h
index 772b67e..7b90016 100644
--- a/Include/pymath.h
+++ b/Include/pymath.h
@@ -52,10 +52,13 @@
// Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN).
#if !defined(Py_NAN)
-# if _Py__has_builtin(__builtin_nan)
+# if defined(_MSC_VER) && _MSC_VER < 1300
+ // VC6 has no C99 NAN macro. IEEE infinity times zero produces NaN.
+# define Py_NAN (Py_HUGE_VAL * 0.0)
+# elif _Py__has_builtin(__builtin_nan)
// Built-in implementation of the ISO C99 function nan(): quiet NaN.
# define Py_NAN (__builtin_nan(""))
-#else
+# else
// Use C99 NAN constant: quiet Not-A-Number.
// NAN is a float, Py_NAN is a double: cast to double.
# define Py_NAN ((double)NAN)
diff --git a/Include/pyport.h b/Include/pyport.h
index b3b8b6f..938d131 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -97,6 +97,13 @@ Used in: Py_SAFE_DOWNCAST
#define PY_ULLONG_MAX ULLONG_MAX
#endif
+/* Spelling of 64 bit integer literal suffixes; see PC/pyconfig.h for the
+ compilers that need something other than the C99 LL/ULL suffixes. */
+#ifndef PY_LL
+#define PY_LL(x) x##LL
+#define PY_ULL(x) x##ULL
+#endif
+
#define PY_UINT32_T uint32_t
#define PY_UINT64_T uint64_t
@@ -334,9 +341,12 @@ extern "C" {
#if defined(__GNUC__) \
&& ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
#define Py_DEPRECATED(VERSION) __declspec(deprecated( \
"deprecated in " #VERSION))
+#elif defined(_MSC_VER)
+/* Visual C++ 6.0 has no supported deprecation declaration syntax. */
+#define Py_DEPRECATED(VERSION_UNUSED)
#else
#define Py_DEPRECATED(VERSION_UNUSED)
#endif
@@ -352,10 +362,14 @@ extern "C" {
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
#define _Py_COMP_DIAG_PUSH __pragma(warning(push))
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
#define _Py_COMP_DIAG_POP __pragma(warning(pop))
+#elif defined(_MSC_VER)
+#define _Py_COMP_DIAG_PUSH
+#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
+#define _Py_COMP_DIAG_POP
#else
#define _Py_COMP_DIAG_PUSH
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
@@ -425,7 +439,7 @@ extern "C" {
// Py_NO_INLINE static int random(void) { return 4; }
#if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
# define Py_NO_INLINE __attribute__ ((noinline))
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
# define Py_NO_INLINE __declspec(noinline)
#else
# define Py_NO_INLINE
diff --git a/Include/pythread.h b/Include/pythread.h
index a483290..defdaf1 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -40,23 +40,23 @@ PyAPI_FUNC(int) PyThread_acquire_lock(PyThread_type_lock, int);
module exposes a higher-level API, with timeouts expressed in seconds
and floating-point numbers allowed.
*/
-#define PY_TIMEOUT_T long long
+#define PY_TIMEOUT_T PY_LONG_LONG
#if defined(_POSIX_THREADS)
/* PyThread_acquire_lock_timed() uses _PyTime_FromNanoseconds(us * 1000),
convert microseconds to nanoseconds. */
-# define PY_TIMEOUT_MAX (LLONG_MAX / 1000)
+# define PY_TIMEOUT_MAX (PY_LLONG_MAX / 1000)
#elif defined (NT_THREADS)
// WaitForSingleObject() accepts timeout in milliseconds in the range
// [0; 0xFFFFFFFE] (DWORD type). INFINITE value (0xFFFFFFFF) means no
// timeout. 0xFFFFFFFE milliseconds is around 49.7 days.
-# if 0xFFFFFFFELL * 1000 < LLONG_MAX
-# define PY_TIMEOUT_MAX (0xFFFFFFFELL * 1000)
+# if PY_LL(0xFFFFFFFE) * 1000 < PY_LLONG_MAX
+# define PY_TIMEOUT_MAX (PY_LL(0xFFFFFFFE) * 1000)
# else
-# define PY_TIMEOUT_MAX LLONG_MAX
+# define PY_TIMEOUT_MAX PY_LLONG_MAX
# endif
#else
-# define PY_TIMEOUT_MAX LLONG_MAX
+# define PY_TIMEOUT_MAX PY_LLONG_MAX
#endif
diff --git a/Modules/_abc.c b/Modules/_abc.c
index b22daa8..69cfd5c 100644
--- a/Modules/_abc.c
+++ b/Modules/_abc.c
@@ -19,7 +19,7 @@ PyDoc_STRVAR(_abc__doc__,
typedef struct {
PyTypeObject *_abc_data_type;
- unsigned long long abc_invalidation_counter;
+ unsigned PY_LONG_LONG abc_invalidation_counter;
} _abcmodule_state;
static inline _abcmodule_state*
@@ -38,7 +38,7 @@ typedef struct {
PyObject *_abc_registry;
PyObject *_abc_cache; /* Normal set of weak references. */
PyObject *_abc_negative_cache; /* Normal set of weak references. */
- unsigned long long _abc_negative_cache_version;
+ unsigned PY_LONG_LONG _abc_negative_cache_version;
} _abc_data;
static int
@@ -63,8 +63,9 @@ abc_data_clear(_abc_data *self)
static void
abc_data_dealloc(_abc_data *self)
{
+ PyTypeObject *tp;
PyObject_GC_UnTrack(self);
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
(void)abc_data_clear(self);
tp->tp_free(self);
Py_DECREF(tp);
@@ -105,10 +106,11 @@ static PyType_Slot _abc_data_type_spec_slots[] = {
};
static PyType_Spec _abc_data_type_spec = {
- .name = "_abc._abc_data",
- .basicsize = sizeof(_abc_data),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
- .slots = _abc_data_type_spec_slots,
+ "_abc._abc_data",
+ sizeof(_abc_data),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ _abc_data_type_spec_slots,
};
static _abc_data *
@@ -130,10 +132,12 @@ _get_impl(PyObject *module, PyObject *self)
static int
_in_weak_set(PyObject *set, PyObject *obj)
{
+ PyObject *ref;
+ int res;
if (set == NULL || PySet_GET_SIZE(set) == 0) {
return 0;
}
- PyObject *ref = PyWeakref_NewRef(obj, NULL);
+ ref = PyWeakref_NewRef(obj, NULL);
if (ref == NULL) {
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_Clear();
@@ -141,7 +145,7 @@ _in_weak_set(PyObject *set, PyObject *obj)
}
return -1;
}
- int res = PySet_Contains(set, ref);
+ res = PySet_Contains(set, ref);
Py_DECREF(ref);
return res;
}
@@ -170,6 +174,10 @@ static PyMethodDef _destroy_def = {
static int
_add_to_weak_set(PyObject **pset, PyObject *obj)
{
+ PyObject *set;
+ PyObject *ref, *wr;
+ PyObject *destroy_cb;
+ int ret;
if (*pset == NULL) {
*pset = PySet_New(NULL);
if (*pset == NULL) {
@@ -177,9 +185,7 @@ _add_to_weak_set(PyObject **pset, PyObject *obj)
}
}
- PyObject *set = *pset;
- PyObject *ref, *wr;
- PyObject *destroy_cb;
+ set = *pset;
wr = PyWeakref_NewRef(set, NULL);
if (wr == NULL) {
return -1;
@@ -195,7 +201,7 @@ _add_to_weak_set(PyObject **pset, PyObject *obj)
Py_DECREF(wr);
return -1;
}
- int ret = PySet_Add(set, ref);
+ ret = PySet_Add(set, ref);
Py_DECREF(wr);
Py_DECREF(ref);
return ret;
@@ -279,14 +285,15 @@ _abc__get_dump(PyObject *module, PyObject *self)
/*[clinic end generated code: output=9d9569a8e2c1c443 input=2c5deb1bfe9e3c79]*/
{
_abc_data *impl = _get_impl(module, self);
+ PyObject *res;
if (impl == NULL) {
return NULL;
}
- PyObject *res = Py_BuildValue("NNNK",
- PySet_New(impl->_abc_registry),
- PySet_New(impl->_abc_cache),
- PySet_New(impl->_abc_negative_cache),
- impl->_abc_negative_cache_version);
+ res = Py_BuildValue("NNNK",
+ PySet_New(impl->_abc_registry),
+ PySet_New(impl->_abc_cache),
+ PySet_New(impl->_abc_negative_cache),
+ impl->_abc_negative_cache_version);
Py_DECREF(impl);
return res;
}
@@ -297,12 +304,12 @@ compute_abstract_methods(PyObject *self)
{
int ret = -1;
PyObject *abstracts = PyFrozenSet_New(NULL);
+ PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error.
+ Py_ssize_t pos;
if (abstracts == NULL) {
return -1;
}
- PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error.
-
/* Stage 1: direct abstract methods. */
ns = PyObject_GetAttr(self, &_Py_ID(__dict__));
if (!ns) {
@@ -316,8 +323,11 @@ compute_abstract_methods(PyObject *self)
goto error;
}
assert(PyList_Check(items));
- for (Py_ssize_t pos = 0; pos < PyList_GET_SIZE(items); pos++) {
- PyObject *it = PySequence_Fast(
+ for (pos = 0; pos < PyList_GET_SIZE(items); pos++) {
+ PyObject *it;
+ PyObject *key, *value;
+ int is_abstract;
+ it = PySequence_Fast(
PyList_GET_ITEM(items, pos),
"items() returned non-iterable");
if (!it) {
@@ -331,12 +341,12 @@ compute_abstract_methods(PyObject *self)
}
// borrowed
- PyObject *key = PySequence_Fast_GET_ITEM(it, 0);
- PyObject *value = PySequence_Fast_GET_ITEM(it, 1);
+ key = PySequence_Fast_GET_ITEM(it, 0);
+ value = PySequence_Fast_GET_ITEM(it, 1);
// items or it may be cleared while accessing __abstractmethod__
// So we need to keep strong reference for key
Py_INCREF(key);
- int is_abstract = _PyObject_IsAbstract(value);
+ is_abstract = _PyObject_IsAbstract(value);
if (is_abstract < 0 ||
(is_abstract && PySet_Add(abstracts, key) < 0)) {
Py_DECREF(it);
@@ -357,10 +367,12 @@ compute_abstract_methods(PyObject *self)
goto error;
}
- for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(bases); pos++) {
- PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed
+ for (pos = 0; pos < PyTuple_GET_SIZE(bases); pos++) {
+ PyObject *item;
PyObject *base_abstracts, *iter;
+ PyObject *key, *value;
+ item = PyTuple_GET_ITEM(bases, pos); // borrowed
if (_PyObject_LookupAttr(item, &_Py_ID(__abstractmethods__),
&base_abstracts) < 0) {
goto error;
@@ -373,8 +385,8 @@ compute_abstract_methods(PyObject *self)
goto error;
}
Py_DECREF(base_abstracts);
- PyObject *key, *value;
while ((key = PyIter_Next(iter))) {
+ int is_abstract;
if (_PyObject_LookupAttr(self, key, &value) < 0) {
Py_DECREF(key);
Py_DECREF(iter);
@@ -385,7 +397,7 @@ compute_abstract_methods(PyObject *self)
continue;
}
- int is_abstract = _PyObject_IsAbstract(value);
+ is_abstract = _PyObject_IsAbstract(value);
Py_DECREF(value);
if (is_abstract < 0 ||
(is_abstract && PySet_Add(abstracts, key) < 0))
@@ -482,6 +494,8 @@ _abc__abc_init(PyObject *module, PyObject *self)
static void
set_collection_flag_recursive(PyTypeObject *child, unsigned long flag)
{
+ PyObject *grandchildren;
+ Py_ssize_t i;
assert(flag == Py_TPFLAGS_MAPPING || flag == Py_TPFLAGS_SEQUENCE);
if (PyType_HasFeature(child, Py_TPFLAGS_IMMUTABLETYPE) ||
(child->tp_flags & COLLECTION_FLAGS) == flag)
@@ -492,12 +506,12 @@ set_collection_flag_recursive(PyTypeObject *child, unsigned long flag)
child->tp_flags &= ~COLLECTION_FLAGS;
child->tp_flags |= flag;
- PyObject *grandchildren = _PyType_GetSubclasses(child);
+ grandchildren = _PyType_GetSubclasses(child);
if (grandchildren == NULL) {
return;
}
- for (Py_ssize_t i = 0; i < PyList_GET_SIZE(grandchildren); i++) {
+ for (i = 0; i < PyList_GET_SIZE(grandchildren); i++) {
PyObject *grandchild = PyList_GET_ITEM(grandchildren, i);
set_collection_flag_recursive((PyTypeObject *)grandchild, flag);
}
@@ -518,11 +532,13 @@ static PyObject *
_abc__abc_register_impl(PyObject *module, PyObject *self, PyObject *subclass)
/*[clinic end generated code: output=7851e7668c963524 input=ca589f8c3080e67f]*/
{
+ int result;
+ _abc_data *impl;
if (!PyType_Check(subclass)) {
PyErr_SetString(PyExc_TypeError, "Can only register classes");
return NULL;
}
- int result = PyObject_IsSubclass(subclass, self);
+ result = PyObject_IsSubclass(subclass, self);
if (result > 0) {
Py_INCREF(subclass);
return subclass; /* Already a subclass. */
@@ -541,7 +557,7 @@ _abc__abc_register_impl(PyObject *module, PyObject *self, PyObject *subclass)
if (result < 0) {
return NULL;
}
- _abc_data *impl = _get_impl(module, self);
+ impl = _get_impl(module, self);
if (impl == NULL) {
return NULL;
}
@@ -583,6 +599,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
{
PyObject *subtype, *result = NULL, *subclass = NULL;
_abc_data *impl = _get_impl(module, self);
+ int incache;
if (impl == NULL) {
return NULL;
}
@@ -593,7 +610,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
return NULL;
}
/* Inline the cache checking. */
- int incache = _in_weak_set(impl->_abc_cache, subclass);
+ incache = _in_weak_set(impl->_abc_cache, subclass);
if (incache < 0) {
goto end;
}
@@ -670,16 +687,18 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
PyObject *subclass)
/*[clinic end generated code: output=b56c9e4a530e3894 input=1d947243409d10b8]*/
{
+ PyObject *ok, *subclasses = NULL, *result = NULL;
+ _abcmodule_state *state = NULL;
+ Py_ssize_t pos;
+ int incache;
+ _abc_data *impl;
+ PyObject *mro;
if (!PyType_Check(subclass)) {
PyErr_SetString(PyExc_TypeError, "issubclass() arg 1 must be a class");
return NULL;
}
- PyObject *ok, *subclasses = NULL, *result = NULL;
- _abcmodule_state *state = NULL;
- Py_ssize_t pos;
- int incache;
- _abc_data *impl = _get_impl(module, self);
+ impl = _get_impl(module, self);
if (impl == NULL) {
return NULL;
}
@@ -747,7 +766,7 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
Py_DECREF(ok);
/* 4. Check if it's a direct subclass. */
- PyObject *mro = ((PyTypeObject *)subclass)->tp_mro;
+ mro = ((PyTypeObject *)subclass)->tp_mro;
assert(PyTuple_Check(mro));
for (pos = 0; pos < PyTuple_GET_SIZE(mro); pos++) {
PyObject *mro_item = PyTuple_GET_ITEM(mro, pos);
@@ -777,9 +796,11 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
goto end;
}
for (pos = 0; pos < PyList_GET_SIZE(subclasses); pos++) {
- PyObject *scls = PyList_GET_ITEM(subclasses, pos);
+ PyObject *scls;
+ int r;
+ scls = PyList_GET_ITEM(subclasses, pos);
Py_INCREF(scls);
- int r = PyObject_IsSubclass(subclass, scls);
+ r = PyObject_IsSubclass(subclass, scls);
Py_DECREF(scls);
if (r > 0) {
if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) {
@@ -811,8 +832,16 @@ static int
subclasscheck_check_registry(_abc_data *impl, PyObject *subclass,
PyObject **result)
{
+ int ret;
+ Py_ssize_t registry_size;
+ PyObject **copy;
+ PyObject *key;
+ Py_ssize_t pos = 0;
+ Py_hash_t hash;
+ Py_ssize_t i = 0;
+
// Fast path: check subclass is in weakref directly.
- int ret = _in_weak_set(impl->_abc_registry, subclass);
+ ret = _in_weak_set(impl->_abc_registry, subclass);
if (ret < 0) {
*result = NULL;
return -1;
@@ -825,21 +854,17 @@ subclasscheck_check_registry(_abc_data *impl, PyObject *subclass,
if (impl->_abc_registry == NULL) {
return 0;
}
- Py_ssize_t registry_size = PySet_Size(impl->_abc_registry);
+ registry_size = PySet_Size(impl->_abc_registry);
if (registry_size == 0) {
return 0;
}
// Weakref callback may remove entry from set.
// So we take snapshot of registry first.
- PyObject **copy = PyMem_Malloc(sizeof(PyObject*) * registry_size);
+ copy = PyMem_Malloc(sizeof(PyObject*) * registry_size);
if (copy == NULL) {
PyErr_NoMemory();
return -1;
}
- PyObject *key;
- Py_ssize_t pos = 0;
- Py_hash_t hash;
- Py_ssize_t i = 0;
while (_PySet_NextEntry(impl->_abc_registry, &pos, &key, &hash)) {
Py_INCREF(key);
@@ -848,7 +873,9 @@ subclasscheck_check_registry(_abc_data *impl, PyObject *subclass,
assert(i == registry_size);
for (i = 0; i < registry_size; i++) {
- PyObject *rkey = PyWeakref_GetObject(copy[i]);
+ PyObject *rkey;
+ int r;
+ rkey = PyWeakref_GetObject(copy[i]);
if (rkey == NULL) {
// Someone inject non-weakref type in the registry.
ret = -1;
@@ -858,7 +885,7 @@ subclasscheck_check_registry(_abc_data *impl, PyObject *subclass,
continue;
}
Py_INCREF(rkey);
- int r = PyObject_IsSubclass(subclass, rkey);
+ r = PyObject_IsSubclass(subclass, rkey);
Py_DECREF(rkey);
if (r < 0) {
ret = -1;
@@ -954,14 +981,14 @@ static PyModuleDef_Slot _abcmodule_slots[] = {
static struct PyModuleDef _abcmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_abc",
- .m_doc = _abc__doc__,
- .m_size = sizeof(_abcmodule_state),
- .m_methods = _abcmodule_methods,
- .m_slots = _abcmodule_slots,
- .m_traverse = _abcmodule_traverse,
- .m_clear = _abcmodule_clear,
- .m_free = _abcmodule_free,
+ "_abc",
+ _abc__doc__,
+ sizeof(_abcmodule_state),
+ _abcmodule_methods,
+ _abcmodule_slots,
+ _abcmodule_traverse,
+ _abcmodule_clear,
+ _abcmodule_free,
};
PyMODINIT_FUNC
diff --git a/Modules/_bisectmodule.c b/Modules/_bisectmodule.c
index 0caa92b..1bfd7d3 100644
--- a/Modules/_bisectmodule.c
+++ b/Modules/_bisectmodule.c
@@ -326,13 +326,14 @@ static PyModuleDef_Slot bisect_slots[] = {
static struct PyModuleDef _bisectmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_bisect",
- .m_size = sizeof(bisect_state),
- .m_doc = module_doc,
- .m_methods = bisect_methods,
- .m_slots = bisect_slots,
- .m_clear = bisect_clear,
- .m_free = bisect_free,
+ "_bisect",
+ module_doc,
+ sizeof(bisect_state),
+ bisect_methods,
+ bisect_slots,
+ NULL,
+ bisect_clear,
+ bisect_free,
};
PyMODINIT_FUNC
diff --git a/Modules/_blake2/blake2b_impl.c b/Modules/_blake2/blake2b_impl.c
index c2cac98..c9c5d88 100644
--- a/Modules/_blake2/blake2b_impl.c
+++ b/Modules/_blake2/blake2b_impl.c
@@ -91,7 +91,7 @@ static PyObject *
py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
int fanout, int depth, unsigned long leaf_size,
- unsigned long long node_offset, int node_depth,
+ unsigned PY_LONG_LONG node_offset, int node_depth,
int inner_size, int last_node, int usedforsecurity)
/*[clinic end generated code: output=32bfd8f043c6896f input=b947312abff46977]*/
{
@@ -385,6 +385,7 @@ static void
py_blake2b_dealloc(PyObject *self)
{
BLAKE2bObject *obj = (BLAKE2bObject *)self;
+ PyTypeObject *type;
/* Try not to leave state in memory. */
secure_zero_memory(&obj->param, sizeof(obj->param));
@@ -394,7 +395,7 @@ py_blake2b_dealloc(PyObject *self)
obj->lock = NULL;
}
- PyTypeObject *type = Py_TYPE(self);
+ type = Py_TYPE(self);
PyObject_Free(self);
Py_DECREF(type);
}
@@ -409,8 +410,9 @@ static PyType_Slot blake2b_type_slots[] = {
};
PyType_Spec blake2b_type_spec = {
- .name = "_blake2.blake2b",
- .basicsize = sizeof(BLAKE2bObject),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
- .slots = blake2b_type_slots
+ "_blake2.blake2b",
+ sizeof(BLAKE2bObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
+ blake2b_type_slots
};
diff --git a/Modules/_blake2/blake2module.c b/Modules/_blake2/blake2module.c
index 93478f5..afd2e33 100644
--- a/Modules/_blake2/blake2module.c
+++ b/Modules/_blake2/blake2module.c
@@ -84,6 +84,7 @@ static int
blake2_exec(PyObject *m)
{
Blake2State* st = blake2_get_state(m);
+ PyObject *d;
st->blake2b_type = (PyTypeObject *)PyType_FromModuleAndSpec(
m, &blake2b_type_spec, NULL);
@@ -95,7 +96,7 @@ blake2_exec(PyObject *m)
return -1;
}
- PyObject *d = st->blake2b_type->tp_dict;
+ d = st->blake2b_type->tp_dict;
ADD_INT(d, "SALT_SIZE", BLAKE2B_SALTBYTES);
ADD_INT(d, "PERSON_SIZE", BLAKE2B_PERSONALBYTES);
ADD_INT(d, "MAX_KEY_SIZE", BLAKE2B_KEYBYTES);
@@ -142,13 +143,13 @@ static PyModuleDef_Slot _blake2_slots[] = {
static struct PyModuleDef blake2_module = {
PyModuleDef_HEAD_INIT,
"_blake2",
- .m_doc = blake2mod__doc__,
- .m_size = sizeof(Blake2State),
- .m_methods = blake2mod_functions,
- .m_slots = _blake2_slots,
- .m_traverse = _blake2_traverse,
- .m_clear = _blake2_clear,
- .m_free = _blake2_free,
+ blake2mod__doc__,
+ sizeof(Blake2State),
+ blake2mod_functions,
+ _blake2_slots,
+ _blake2_traverse,
+ _blake2_clear,
+ _blake2_free,
};
PyMODINIT_FUNC
diff --git a/Modules/_blake2/blake2s_impl.c b/Modules/_blake2/blake2s_impl.c
index 1c47328..6104437 100644
--- a/Modules/_blake2/blake2s_impl.c
+++ b/Modules/_blake2/blake2s_impl.c
@@ -91,7 +91,7 @@ static PyObject *
py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
int fanout, int depth, unsigned long leaf_size,
- unsigned long long node_offset, int node_depth,
+ unsigned PY_LONG_LONG node_offset, int node_depth,
int inner_size, int last_node, int usedforsecurity)
/*[clinic end generated code: output=556181f73905c686 input=4dda87723f23abb0]*/
{
@@ -160,7 +160,7 @@ py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
store32(&(self->param.leaf_length), leaf_size);
#ifdef HAVE_BLAKE2S
- if (node_offset > 0xFFFFFFFFFFFFULL) {
+ if (node_offset > PY_ULL(0xFFFFFFFFFFFF)) {
/* maximum 2**48 - 1 */
PyErr_SetString(PyExc_OverflowError, "node_offset is too large");
goto error;
@@ -385,6 +385,7 @@ static void
py_blake2s_dealloc(PyObject *self)
{
BLAKE2sObject *obj = (BLAKE2sObject *)self;
+ PyTypeObject *type;
/* Try not to leave state in memory. */
secure_zero_memory(&obj->param, sizeof(obj->param));
@@ -394,7 +395,7 @@ py_blake2s_dealloc(PyObject *self)
obj->lock = NULL;
}
- PyTypeObject *type = Py_TYPE(self);
+ type = Py_TYPE(self);
PyObject_Free(self);
Py_DECREF(type);
}
@@ -409,8 +410,9 @@ static PyType_Slot blake2s_type_slots[] = {
};
PyType_Spec blake2s_type_spec = {
- .name = "_blake2.blake2s",
- .basicsize = sizeof(BLAKE2sObject),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
- .slots = blake2s_type_slots
+ "_blake2.blake2s",
+ sizeof(BLAKE2sObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
+ blake2s_type_slots
};
diff --git a/Modules/_blake2/clinic/blake2b_impl.c.h b/Modules/_blake2/clinic/blake2b_impl.c.h
index 4e74e08..4b079b3 100644
--- a/Modules/_blake2/clinic/blake2b_impl.c.h
+++ b/Modules/_blake2/clinic/blake2b_impl.c.h
@@ -15,7 +15,7 @@ static PyObject *
py_blake2b_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
int fanout, int depth, unsigned long leaf_size,
- unsigned long long node_offset, int node_depth,
+ unsigned PY_LONG_LONG node_offset, int node_depth,
int inner_size, int last_node, int usedforsecurity);
static PyObject *
@@ -36,7 +36,7 @@ py_blake2b_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
int fanout = 1;
int depth = 1;
unsigned long leaf_size = 0;
- unsigned long long node_offset = 0;
+ unsigned PY_LONG_LONG node_offset = 0;
int node_depth = 0;
int inner_size = 0;
int last_node = 0;
diff --git a/Modules/_blake2/clinic/blake2s_impl.c.h b/Modules/_blake2/clinic/blake2s_impl.c.h
index 0f0d983..a25b6cb 100644
--- a/Modules/_blake2/clinic/blake2s_impl.c.h
+++ b/Modules/_blake2/clinic/blake2s_impl.c.h
@@ -15,7 +15,7 @@ static PyObject *
py_blake2s_new_impl(PyTypeObject *type, PyObject *data, int digest_size,
Py_buffer *key, Py_buffer *salt, Py_buffer *person,
int fanout, int depth, unsigned long leaf_size,
- unsigned long long node_offset, int node_depth,
+ unsigned PY_LONG_LONG node_offset, int node_depth,
int inner_size, int last_node, int usedforsecurity);
static PyObject *
@@ -36,7 +36,7 @@ py_blake2s_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
int fanout = 1;
int depth = 1;
unsigned long leaf_size = 0;
- unsigned long long node_offset = 0;
+ unsigned PY_LONG_LONG node_offset = 0;
int node_depth = 0;
int inner_size = 0;
int last_node = 0;
diff --git a/Modules/_blake2/impl/blake2b-ref.c b/Modules/_blake2/impl/blake2b-ref.c
index e58c436..b386ac5 100644
--- a/Modules/_blake2/impl/blake2b-ref.c
+++ b/Modules/_blake2/impl/blake2b-ref.c
@@ -20,10 +20,10 @@
static const uint64_t blake2b_IV[8] =
{
- 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
- 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
- 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
- 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
+ PY_ULL(0x6a09e667f3bcc908), PY_ULL(0xbb67ae8584caa73b),
+ PY_ULL(0x3c6ef372fe94f82b), PY_ULL(0xa54ff53a5f1d36f1),
+ PY_ULL(0x510e527fade682d1), PY_ULL(0x9b05688c2b3e6c1f),
+ PY_ULL(0x1f83d9abfb41bd6b), PY_ULL(0x5be0cd19137e2179)
};
static const uint8_t blake2b_sigma[12][16] =
@@ -45,13 +45,13 @@ static const uint8_t blake2b_sigma[12][16] =
static inline int blake2b_set_lastnode( blake2b_state *S )
{
- S->f[1] = ~0ULL;
+ S->f[1] = ~PY_ULL(0);
return 0;
}
static inline int blake2b_clear_lastnode( blake2b_state *S )
{
- S->f[1] = 0ULL;
+ S->f[1] = PY_ULL(0);
return 0;
}
@@ -60,7 +60,7 @@ static inline int blake2b_set_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_set_lastnode( S );
- S->f[0] = ~0ULL;
+ S->f[0] = ~PY_ULL(0);
return 0;
}
@@ -68,7 +68,7 @@ static inline int blake2b_clear_lastblock( blake2b_state *S )
{
if( S->last_node ) blake2b_clear_lastnode( S );
- S->f[0] = 0ULL;
+ S->f[0] = PY_ULL(0);
return 0;
}
@@ -138,9 +138,11 @@ static inline int blake2b_param_set_personal( blake2b_param *P, const uint8_t pe
static inline int blake2b_init0( blake2b_state *S )
{
+ int i;
+
memset( S, 0, sizeof( blake2b_state ) );
- for( int i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
+ for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
return 0;
}
@@ -161,11 +163,14 @@ extern "C" {
/* init xors IV with input parameter block */
int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
{
+ uint8_t *p;
+ size_t i;
+
blake2b_init0( S );
- uint8_t *p = ( uint8_t * )( P );
+ p = ( uint8_t * )( P );
/* IV XOR ParamBlock */
- for( size_t i = 0; i < 8; ++i )
+ for( i = 0; i < 8; ++i )
S->h[i] ^= load64( p + sizeof( S->h[i] ) * i );
S->outlen = P->digest_length;
diff --git a/Modules/_blake2/impl/blake2s-ref.c b/Modules/_blake2/impl/blake2s-ref.c
index ab86cc1..12b89d9 100644
--- a/Modules/_blake2/impl/blake2s-ref.c
+++ b/Modules/_blake2/impl/blake2s-ref.c
@@ -131,9 +131,11 @@ static inline int blake2s_param_set_personal( blake2s_param *P, const uint8_t pe
static inline int blake2s_init0( blake2s_state *S )
{
+ int i;
+
memset( S, 0, sizeof( blake2s_state ) );
- for( int i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
+ for( i = 0; i < 8; ++i ) S->h[i] = blake2s_IV[i];
return 0;
}
@@ -154,11 +156,14 @@ extern "C" {
/* init2 xors IV with input parameter block */
int blake2s_init_param( blake2s_state *S, const blake2s_param *P )
{
+ uint32_t *p;
+ size_t i;
+
blake2s_init0( S );
- uint32_t *p = ( uint32_t * )( P );
+ p = ( uint32_t * )( P );
/* IV XOR ParamBlock */
- for( size_t i = 0; i < 8; ++i )
+ for( i = 0; i < 8; ++i )
S->h[i] ^= load32( &p[i] );
S->outlen = P->digest_length;
@@ -224,11 +229,12 @@ static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCK
{
uint32_t m[16];
uint32_t v[16];
+ size_t i;
- for( size_t i = 0; i < 16; ++i )
+ for( i = 0; i < 16; ++i )
m[i] = load32( block + i * sizeof( m[i] ) );
- for( size_t i = 0; i < 8; ++i )
+ for( i = 0; i < 8; ++i )
v[i] = S->h[i];
v[ 8] = blake2s_IV[0];
@@ -272,7 +278,7 @@ static int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCK
ROUND( 8 );
ROUND( 9 );
- for( size_t i = 0; i < 8; ++i )
+ for( i = 0; i < 8; ++i )
S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
#undef G
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 900d906..1cba998 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -2138,6 +2138,7 @@ static PyObject*
defdict_or(PyObject* left, PyObject* right)
{
PyObject *self, *other;
+ PyObject *new;
if (PyObject_TypeCheck(left, &defdict_type)) {
self = left;
other = right;
@@ -2151,7 +2152,7 @@ defdict_or(PyObject* left, PyObject* right)
}
// Like copy(), this calls the object's class.
// Override __or__/__ror__ for subclasses with different constructors.
- PyObject *new = new_defdict((defdictobject*)self, left);
+ new = new_defdict((defdictobject*)self, left);
if (!new) {
return NULL;
}
@@ -2162,9 +2163,7 @@ defdict_or(PyObject* left, PyObject* right)
return new;
}
-static PyNumberMethods defdict_as_number = {
- .nb_or = defdict_or,
-};
+static PyNumberMethods defdict_as_number;
static int
defdict_traverse(PyObject *self, visitproc visit, void *arg)
@@ -2295,6 +2294,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
PyObject *mapping_setitem;
PyObject *dict_setitem;
PyObject *one = _PyLong_GetOne(); // borrowed reference
+ PyObject *zero;
it = PyObject_GetIter(iterable);
if (it == NULL)
@@ -2359,7 +2359,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
if (bound_get == NULL)
goto done;
- PyObject *zero = _PyLong_GetZero(); // borrowed reference
+ zero = _PyLong_GetZero(); // borrowed reference
while (1) {
key = PyIter_Next(it);
if (key == NULL)
@@ -2580,10 +2580,12 @@ collections_exec(PyObject *module) {
&dequereviter_type,
&tuplegetter_type
};
+ size_t i;
+ defdict_as_number.nb_or = defdict_or;
defdict_type.tp_base = &PyDict_Type;
- for (size_t i = 0; i < Py_ARRAY_LENGTH(typelist); i++) {
+ for (i = 0; i < Py_ARRAY_LENGTH(typelist); i++) {
if (PyModule_AddType(module, typelist[i]) < 0) {
return -1;
}
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 045b71a..3c16361 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -242,6 +242,7 @@ _set_int(const char *name, int *target, PyObject *src, int dflt)
static int
_set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
{
+ Py_ssize_t len;
if (src == NULL) {
*target = dflt;
}
@@ -254,7 +255,7 @@ _set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt
Py_TYPE(src)->tp_name);
return -1;
}
- Py_ssize_t len = PyUnicode_GetLength(src);
+ len = PyUnicode_GetLength(src);
if (len < 0) {
return -1;
}
@@ -274,6 +275,7 @@ _set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt
static int
_set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
{
+ Py_ssize_t len;
if (src == NULL) {
*target = dflt;
}
@@ -284,7 +286,7 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
Py_TYPE(src)->tp_name);
return -1;
}
- Py_ssize_t len = PyUnicode_GetLength(src);
+ len = PyUnicode_GetLength(src);
if (len < 0) {
return -1;
}
@@ -381,10 +383,11 @@ static _csvstate *
_csv_state_from_type(PyTypeObject *type, const char *name)
{
PyObject *module = PyType_GetModuleByDef(type, &_csvmodule);
+ _csvstate *module_state;
if (module == NULL) {
return NULL;
}
- _csvstate *module_state = PyModule_GetState(module);
+ module_state = PyModule_GetState(module);
if (module_state == NULL) {
PyErr_Format(PyExc_SystemError,
"%s: No _csv module state found", name);
@@ -398,6 +401,7 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
DialectObj *self;
PyObject *ret = NULL;
+ _csvstate *module_state;
PyObject *dialect = NULL;
PyObject *delimiter = NULL;
PyObject *doublequote = NULL;
@@ -421,7 +425,7 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
&strict))
return NULL;
- _csvstate *module_state = _csv_state_from_type(type, "dialect_new");
+ module_state = _csv_state_from_type(type, "dialect_new");
if (module_state == NULL) {
return NULL;
}
@@ -581,11 +585,12 @@ static PyType_Slot Dialect_Type_slots[] = {
};
PyType_Spec Dialect_Type_spec = {
- .name = "_csv.Dialect",
- .basicsize = sizeof(DialectObj),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = Dialect_Type_slots,
+ "_csv.Dialect",
+ sizeof(DialectObj),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_IMMUTABLETYPE),
+ Dialect_Type_slots
};
@@ -639,10 +644,12 @@ parse_save_field(ReaderObj *self)
static int
parse_grow_buff(ReaderObj *self)
{
+ Py_ssize_t field_size_new;
+ Py_UCS4 *field_new;
assert((size_t)self->field_size <= PY_SSIZE_T_MAX / sizeof(Py_UCS4));
- Py_ssize_t field_size_new = self->field_size ? 2 * self->field_size : 4096;
- Py_UCS4 *field_new = self->field;
+ field_size_new = self->field_size ? 2 * self->field_size : 4096;
+ field_new = self->field;
PyMem_Resize(field_new, Py_UCS4, field_size_new);
if (field_new == NULL) {
PyErr_NoMemory();
@@ -998,11 +1005,12 @@ static PyType_Slot Reader_Type_slots[] = {
};
PyType_Spec Reader_Type_spec = {
- .name = "_csv.reader",
- .basicsize = sizeof(ReaderObj),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
- .slots = Reader_Type_slots
+ "_csv.reader",
+ sizeof(ReaderObj),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
+ Reader_Type_slots
};
@@ -1435,11 +1443,12 @@ static PyType_Slot Writer_Type_slots[] = {
};
PyType_Spec Writer_Type_spec = {
- .name = "_csv.writer",
- .basicsize = sizeof(WriterObj),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
- .slots = Writer_Type_slots,
+ "_csv.writer",
+ sizeof(WriterObj),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
+ Writer_Type_slots
};
@@ -1616,9 +1625,11 @@ static PyType_Slot error_slots[] = {
};
PyType_Spec error_spec = {
- .name = "_csv.Error",
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- .slots = error_slots,
+ "_csv.Error",
+ 0,
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ error_slots
};
/*
@@ -1734,6 +1745,7 @@ static int
csv_exec(PyObject *module) {
const StyleDesc *style;
PyObject *temp;
+ PyObject *bases;
_csvstate *module_state = get_csv_state(module);
temp = PyType_FromModuleAndSpec(module, &Dialect_Type_spec, NULL);
@@ -1777,7 +1789,7 @@ csv_exec(PyObject *module) {
}
/* Add the CSV exception object to the module. */
- PyObject *bases = PyTuple_Pack(1, PyExc_Exception);
+ bases = PyTuple_Pack(1, PyExc_Exception);
if (bases == NULL) {
return -1;
}
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index df0ce72..dc29ee8 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -398,6 +398,9 @@ iso_week1_monday(int year)
static int
iso_to_ymd(const int iso_year, const int iso_week, const int iso_day,
int *year, int *month, int *day) {
+ int day_1;
+ int day_offset;
+
if (iso_week <= 0 || iso_week >= 53) {
int out_of_range = 1;
if (iso_week == 53) {
@@ -419,9 +422,9 @@ iso_to_ymd(const int iso_year, const int iso_week, const int iso_day,
}
// Convert (Y, W, D) to (Y, M, D) in-place
- int day_1 = iso_week1_monday(iso_year);
+ day_1 = iso_week1_monday(iso_year);
- int day_offset = (iso_week - 1)*7 + iso_day - 1;
+ day_offset = (iso_week - 1)*7 + iso_day - 1;
ord_to_ymd(day_1 + day_offset, year, month, day);
return 0;
@@ -721,7 +724,9 @@ is_digit(const char c) {
static const char *
parse_digits(const char *ptr, int *var, size_t num_digits)
{
- for (size_t i = 0; i < num_digits; ++i) {
+ size_t i;
+
+ for (i = 0; i < num_digits; ++i) {
unsigned int tmp = (unsigned int)(*(ptr++) - '0');
if (tmp > 9) {
return NULL;
@@ -747,12 +752,16 @@ parse_isoformat_date(const char *dtstr, const size_t len, int *year, int *month,
* -5, -6: Failure in iso_to_ymd
*/
const char *p = dtstr;
+ unsigned char uses_separator;
+ int iso_week;
+ int iso_day;
+ int rv;
p = parse_digits(p, year, 4);
if (NULL == p) {
return -1;
}
- const unsigned char uses_separator = (*p == '-');
+ uses_separator = (*p == '-');
if (uses_separator) {
++p;
}
@@ -760,8 +769,8 @@ parse_isoformat_date(const char *dtstr, const size_t len, int *year, int *month,
if(*p == 'W') {
// This is an isocalendar-style date string
p++;
- int iso_week = 0;
- int iso_day = 0;
+ iso_week = 0;
+ iso_day = 0;
p = parse_digits(p, &iso_week, 2);
if (NULL == p) {
@@ -782,7 +791,7 @@ parse_isoformat_date(const char *dtstr, const size_t len, int *year, int *month,
iso_day = 1;
}
- int rv = iso_to_ymd(*year, iso_week, iso_day, year, month, day);
+ rv = iso_to_ymd(*year, iso_week, iso_day, year, month, day);
if (rv) {
return -3 + rv;
} else {
@@ -809,21 +818,32 @@ static int
parse_hh_mm_ss_ff(const char *tstr, const char *tstr_end, int *hour,
int *minute, int *second, int *microsecond)
{
- *hour = *minute = *second = *microsecond = 0;
const char *p = tstr;
const char *p_end = tstr_end;
- int *vals[3] = {hour, minute, second};
+ int *vals[3];
// This is initialized to satisfy an erroneous compiler warning.
unsigned char has_separator = 1;
+ size_t i;
+ size_t len_remains;
+ size_t to_parse;
+ static int correction[] = {
+ 100000, 10000, 1000, 100, 10
+ };
+
+ *hour = *minute = *second = *microsecond = 0;
+ vals[0] = hour;
+ vals[1] = minute;
+ vals[2] = second;
// Parse [HH[:?MM[:?SS]]]
- for (size_t i = 0; i < 3; ++i) {
+ for (i = 0; i < 3; ++i) {
+ char c;
p = parse_digits(p, vals[i], 2);
if (NULL == p) {
return -3;
}
- char c = *(p++);
+ c = *(p++);
if (i == 0) {
has_separator = (c == ':');
}
@@ -844,8 +864,8 @@ parse_hh_mm_ss_ff(const char *tstr, const char *tstr_end, int *hour,
}
// Parse fractional components
- size_t len_remains = p_end - p;
- size_t to_parse = len_remains;
+ len_remains = p_end - p;
+ to_parse = len_remains;
if (len_remains >= 6) {
to_parse = 6;
}
@@ -855,10 +875,6 @@ parse_hh_mm_ss_ff(const char *tstr, const char *tstr_end, int *hour,
return -3;
}
- static int correction[] = {
- 100000, 10000, 1000, 100, 10
- };
-
if (to_parse < 6) {
*microsecond *= correction[to_parse-1];
}
@@ -889,14 +905,20 @@ parse_isoformat_time(const char *dtstr, size_t dtlen, int *hour, int *minute,
const char *p_end = dtstr + dtlen;
const char *tzinfo_pos = p;
+ int rv;
+ int tzsign;
+ int tzhour;
+ int tzminute;
+ int tzsecond;
+
do {
if (*tzinfo_pos == 'Z' || *tzinfo_pos == '+' || *tzinfo_pos == '-') {
break;
}
} while (++tzinfo_pos < p_end);
- int rv = parse_hh_mm_ss_ff(dtstr, tzinfo_pos, hour, minute, second,
- microsecond);
+ rv = parse_hh_mm_ss_ff(dtstr, tzinfo_pos, hour, minute, second,
+ microsecond);
if (rv < 0) {
return rv;
@@ -924,9 +946,11 @@ parse_isoformat_time(const char *dtstr, size_t dtlen, int *hour, int *minute,
}
}
- int tzsign = (*tzinfo_pos == '-') ? -1 : 1;
+ tzsign = (*tzinfo_pos == '-') ? -1 : 1;
tzinfo_pos++;
- int tzhour = 0, tzminute = 0, tzsecond = 0;
+ tzhour = 0;
+ tzminute = 0;
+ tzsecond = 0;
rv = parse_hh_mm_ss_ff(tzinfo_pos, p_end, &tzhour, &tzminute, &tzsecond,
tzmicrosecond);
@@ -1401,6 +1425,7 @@ static inline PyObject *
tzinfo_from_isoformat_results(int rv, int tzoffset, int tz_useconds)
{
PyObject *tzinfo;
+ PyObject *delta;
if (rv == 1) {
// Create a timezone from offset in seconds (0 returns UTC)
if (tzoffset == 0) {
@@ -1408,7 +1433,7 @@ tzinfo_from_isoformat_results(int rv, int tzoffset, int tz_useconds)
return PyDateTime_TimeZone_UTC;
}
- PyObject *delta = new_delta(0, tzoffset, tz_useconds, 1);
+ delta = new_delta(0, tzoffset, tz_useconds, 1);
if (delta == NULL) {
return NULL;
}
@@ -2629,13 +2654,15 @@ delta_bool(PyDateTime_Delta *self)
static PyObject *
delta_repr(PyDateTime_Delta *self)
{
+ const char *sep;
+ PyObject *repr;
PyObject *args = PyUnicode_FromString("");
if (args == NULL) {
return NULL;
}
- const char *sep = "";
+ sep = "";
if (GET_TD_DAYS(self) != 0) {
Py_SETREF(args, PyUnicode_FromFormat("days=%d", GET_TD_DAYS(self)));
@@ -2669,8 +2696,8 @@ delta_repr(PyDateTime_Delta *self)
}
}
- PyObject *repr = PyUnicode_FromFormat("%s(%S)", Py_TYPE(self)->tp_name,
- args);
+ repr = PyUnicode_FromFormat("%s(%S)", Py_TYPE(self)->tp_name,
+ args);
Py_DECREF(args);
return repr;
}
@@ -3057,6 +3084,11 @@ date_fromordinal(PyObject *cls, PyObject *args)
static PyObject *
date_fromisoformat(PyObject *cls, PyObject *dtstr)
{
+ Py_ssize_t len;
+ const char *dt_ptr;
+ int year, month, day;
+ int rv;
+
assert(dtstr != NULL);
if (!PyUnicode_Check(dtstr)) {
@@ -3065,16 +3097,14 @@ date_fromisoformat(PyObject *cls, PyObject *dtstr)
return NULL;
}
- Py_ssize_t len;
-
- const char *dt_ptr = PyUnicode_AsUTF8AndSize(dtstr, &len);
+ dt_ptr = PyUnicode_AsUTF8AndSize(dtstr, &len);
if (dt_ptr == NULL) {
goto invalid_string_error;
}
- int year = 0, month = 0, day = 0;
-
- int rv;
+ year = 0;
+ month = 0;
+ day = 0;
if (len == 7 || len == 8 || len == 10) {
rv = parse_isoformat_date(dt_ptr, len, &year, &month, &day);
}
@@ -3102,6 +3132,8 @@ date_fromisocalendar(PyObject *cls, PyObject *args, PyObject *kw)
};
int year, week, day;
+ int month;
+ int rv;
if (PyArg_ParseTupleAndKeywords(args, kw, "iii:fromisocalendar",
keywords,
&year, &week, &day) == 0) {
@@ -3119,8 +3151,7 @@ date_fromisocalendar(PyObject *cls, PyObject *args, PyObject *kw)
return NULL;
}
- int month;
- int rv = iso_to_ymd(year, week, day, &year, &month, &day);
+ rv = iso_to_ymd(year, week, day, &year, &month, &day);
if (rv == -2) {
@@ -3312,14 +3343,16 @@ static PyObject *
iso_calendar_date_repr(PyDateTime_IsoCalendarDate *self)
{
PyObject* year = PyTuple_GetItem((PyObject *)self, 0);
+ PyObject* week;
+ PyObject* weekday;
if (year == NULL) {
return NULL;
}
- PyObject* week = PyTuple_GetItem((PyObject *)self, 1);
+ week = PyTuple_GetItem((PyObject *)self, 1);
if (week == NULL) {
return NULL;
}
- PyObject* weekday = PyTuple_GetItem((PyObject *)self, 2);
+ weekday = PyTuple_GetItem((PyObject *)self, 2);
if (weekday == NULL) {
return NULL;
}
@@ -3390,15 +3423,44 @@ static PyMethodDef iso_calendar_date_methods[] = {
static PyTypeObject PyDateTime_IsoCalendarDateType = {
PyVarObject_HEAD_INIT(NULL, 0)
- .tp_name = "datetime.IsoCalendarDate",
- .tp_basicsize = sizeof(PyDateTime_IsoCalendarDate),
- .tp_repr = (reprfunc) iso_calendar_date_repr,
- .tp_flags = Py_TPFLAGS_DEFAULT,
- .tp_doc = iso_calendar_date__doc__,
- .tp_methods = iso_calendar_date_methods,
- .tp_getset = iso_calendar_date_getset,
- // .tp_base = &PyTuple_Type, // filled in PyInit__datetime
- .tp_new = iso_calendar_date_new,
+ "datetime.IsoCalendarDate",
+ sizeof(PyDateTime_IsoCalendarDate),
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ (reprfunc) iso_calendar_date_repr,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ PyObject_GenericGetAttr,
+ 0,
+ 0,
+ Py_TPFLAGS_DEFAULT,
+ iso_calendar_date__doc__,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ iso_calendar_date_methods,
+ 0,
+ iso_calendar_date_getset,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ iso_calendar_date_new,
+ 0,
};
/*[clinic input]
@@ -3431,6 +3493,7 @@ iso_calendar_date_new_impl(PyTypeObject *type, int year, int week,
static PyObject *
date_isocalendar(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored))
{
+ PyObject* v;
int year = GET_YEAR(self);
int week1_monday = iso_week1_monday(year);
int today = ymd_to_ord(year, GET_MONTH(self), GET_DAY(self));
@@ -3448,7 +3511,7 @@ date_isocalendar(PyDateTime_Date *self, PyObject *Py_UNUSED(ignored))
week = 0;
}
- PyObject* v = iso_calendar_date_new_impl(&PyDateTime_IsoCalendarDateType,
+ v = iso_calendar_date_new_impl(&PyDateTime_IsoCalendarDateType,
year, week + 1, day + 1);
if (v == NULL) {
return NULL;
@@ -4626,6 +4689,14 @@ time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
static PyObject *
time_fromisoformat(PyObject *cls, PyObject *tstr) {
+ Py_ssize_t len;
+ const char *p;
+ int hour, minute, second, microsecond;
+ int tzoffset, tzimicrosecond;
+ int rv;
+ PyObject *tzinfo;
+ PyObject *t;
+
assert(tstr != NULL);
if (!PyUnicode_Check(tstr)) {
@@ -4633,8 +4704,7 @@ time_fromisoformat(PyObject *cls, PyObject *tstr) {
return NULL;
}
- Py_ssize_t len;
- const char *p = PyUnicode_AsUTF8AndSize(tstr, &len);
+ p = PyUnicode_AsUTF8AndSize(tstr, &len);
if (p == NULL) {
goto invalid_string_error;
@@ -4648,24 +4718,23 @@ time_fromisoformat(PyObject *cls, PyObject *tstr) {
len -= 1;
}
- int hour = 0, minute = 0, second = 0, microsecond = 0;
- int tzoffset = 0, tzimicrosecond = 0;
- int rv = parse_isoformat_time(p, len,
- &hour, &minute, &second, &microsecond,
- &tzoffset, &tzimicrosecond);
+ hour = minute = second = microsecond = 0;
+ tzoffset = tzimicrosecond = 0;
+ rv = parse_isoformat_time(p, len,
+ &hour, &minute, &second, &microsecond,
+ &tzoffset, &tzimicrosecond);
if (rv < 0) {
goto invalid_string_error;
}
- PyObject *tzinfo = tzinfo_from_isoformat_results(rv, tzoffset,
- tzimicrosecond);
+ tzinfo = tzinfo_from_isoformat_results(rv, tzoffset,
+ tzimicrosecond);
if (tzinfo == NULL) {
return NULL;
}
- PyObject *t;
if ( (PyTypeObject *)cls == &PyDateTime_TimeType ) {
t = new_time(hour, minute, second, microsecond, tzinfo, 0);
} else {
@@ -4981,15 +5050,15 @@ typedef int (*TM_FUNC)(time_t timer, struct tm*);
/* As of version 2015f max fold in IANA database is
* 23 hours at 1969-09-30 13:00:00 in Kwajalein. */
-static long long max_fold_seconds = 24 * 3600;
+static PY_LONG_LONG max_fold_seconds = 24 * 3600;
/* NB: date(1970,1,1).toordinal() == 719163 */
-static long long epoch = 719163LL * 24 * 60 * 60;
+static PY_LONG_LONG epoch = PY_LL(719163) * 24 * 60 * 60;
-static long long
+static PY_LONG_LONG
utc_to_seconds(int year, int month, int day,
int hour, int minute, int second)
{
- long long ordinal;
+ PY_LONG_LONG ordinal;
/* ymd_to_ord() doesn't support year <= 0 */
if (year < MINYEAR || year > MAXYEAR) {
@@ -5001,8 +5070,8 @@ utc_to_seconds(int year, int month, int day,
return ((ordinal * 24 + hour) * 60 + minute) * 60 + second;
}
-static long long
-local(long long u)
+static PY_LONG_LONG
+local(PY_LONG_LONG u)
{
struct tm local_time;
time_t t;
@@ -5067,7 +5136,7 @@ datetime_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, int us,
&& (timet - max_fold_seconds > 0)
#endif
) {
- long long probe_seconds, result_seconds, transition;
+ PY_LONG_LONG probe_seconds, result_seconds, transition;
result_seconds = utc_to_seconds(year, month, day,
hour, minute, second);
@@ -5272,6 +5341,12 @@ datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
static PyObject *
_sanitize_isoformat_str(PyObject *dtstr)
{
+ static const size_t potential_separators[3] = {7, 8, 10};
+ const void *unicode_data;
+ unsigned int kind;
+ size_t surrogate_separator;
+ size_t idx;
+ PyObject *str_out;
Py_ssize_t len = PyUnicode_GetLength(dtstr);
if (len < 7) { // All valid ISO 8601 strings are at least 7 characters long
return NULL;
@@ -5283,17 +5358,16 @@ _sanitize_isoformat_str(PyObject *dtstr)
// replaces any surrogate character separators with `T`.
//
// The result of this, if not NULL, returns a new reference
- const void* const unicode_data = PyUnicode_DATA(dtstr);
- const unsigned int kind = PyUnicode_KIND(dtstr);
+ unicode_data = PyUnicode_DATA(dtstr);
+ kind = PyUnicode_KIND(dtstr);
// Depending on the format of the string, the separator can only ever be
// in positions 7, 8 or 10. We'll check each of these for a surrogate and
// if we find one, replace it with `T`. If there is more than one surrogate,
// we don't have to bother sanitizing it, because the function will later
// fail when we try to encode the string as ASCII.
- static const size_t potential_separators[3] = {7, 8, 10};
- size_t surrogate_separator = 0;
- for(size_t idx = 0;
+ surrogate_separator = 0;
+ for (idx = 0;
idx < sizeof(potential_separators) / sizeof(*potential_separators);
++idx) {
size_t pos = potential_separators[idx];
@@ -5312,7 +5386,7 @@ _sanitize_isoformat_str(PyObject *dtstr)
return dtstr;
}
- PyObject *str_out = _PyUnicode_Copy(dtstr);
+ str_out = _PyUnicode_Copy(dtstr);
if (str_out == NULL) {
return NULL;
}
@@ -5428,6 +5502,18 @@ _find_isoformat_datetime_separator(const char *dtstr, Py_ssize_t len) {
static PyObject *
datetime_fromisoformat(PyObject *cls, PyObject *dtstr)
{
+ PyObject *dtstr_clean;
+ Py_ssize_t len;
+ const char *dt_ptr;
+ Py_ssize_t separator_location;
+ const char *p;
+ int year, month, day;
+ int hour, minute, second, microsecond;
+ int tzoffset, tzusec;
+ int rv;
+ PyObject *tzinfo;
+ PyObject *dt;
+
assert(dtstr != NULL);
if (!PyUnicode_Check(dtstr)) {
@@ -5441,13 +5527,12 @@ datetime_fromisoformat(PyObject *cls, PyObject *dtstr)
// we don't have to sanitize it anything because that can only happen when
// the separator is either '-' or a number. This should mostly be a noop
// but it makes the reference counting easier if we still sanitize.
- PyObject *dtstr_clean = _sanitize_isoformat_str(dtstr);
+ dtstr_clean = _sanitize_isoformat_str(dtstr);
if (dtstr_clean == NULL) {
goto invalid_string_error;
}
- Py_ssize_t len;
- const char *dt_ptr = PyUnicode_AsUTF8AndSize(dtstr_clean, &len);
+ dt_ptr = PyUnicode_AsUTF8AndSize(dtstr_clean, &len);
if (dt_ptr == NULL) {
if (PyErr_ExceptionMatches(PyExc_UnicodeEncodeError)) {
@@ -5459,18 +5544,18 @@ datetime_fromisoformat(PyObject *cls, PyObject *dtstr)
}
}
- const Py_ssize_t separator_location = _find_isoformat_datetime_separator(
+ separator_location = _find_isoformat_datetime_separator(
dt_ptr, len);
- const char *p = dt_ptr;
+ p = dt_ptr;
- int year = 0, month = 0, day = 0;
- int hour = 0, minute = 0, second = 0, microsecond = 0;
- int tzoffset = 0, tzusec = 0;
+ year = 0; month = 0; day = 0;
+ hour = 0; minute = 0; second = 0; microsecond = 0;
+ tzoffset = 0; tzusec = 0;
// date runs up to separator_location
- int rv = parse_isoformat_date(p, separator_location, &year, &month, &day);
+ rv = parse_isoformat_date(p, separator_location, &year, &month, &day);
if (!rv && len > separator_location) {
// In UTF-8, the length of multi-byte characters is encoded in the MSB
@@ -5500,13 +5585,13 @@ datetime_fromisoformat(PyObject *cls, PyObject *dtstr)
goto invalid_string_error;
}
- PyObject *tzinfo = tzinfo_from_isoformat_results(rv, tzoffset, tzusec);
+ tzinfo = tzinfo_from_isoformat_results(rv, tzoffset, tzusec);
if (tzinfo == NULL) {
goto error;
}
- PyObject *dt = new_datetime_subclass_ex(year, month, day, hour, minute,
- second, microsecond, tzinfo, cls);
+ dt = new_datetime_subclass_ex(year, month, day, hour, minute,
+ second, microsecond, tzinfo, cls);
Py_DECREF(tzinfo);
Py_DECREF(dtstr_clean);
@@ -6172,14 +6257,14 @@ local_timezone(PyDateTime_DateTime *utc_time)
return local_timezone_from_timestamp(timestamp);
}
-static long long
+static PY_LONG_LONG
local_to_seconds(int year, int month, int day,
int hour, int minute, int second, int fold);
static PyObject *
local_timezone_from_local(PyDateTime_DateTime *local_dt)
{
- long long seconds;
+ PY_LONG_LONG seconds;
time_t timestamp;
seconds = local_to_seconds(GET_YEAR(local_dt),
GET_MONTH(local_dt),
@@ -6324,11 +6409,11 @@ datetime_timetuple(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored))
dstflag);
}
-static long long
+static PY_LONG_LONG
local_to_seconds(int year, int month, int day,
int hour, int minute, int second, int fold)
{
- long long t, a, b, u1, u2, t1, t2, lt;
+ PY_LONG_LONG t, a, b, u1, u2, t1, t2, lt;
t = utc_to_seconds(year, month, day, hour, minute, second);
/* Our goal is to solve t = local(u) for u. */
lt = local(t);
@@ -6372,7 +6457,7 @@ local_to_seconds(int year, int month, int day,
}
/* date(1970,1,1).toordinal() == 719163 */
-#define EPOCH_SECONDS (719163LL * 24 * 60 * 60)
+#define EPOCH_SECONDS (PY_LL(719163) * 24 * 60 * 60)
static PyObject *
datetime_timestamp(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored))
@@ -6388,7 +6473,7 @@ datetime_timestamp(PyDateTime_DateTime *self, PyObject *Py_UNUSED(ignored))
Py_DECREF(delta);
}
else {
- long long seconds;
+ PY_LONG_LONG seconds;
seconds = local_to_seconds(GET_YEAR(self),
GET_MONTH(self),
GET_DAY(self),
@@ -6719,13 +6804,6 @@ datetime_destructor(PyObject *op)
static int
_datetime_exec(PyObject *module)
{
- // `&...` is not a constant expression according to a strict reading
- // of C standards. Fill tp_base at run-time rather than statically.
- // See https://bugs.python.org/issue40777
- PyDateTime_IsoCalendarDateType.tp_base = &PyTuple_Type;
- PyDateTime_TimeZoneType.tp_base = &PyDateTime_TZInfoType;
- PyDateTime_DateTimeType.tp_base = &PyDateTime_DateType;
-
PyTypeObject *types[] = {
&PyDateTime_DateType,
&PyDateTime_DateTimeType,
@@ -6734,8 +6812,20 @@ _datetime_exec(PyObject *module)
&PyDateTime_TZInfoType,
&PyDateTime_TimeZoneType,
};
+ size_t i;
+ PyObject *d;
+ PyObject *delta;
+ PyObject *x;
+ PyDateTime_CAPI *capi;
+
+ // `&...` is not a constant expression according to a strict reading
+ // of C standards. Fill tp_base at run-time rather than statically.
+ // See https://bugs.python.org/issue40777
+ PyDateTime_IsoCalendarDateType.tp_base = &PyTuple_Type;
+ PyDateTime_TimeZoneType.tp_base = &PyDateTime_TZInfoType;
+ PyDateTime_DateTimeType.tp_base = &PyDateTime_DateType;
- for (size_t i = 0; i < Py_ARRAY_LENGTH(types); i++) {
+ for (i = 0; i < Py_ARRAY_LENGTH(types); i++) {
if (PyModule_AddType(module, types[i]) < 0) {
return -1;
}
@@ -6759,7 +6849,7 @@ _datetime_exec(PyObject *module)
} while(0)
/* timedelta values */
- PyObject *d = PyDateTime_DeltaType.tp_dict;
+ d = PyDateTime_DeltaType.tp_dict;
DATETIME_ADD_MACRO(d, "resolution", new_delta(0, 0, 1, 0));
DATETIME_ADD_MACRO(d, "min", new_delta(-MAX_DELTA_DAYS, 0, 0, 0));
DATETIME_ADD_MACRO(d, "max",
@@ -6787,12 +6877,12 @@ _datetime_exec(PyObject *module)
/* timezone values */
d = PyDateTime_TimeZoneType.tp_dict;
- PyObject *delta = new_delta(0, 0, 0, 0);
+ delta = new_delta(0, 0, 0, 0);
if (delta == NULL) {
return -1;
}
- PyObject *x = create_timezone(delta, NULL);
+ x = create_timezone(delta, NULL);
Py_DECREF(delta);
if (x == NULL) {
return -1;
@@ -6840,7 +6930,7 @@ _datetime_exec(PyObject *module)
return -1;
}
- PyDateTime_CAPI *capi = get_datetime_capi();
+ capi = get_datetime_capi();
if (capi == NULL) {
return -1;
}
@@ -6925,10 +7015,11 @@ _datetime_exec(PyObject *module)
static struct PyModuleDef datetimemodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_datetime",
- .m_doc = "Fast implementation of the datetime type.",
- .m_size = -1,
- .m_methods = module_methods,
+ "_datetime",
+ "Fast implementation of the datetime type.",
+ -1,
+ module_methods,
+ NULL
};
PyMODINIT_FUNC
diff --git a/Modules/_functoolsmodule.c b/Modules/_functoolsmodule.c
index 3abb7fd..072c07f 100644
--- a/Modules/_functoolsmodule.c
+++ b/Modules/_functoolsmodule.c
@@ -192,8 +192,9 @@ partial_vectorcall_fallback(PyThreadState *tstate, partialobject *pto,
PyObject *const *args, size_t nargsf,
PyObject *kwnames)
{
+ Py_ssize_t nargs;
pto->vectorcall = NULL;
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ nargs = PyVectorcall_NARGS(nargsf);
return _PyObject_MakeTpCall(tstate, (PyObject *)pto,
args, nargs, kwnames);
}
@@ -202,21 +203,33 @@ static PyObject *
partial_vectorcall(partialobject *pto, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
- PyThreadState *tstate = _PyThreadState_GET();
+ PyThreadState *tstate;
+ Py_ssize_t nargs;
+ Py_ssize_t nargs_total;
+ PyObject **pto_args;
+ Py_ssize_t pto_nargs;
+ PyObject **newargs;
+ PyObject *tmp;
+ PyObject *ret;
+ Py_ssize_t newnargs_total;
+ PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
+ PyObject **stack;
+
+ tstate = _PyThreadState_GET();
/* pto->kw is mutable, so need to check every time */
if (PyDict_GET_SIZE(pto->kw)) {
return partial_vectorcall_fallback(tstate, pto, args, nargsf, kwnames);
}
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
- Py_ssize_t nargs_total = nargs;
+ nargs = PyVectorcall_NARGS(nargsf);
+ nargs_total = nargs;
if (kwnames != NULL) {
nargs_total += PyTuple_GET_SIZE(kwnames);
}
- PyObject **pto_args = _PyTuple_ITEMS(pto->args);
- Py_ssize_t pto_nargs = PyTuple_GET_SIZE(pto->args);
+ pto_args = _PyTuple_ITEMS(pto->args);
+ pto_nargs = PyTuple_GET_SIZE(pto->args);
/* Fast path if we're called without arguments */
if (nargs_total == 0) {
@@ -227,20 +240,16 @@ partial_vectorcall(partialobject *pto, PyObject *const *args,
/* Fast path using PY_VECTORCALL_ARGUMENTS_OFFSET to prepend a single
* positional argument */
if (pto_nargs == 1 && (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET)) {
- PyObject **newargs = (PyObject **)args - 1;
- PyObject *tmp = newargs[0];
+ newargs = (PyObject **)args - 1;
+ tmp = newargs[0];
newargs[0] = pto_args[0];
- PyObject *ret = _PyObject_VectorcallTstate(tstate, pto->fn,
+ ret = _PyObject_VectorcallTstate(tstate, pto->fn,
newargs, nargs + 1, kwnames);
newargs[0] = tmp;
return ret;
}
- Py_ssize_t newnargs_total = pto_nargs + nargs_total;
-
- PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
- PyObject *ret;
- PyObject **stack;
+ newnargs_total = pto_nargs + nargs_total;
if (newnargs_total <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
stack = small_stack;
@@ -285,12 +294,15 @@ partial_setvectorcall(partialobject *pto)
static PyObject *
partial_call(partialobject *pto, PyObject *args, PyObject *kwargs)
{
+ PyObject *kwargs2;
+ PyObject *args2;
+ PyObject *res;
+
assert(PyCallable_Check(pto->fn));
assert(PyTuple_Check(pto->args));
assert(PyDict_Check(pto->kw));
/* Merge keywords */
- PyObject *kwargs2;
if (PyDict_GET_SIZE(pto->kw) == 0) {
/* kwargs can be NULL */
kwargs2 = kwargs;
@@ -315,13 +327,13 @@ partial_call(partialobject *pto, PyObject *args, PyObject *kwargs)
/* Merge positional arguments */
/* Note: tupleconcat() is optimized for empty tuples */
- PyObject *args2 = PySequence_Concat(pto->args, args);
+ args2 = PySequence_Concat(pto->args, args);
if (args2 == NULL) {
Py_XDECREF(kwargs2);
return NULL;
}
- PyObject *res = PyObject_Call(pto->fn, args2, kwargs2);
+ res = PyObject_Call(pto->fn, args2, kwargs2);
Py_DECREF(args2);
Py_XDECREF(kwargs2);
return res;
@@ -489,12 +501,13 @@ static PyType_Slot partial_type_slots[] = {
};
static PyType_Spec partial_type_spec = {
- .name = "functools.partial",
- .basicsize = sizeof(partialobject),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_VECTORCALL |
- Py_TPFLAGS_IMMUTABLETYPE,
- .slots = partial_type_slots
+ "functools.partial",
+ sizeof(partialobject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_VECTORCALL |
+ Py_TPFLAGS_IMMUTABLETYPE,
+ partial_type_slots
};
@@ -558,11 +571,12 @@ static PyType_Slot keyobject_type_slots[] = {
};
static PyType_Spec keyobject_type_spec = {
- .name = "functools.KeyWrapper",
- .basicsize = sizeof(keyobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = keyobject_type_slots
+ "functools.KeyWrapper",
+ sizeof(keyobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
+ keyobject_type_slots
};
static PyObject *
@@ -781,11 +795,12 @@ static PyType_Slot lru_list_elem_type_slots[] = {
};
static PyType_Spec lru_list_elem_type_spec = {
- .name = "functools._lru_list_elem",
- .basicsize = sizeof(lru_list_elem),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE,
- .slots = lru_list_elem_type_slots
+ "functools._lru_list_elem",
+ sizeof(lru_list_elem),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE,
+ lru_list_elem_type_slots
};
@@ -993,6 +1008,7 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
{
lru_list_elem *link;
PyObject *key, *result, *testresult;
+ PyObject *oldkey, *oldresult, *popresult;
Py_hash_t hash;
key = lru_cache_make_key(self->kwd_mark, args, kwds, self->typed);
@@ -1086,8 +1102,6 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
make sense to reinsert the link, so we leave it out
and the cache will no longer register as full.
*/
- PyObject *oldkey, *oldresult, *popresult;
-
/* Extract the oldest item. */
assert(self->root.next != &self->root);
link = self->root.next;
@@ -1345,10 +1359,13 @@ lru_cache_deepcopy(PyObject *self, PyObject *unused)
static int
lru_cache_tp_traverse(lru_cache_object *self, visitproc visit, void *arg)
{
+ lru_list_elem *link;
+ lru_list_elem *next;
+
Py_VISIT(Py_TYPE(self));
- lru_list_elem *link = self->root.next;
+ link = self->root.next;
while (link != &self->root) {
- lru_list_elem *next = link->next;
+ next = link->next;
Py_VISIT(link->key);
Py_VISIT(link->result);
Py_VISIT(Py_TYPE(link));
@@ -1417,11 +1434,12 @@ static PyType_Slot lru_cache_type_slots[] = {
};
static PyType_Spec lru_cache_type_spec = {
- .name = "functools._lru_cache_wrapper",
- .basicsize = sizeof(lru_cache_object),
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_METHOD_DESCRIPTOR | Py_TPFLAGS_IMMUTABLETYPE,
- .slots = lru_cache_type_slots
+ "functools._lru_cache_wrapper",
+ sizeof(lru_cache_object),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_METHOD_DESCRIPTOR | Py_TPFLAGS_IMMUTABLETYPE,
+ lru_cache_type_slots
};
@@ -1441,6 +1459,7 @@ static int
_functools_exec(PyObject *module)
{
_functools_state *state = get_functools_state(module);
+ PyObject *lru_cache_type;
state->kwd_mark = _PyObject_CallNoArgs((PyObject *)&PyBaseObject_Type);
if (state->kwd_mark == NULL) {
return -1;
@@ -1455,7 +1474,7 @@ _functools_exec(PyObject *module)
return -1;
}
- PyObject *lru_cache_type = PyType_FromModuleAndSpec(module,
+ lru_cache_type = PyType_FromModuleAndSpec(module,
&lru_cache_type_spec, NULL);
if (lru_cache_type == NULL) {
return -1;
@@ -1520,14 +1539,14 @@ static struct PyModuleDef_Slot _functools_slots[] = {
static struct PyModuleDef _functools_module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_functools",
- .m_doc = _functools_doc,
- .m_size = sizeof(_functools_state),
- .m_methods = _functools_methods,
- .m_slots = _functools_slots,
- .m_traverse = _functools_traverse,
- .m_clear = _functools_clear,
- .m_free = _functools_free,
+ "_functools",
+ _functools_doc,
+ sizeof(_functools_state),
+ _functools_methods,
+ _functools_slots,
+ _functools_traverse,
+ _functools_clear,
+ _functools_free
};
PyMODINIT_FUNC
diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c
index 3dbaaa0..5b17473 100644
--- a/Modules/_heapqmodule.c
+++ b/Modules/_heapqmodule.c
@@ -250,6 +250,7 @@ _heapq_heappushpop_impl(PyObject *module, PyObject *heap, PyObject *item)
/*[clinic end generated code: output=67231dc98ed5774f input=5dc701f1eb4a4aa7]*/
{
PyObject *returnitem;
+ PyObject *top;
int cmp;
if (PyList_GET_SIZE(heap) == 0) {
@@ -257,7 +258,7 @@ _heapq_heappushpop_impl(PyObject *module, PyObject *heap, PyObject *item)
return item;
}
- PyObject* top = PyList_GET_ITEM(heap, 0);
+ top = PyList_GET_ITEM(heap, 0);
Py_INCREF(top);
cmp = PyObject_RichCompareBool(top, item, Py_LT);
Py_DECREF(top);
diff --git a/Modules/_json.c b/Modules/_json.c
index 9464b9f..eada42f 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -317,21 +317,24 @@ escape_unicode(PyObject *pystr)
static void
raise_errmsg(const char *msg, PyObject *s, Py_ssize_t end)
{
+ PyObject *decoder;
+ PyObject *JSONDecodeError;
+ PyObject *exc;
+ _Py_IDENTIFIER(JSONDecodeError);
+
/* Use JSONDecodeError exception to raise a nice looking ValueError subclass */
_Py_static_string(PyId_decoder, "json.decoder");
- PyObject *decoder = _PyImport_GetModuleId(&PyId_decoder);
+ decoder = _PyImport_GetModuleId(&PyId_decoder);
if (decoder == NULL) {
return;
}
- _Py_IDENTIFIER(JSONDecodeError);
- PyObject *JSONDecodeError = _PyObject_GetAttrId(decoder, &PyId_JSONDecodeError);
+ JSONDecodeError = _PyObject_GetAttrId(decoder, &PyId_JSONDecodeError);
Py_DECREF(decoder);
if (JSONDecodeError == NULL) {
return;
}
- PyObject *exc;
exc = PyObject_CallFunction(JSONDecodeError, "zOn", msg, s, end);
Py_DECREF(JSONDecodeError);
if (exc) {
@@ -394,11 +397,11 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
Py_ssize_t next /* = begin */;
const void *buf;
int kind;
+ _PyUnicodeWriter writer;
if (PyUnicode_READY(pystr) == -1)
return 0;
- _PyUnicodeWriter writer;
_PyUnicodeWriter_Init(&writer);
writer.overallocate = 1;
@@ -1227,11 +1230,11 @@ static PyType_Slot PyScannerType_slots[] = {
};
static PyType_Spec PyScannerType_spec = {
- .name = "_json.Scanner",
- .basicsize = sizeof(PyScannerObject),
- .itemsize = 0,
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
- .slots = PyScannerType_slots,
+ "_json.Scanner",
+ sizeof(PyScannerObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ PyScannerType_slots
};
static PyObject *
@@ -1786,11 +1789,11 @@ static PyType_Slot PyEncoderType_slots[] = {
};
static PyType_Spec PyEncoderType_spec = {
- .name = "_json.Encoder",
- .basicsize = sizeof(PyEncoderObject),
- .itemsize = 0,
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
- .slots = PyEncoderType_slots
+ "_json.Encoder",
+ sizeof(PyEncoderObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ PyEncoderType_slots
};
static PyMethodDef speedups_methods[] = {
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index ac9709c..edbd0a9 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -191,10 +191,13 @@ locale_decode_monetary(PyObject *dict, struct lconv *lc)
}
}
-#define GET_LOCALE_STRING(ATTR) PyUnicode_DecodeLocale(lc->ATTR, NULL)
#else /* MS_WINDOWS */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+#define GET_LOCALE_STRING(ATTR) PyUnicode_DecodeLocale(lc->ATTR, NULL)
+#else
/* Use _W_* fields of Windows struct lconv */
#define GET_LOCALE_STRING(ATTR) PyUnicode_FromWideChar(lc->_W_ ## ATTR, -1)
+#endif
#endif /* MS_WINDOWS */
int res = -1;
@@ -245,6 +248,7 @@ _locale_localeconv_impl(PyObject *module)
PyObject* result;
struct lconv *lc;
PyObject *x;
+ PyObject *decimal_point = NULL, *thousands_sep = NULL;
result = PyDict_New();
if (!result) {
@@ -268,7 +272,9 @@ _locale_localeconv_impl(PyObject *module)
Py_DECREF(obj); \
} while (0)
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+#define GET_LOCALE_STRING(ATTR) PyUnicode_DecodeLocale(lc->ATTR, NULL)
+#elif defined(MS_WINDOWS)
/* Use _W_* fields of Windows struct lconv */
#define GET_LOCALE_STRING(ATTR) PyUnicode_FromWideChar(lc->_W_ ## ATTR, -1)
#else
@@ -305,7 +311,6 @@ _locale_localeconv_impl(PyObject *module)
RESULT_INT(n_sign_posn);
/* Numeric information: LC_NUMERIC encoding */
- PyObject *decimal_point = NULL, *thousands_sep = NULL;
if (_Py_GetLocaleconvNumeric(lc, &decimal_point, &thousands_sep) < 0) {
Py_XDECREF(decimal_point);
Py_XDECREF(thousands_sep);
@@ -828,6 +833,7 @@ _locale_exec(PyObject *module)
} \
} while (0)
+ _locale_state *state;
ADD_INT(module, LC_CTYPE);
ADD_INT(module, LC_TIME);
ADD_INT(module, LC_COLLATE);
@@ -841,7 +847,7 @@ _locale_exec(PyObject *module)
ADD_INT(module, LC_ALL);
ADD_INT(module, CHAR_MAX);
- _locale_state *state = get_locale_state(module);
+ state = get_locale_state(module);
state->Error = PyErr_NewException("locale.Error", NULL, NULL);
if (state->Error == NULL) {
return -1;
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index a0e262b..f785e94 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -82,14 +82,16 @@ _lsprof_get_state(PyObject *module)
static _PyTime_t CallExternalTimer(ProfilerObject *pObj)
{
- PyObject *o = _PyObject_CallNoArgs(pObj->externalTimer);
+ PyObject *o;
+ _PyTime_t result;
+ int err;
+
+ o = _PyObject_CallNoArgs(pObj->externalTimer);
if (o == NULL) {
PyErr_WriteUnraisable(pObj->externalTimer);
return 0;
}
- _PyTime_t result;
- int err;
if (pObj->externalTimerUnit > 0.0) {
/* interpret the result as an integer that will be scaled
in profiler_getstats() */
@@ -494,17 +496,17 @@ static PyStructSequence_Field profiler_subentry_fields[] = {
};
static PyStructSequence_Desc profiler_entry_desc = {
- .name = "_lsprof.profiler_entry",
- .fields = profiler_entry_fields,
- .doc = NULL,
- .n_in_sequence = 6
+ "_lsprof.profiler_entry",
+ NULL,
+ profiler_entry_fields,
+ 6
};
static PyStructSequence_Desc profiler_subentry_desc = {
- .name = "_lsprof.profiler_subentry",
- .fields = profiler_subentry_fields,
- .doc = NULL,
- .n_in_sequence = 5
+ "_lsprof.profiler_subentry",
+ NULL,
+ profiler_subentry_fields,
+ 5
};
typedef struct {
@@ -670,6 +672,7 @@ profiler_enable(ProfilerObject *self, PyObject *args, PyObject *kwds)
int subcalls = -1;
int builtins = -1;
static char *kwlist[] = {"subcalls", "builtins", 0};
+ PyThreadState *tstate;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii:enable",
kwlist, &subcalls, &builtins))
return NULL;
@@ -677,7 +680,7 @@ profiler_enable(ProfilerObject *self, PyObject *args, PyObject *kwds)
return NULL;
}
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (_PyEval_SetProfile(tstate, profiler_callback, (PyObject*)self) < 0) {
return NULL;
}
@@ -747,9 +750,11 @@ profiler_traverse(ProfilerObject *op, visitproc visit, void *arg)
static void
profiler_dealloc(ProfilerObject *op)
{
+ PyTypeObject *tp;
+ PyThreadState *tstate;
PyObject_GC_UnTrack(op);
if (op->flags & POF_ENABLED) {
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {
_PyErr_WriteUnraisableMsg("When destroying _lsprof profiler", NULL);
}
@@ -758,7 +763,7 @@ profiler_dealloc(ProfilerObject *op)
flush_unmatched(op);
clearEntries(op);
Py_XDECREF(op->externalTimer);
- PyTypeObject *tp = Py_TYPE(op);
+ tp = Py_TYPE(op);
tp->tp_free(op);
Py_DECREF(tp);
}
@@ -817,11 +822,12 @@ static PyType_Slot _lsprof_profiler_type_spec_slots[] = {
};
static PyType_Spec _lsprof_profiler_type_spec = {
- .name = "_lsprof.Profiler",
- .basicsize = sizeof(ProfilerObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = _lsprof_profiler_type_spec_slots,
+ "_lsprof.Profiler",
+ sizeof(ProfilerObject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
+ _lsprof_profiler_type_spec_slots
};
static PyMethodDef moduleMethods[] = {
@@ -895,14 +901,14 @@ static PyModuleDef_Slot _lsprofslots[] = {
static struct PyModuleDef _lsprofmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_lsprof",
- .m_doc = "Fast profiler",
- .m_size = sizeof(_lsprof_state),
- .m_methods = moduleMethods,
- .m_slots = _lsprofslots,
- .m_traverse = _lsprof_traverse,
- .m_clear = _lsprof_clear,
- .m_free = _lsprof_free
+ "_lsprof",
+ "Fast profiler",
+ sizeof(_lsprof_state),
+ moduleMethods,
+ _lsprofslots,
+ _lsprof_traverse,
+ _lsprof_clear,
+ _lsprof_free
};
PyMODINIT_FUNC
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index f0cb302..47ba9e5 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -761,7 +761,10 @@ PyMemoTable_New(void)
static PyMemoTable *
PyMemoTable_Copy(PyMemoTable *self)
{
- PyMemoTable *new = PyMemoTable_New();
+ PyMemoTable *new;
+ size_t i;
+
+ new = PyMemoTable_New();
if (new == NULL)
return NULL;
@@ -777,7 +780,7 @@ PyMemoTable_Copy(PyMemoTable *self)
PyErr_NoMemory();
return NULL;
}
- for (size_t i = 0; i < self->mt_allocated; i++) {
+ for (i = 0; i < self->mt_allocated; i++) {
Py_XINCREF(self->mt_table[i].me_key);
}
memcpy(new->mt_table, self->mt_table,
@@ -911,6 +914,7 @@ static int
PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
{
PyMemoEntry *entry;
+ size_t desired_size;
assert(key != NULL);
@@ -934,11 +938,11 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value)
* Very large memo tables (over 50K items) use doubling instead.
* This may help applications with severe memory constraints.
*/
- if (SIZE_MAX / 3 >= self->mt_used && self->mt_used * 3 < self->mt_allocated * 2) {
+ if (((size_t)-1) / 3 >= self->mt_used && self->mt_used * 3 < self->mt_allocated * 2) {
return 0;
}
// self->mt_used is always < PY_SSIZE_T_MAX, so this can't overflow.
- size_t desired_size = (self->mt_used > 50000 ? 2 : 4) * self->mt_used;
+ desired_size = (self->mt_used > 50000 ? 2 : 4) * self->mt_used;
return _PyMemoTable_ResizeTable(self, desired_size);
}
@@ -1116,18 +1120,22 @@ _Pickler_Write(PicklerObject *self, const char *s, Py_ssize_t data_len)
static PicklerObject *
_Pickler_New(void)
{
- PyMemoTable *memo = PyMemoTable_New();
+ PyMemoTable *memo;
+ const Py_ssize_t max_output_len = WRITE_BUF_SIZE;
+ PyObject *output_buffer;
+ PicklerObject *self;
+
+ memo = PyMemoTable_New();
if (memo == NULL) {
return NULL;
}
- const Py_ssize_t max_output_len = WRITE_BUF_SIZE;
- PyObject *output_buffer = PyBytes_FromStringAndSize(NULL, max_output_len);
+ output_buffer = PyBytes_FromStringAndSize(NULL, max_output_len);
if (output_buffer == NULL) {
goto error;
}
- PicklerObject *self = PyObject_GC_New(PicklerObject, &Pickler_Type);
+ self = PyObject_GC_New(PicklerObject, &Pickler_Type);
if (self == NULL) {
goto error;
}
@@ -1377,12 +1385,20 @@ _Unpickler_ReadImpl(UnpicklerObject *self, char **s, Py_ssize_t n)
static Py_ssize_t
_Unpickler_ReadInto(UnpicklerObject *self, char *buf, Py_ssize_t n)
{
+ Py_ssize_t in_buffer;
+ Py_ssize_t to_read;
+ PyObject *len;
+ PyObject *data;
+ PyObject *buf_obj;
+ PyObject *read_size_obj;
+ Py_ssize_t read_size;
+
assert(n != READ_WHOLE_LINE);
/* Read from available buffer data, if any */
- Py_ssize_t in_buffer = self->input_len - self->next_read_idx;
+ in_buffer = self->input_len - self->next_read_idx;
if (in_buffer > 0) {
- Py_ssize_t to_read = Py_MIN(in_buffer, n);
+ to_read = Py_MIN(in_buffer, n);
memcpy(buf, self->input_buffer + self->next_read_idx, to_read);
self->next_read_idx += to_read;
buf += to_read;
@@ -1405,11 +1421,11 @@ _Unpickler_ReadInto(UnpicklerObject *self, char *buf, Py_ssize_t n)
if (!self->readinto) {
/* readinto() not supported on file-like object, fall back to read()
* and copy into destination buffer (bpo-39681) */
- PyObject* len = PyLong_FromSsize_t(n);
+ len = PyLong_FromSsize_t(n);
if (len == NULL) {
return -1;
}
- PyObject* data = _Pickle_FastCall(self->read, len);
+ data = _Pickle_FastCall(self->read, len);
if (data == NULL) {
return -1;
}
@@ -1420,7 +1436,7 @@ _Unpickler_ReadInto(UnpicklerObject *self, char *buf, Py_ssize_t n)
Py_DECREF(data);
return -1;
}
- Py_ssize_t read_size = PyBytes_GET_SIZE(data);
+ read_size = PyBytes_GET_SIZE(data);
if (read_size < n) {
Py_DECREF(data);
return bad_readline();
@@ -1431,15 +1447,15 @@ _Unpickler_ReadInto(UnpicklerObject *self, char *buf, Py_ssize_t n)
}
/* Call readinto() into user buffer */
- PyObject *buf_obj = PyMemoryView_FromMemory(buf, n, PyBUF_WRITE);
+ buf_obj = PyMemoryView_FromMemory(buf, n, PyBUF_WRITE);
if (buf_obj == NULL) {
return -1;
}
- PyObject *read_size_obj = _Pickle_FastCall(self->readinto, buf_obj);
+ read_size_obj = _Pickle_FastCall(self->readinto, buf_obj);
if (read_size_obj == NULL) {
return -1;
}
- Py_ssize_t read_size = PyLong_AsSsize_t(read_size_obj);
+ read_size = PyLong_AsSsize_t(read_size_obj);
Py_DECREF(read_size_obj);
if (read_size < 0) {
@@ -1527,10 +1543,11 @@ static int
_Unpickler_ResizeMemoList(UnpicklerObject *self, size_t new_size)
{
size_t i;
+ PyObject **memo_new;
assert(new_size > self->memo_size);
- PyObject **memo_new = self->memo;
+ memo_new = self->memo;
PyMem_RESIZE(memo_new, PyObject *, new_size);
if (memo_new == NULL) {
PyErr_NoMemory();
@@ -1610,17 +1627,21 @@ static UnpicklerObject *
_Unpickler_New(void)
{
const int MEMO_SIZE = 32;
- PyObject **memo = _Unpickler_NewMemo(MEMO_SIZE);
+ PyObject **memo;
+ PyObject *stack;
+ UnpicklerObject *self;
+
+ memo = _Unpickler_NewMemo(MEMO_SIZE);
if (memo == NULL) {
return NULL;
}
- PyObject *stack = Pdata_New();
+ stack = Pdata_New();
if (stack == NULL) {
goto error;
}
- UnpicklerObject *self = PyObject_GC_New(UnpicklerObject, &Unpickler_Type);
+ self = PyObject_GC_New(UnpicklerObject, &Unpickler_Type);
if (self == NULL) {
goto error;
}
@@ -1914,6 +1935,8 @@ static int
_checkmodule(PyObject *module_name, PyObject *module,
PyObject *global, PyObject *dotted_path)
{
+ PyObject *candidate;
+
if (module == Py_None) {
return -1;
}
@@ -1922,7 +1945,7 @@ _checkmodule(PyObject *module_name, PyObject *module,
return -1;
}
- PyObject *candidate = get_deep_attribute(module, dotted_path, NULL);
+ candidate = get_deep_attribute(module, dotted_path, NULL);
if (candidate == NULL) {
return -1;
}
@@ -1940,6 +1963,7 @@ whichmodule(PyObject *global, PyObject *dotted_path)
PyObject *module_name;
PyObject *module = NULL;
Py_ssize_t i;
+ PyThreadState *tstate;
PyObject *modules;
if (_PyObject_LookupAttr(global, &_Py_ID(__module__), &module_name) < 0) {
@@ -1956,7 +1980,7 @@ whichmodule(PyObject *global, PyObject *dotted_path)
assert(module_name == NULL);
/* Fallback on walking sys.modules */
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
modules = _PySys_GetAttr(tstate, &_Py_ID(modules));
if (modules == NULL) {
PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules");
@@ -2018,6 +2042,8 @@ whichmodule(PyObject *global, PyObject *dotted_path)
static int
fast_save_enter(PicklerObject *self, PyObject *obj)
{
+ int r;
+
/* if fast_nesting < 0, we're doing an error exit. */
if (++self->fast_nesting >= FAST_NESTING_LIMIT) {
PyObject *key = NULL;
@@ -2033,7 +2059,7 @@ fast_save_enter(PicklerObject *self, PyObject *obj)
self->fast_nesting = -1;
return 0;
}
- int r = PyDict_Contains(self->fast_memo, key);
+ r = PyDict_Contains(self->fast_memo, key);
if (r > 0) {
PyErr_Format(PyExc_ValueError,
"fast mode: can't pickle cyclic objects "
@@ -2381,11 +2407,11 @@ static int
_save_bytes_data(PicklerObject *self, PyObject *obj, const char *data,
Py_ssize_t size)
{
- assert(self->proto >= 3);
-
char header[9];
Py_ssize_t len;
+ assert(self->proto >= 3);
+
if (size < 0)
return -1;
@@ -2479,11 +2505,11 @@ static int
_save_bytearray_data(PicklerObject *self, PyObject *obj, const char *data,
Py_ssize_t size)
{
- assert(self->proto >= 5);
-
char header[9];
Py_ssize_t len;
+ assert(self->proto >= 5);
+
if (size < 0)
return -1;
@@ -2541,13 +2567,16 @@ save_bytearray(PicklerObject *self, PyObject *obj)
static int
save_picklebuffer(PicklerObject *self, PyObject *obj)
{
+ const Py_buffer *view;
+ int in_band;
+
if (self->proto < 5) {
PickleState *st = _Pickle_GetGlobalState();
PyErr_SetString(st->PicklingError,
"PickleBuffer can only pickled with protocol >= 5");
return -1;
}
- const Py_buffer* view = PyPickleBuffer_GetBuffer(obj);
+ view = PyPickleBuffer_GetBuffer(obj);
if (view == NULL) {
return -1;
}
@@ -2558,7 +2587,7 @@ save_picklebuffer(PicklerObject *self, PyObject *obj)
"pointing to a non-contiguous buffer");
return -1;
}
- int in_band = 1;
+ in_band = 1;
if (self->buffer_callback != NULL) {
PyObject *ret = PyObject_CallOneArg(self->buffer_callback, obj);
if (ret == NULL) {
@@ -3021,6 +3050,7 @@ batch_list_exact(PicklerObject *self, PyObject *obj)
{
PyObject *item = NULL;
Py_ssize_t this_batch, total;
+ int err;
const char append_op = APPEND;
const char appends_op = APPENDS;
@@ -3033,7 +3063,7 @@ batch_list_exact(PicklerObject *self, PyObject *obj)
if (PyList_GET_SIZE(obj) == 1) {
item = PyList_GET_ITEM(obj, 0);
Py_INCREF(item);
- int err = save(self, item, 0);
+ err = save(self, item, 0);
Py_DECREF(item);
if (err < 0)
return -1;
@@ -3051,7 +3081,7 @@ batch_list_exact(PicklerObject *self, PyObject *obj)
while (total < PyList_GET_SIZE(obj)) {
item = PyList_GET_ITEM(obj, total);
Py_INCREF(item);
- int err = save(self, item, 0);
+ err = save(self, item, 0);
Py_DECREF(item);
if (err < 0)
return -1;
@@ -3414,6 +3444,7 @@ save_set(PicklerObject *self, PyObject *obj)
{
PyObject *item;
int i;
+ int err;
Py_ssize_t set_size, ppos = 0;
Py_hash_t hash;
@@ -3458,7 +3489,7 @@ save_set(PicklerObject *self, PyObject *obj)
return -1;
while (_PySet_NextEntry(obj, &ppos, &item, &hash)) {
Py_INCREF(item);
- int err = save(self, item, 0);
+ err = save(self, item, 0);
Py_CLEAR(item);
if (err < 0)
return -1;
@@ -4685,13 +4716,15 @@ Pickler_dealloc(PicklerObject *self)
static int
Pickler_traverse(PicklerObject *self, visitproc visit, void *arg)
{
+ PyMemoTable *memo;
+
Py_VISIT(self->write);
Py_VISIT(self->pers_func);
Py_VISIT(self->dispatch_table);
Py_VISIT(self->fast_memo);
Py_VISIT(self->reducer_override);
Py_VISIT(self->buffer_callback);
- PyMemoTable *memo = self->memo;
+ memo = self->memo;
if (memo && memo->mt_table) {
Py_ssize_t i = memo->mt_allocated;
while (--i >= 0) {
@@ -4855,11 +4888,12 @@ _pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self)
{
PyMemoTable *memo;
PyObject *new_memo = PyDict_New();
+ size_t i;
if (new_memo == NULL)
return NULL;
memo = self->pickler->memo;
- for (size_t i = 0; i < memo->mt_allocated; ++i) {
+ for (i = 0; i < memo->mt_allocated; ++i) {
PyMemoEntry entry = memo->mt_table[i];
if (entry.me_key != NULL) {
int status;
@@ -5618,17 +5652,20 @@ load_counted_bytearray(UnpicklerObject *self)
static int
load_next_buffer(UnpicklerObject *self)
{
+ PickleState *st;
+ PyObject *buf;
+
if (self->buffers == NULL) {
- PickleState *st = _Pickle_GetGlobalState();
+ st = _Pickle_GetGlobalState();
PyErr_SetString(st->UnpicklingError,
"pickle stream refers to out-of-band data "
"but no *buffers* argument was given");
return -1;
}
- PyObject *buf = PyIter_Next(self->buffers);
+ buf = PyIter_Next(self->buffers);
if (buf == NULL) {
if (!PyErr_Occurred()) {
- PickleState *st = _Pickle_GetGlobalState();
+ st = _Pickle_GetGlobalState();
PyErr_SetString(st->UnpicklingError,
"not enough out-of-band buffers");
}
@@ -5642,13 +5679,17 @@ load_next_buffer(UnpicklerObject *self)
static int
load_readonly_buffer(UnpicklerObject *self)
{
- Py_ssize_t len = Py_SIZE(self->stack);
+ Py_ssize_t len;
+ PyObject *obj;
+ PyObject *view;
+
+ len = Py_SIZE(self->stack);
if (len <= self->stack->fence) {
return Pdata_stack_underflow(self->stack);
}
- PyObject *obj = self->stack->data[len - 1];
- PyObject *view = PyMemoryView_FromObject(obj);
+ obj = self->stack->data[len - 1];
+ view = PyMemoryView_FromObject(obj);
if (view == NULL) {
return -1;
}
@@ -7215,6 +7256,8 @@ Unpickler_dealloc(UnpicklerObject *self)
static int
Unpickler_traverse(UnpicklerObject *self, visitproc visit, void *arg)
{
+ PyObject **memo;
+
Py_VISIT(self->readline);
Py_VISIT(self->readinto);
Py_VISIT(self->read);
@@ -7222,7 +7265,7 @@ Unpickler_traverse(UnpicklerObject *self, visitproc visit, void *arg)
Py_VISIT(self->stack);
Py_VISIT(self->pers_func);
Py_VISIT(self->buffers);
- PyObject **memo = self->memo;
+ memo = self->memo;
if (memo) {
Py_ssize_t i = self->memo_size;
while (--i >= 0) {
@@ -7527,6 +7570,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored
{
PyObject **new_memo;
size_t new_memo_size = 0;
+ size_t i;
if (obj == NULL) {
PyErr_SetString(PyExc_TypeError,
@@ -7543,7 +7587,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored
if (new_memo == NULL)
return -1;
- for (size_t i = 0; i < new_memo_size; i++) {
+ for (i = 0; i < new_memo_size; i++) {
Py_XINCREF(unpickler->memo[i]);
new_memo[i] = unpickler->memo[i];
}
@@ -7591,7 +7635,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj, void *Py_UNUSED(ignored
error:
if (new_memo_size) {
- for (size_t i = new_memo_size - 1; i != SIZE_MAX; i--) {
+ for (i = new_memo_size; i-- > 0;) {
Py_XDECREF(new_memo[i]);
}
PyMem_Free(new_memo);
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index d96c037..26bbb56 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -585,6 +585,8 @@ static int
_random_exec(PyObject *module)
{
_randomstate *state = get_random_state(module);
+ PyObject *longval;
+ PyObject *longtype;
state->Random_Type = PyType_FromModuleAndSpec(
module, &Random_Type_spec, NULL);
@@ -596,12 +598,12 @@ _random_exec(PyObject *module)
}
/* Look up and save int.__abs__, which is needed in random_seed(). */
- PyObject *longval = PyLong_FromLong(0);
+ longval = PyLong_FromLong(0);
if (longval == NULL) {
return -1;
}
- PyObject *longtype = PyObject_Type(longval);
+ longtype = PyObject_Type(longval);
Py_DECREF(longval);
if (longtype == NULL) {
return -1;
diff --git a/Modules/_sha3/sha3module.c b/Modules/_sha3/sha3module.c
index bd1dd59..7abc300 100644
--- a/Modules/_sha3/sha3module.c
+++ b/Modules/_sha3/sha3module.c
@@ -176,11 +176,13 @@ py_sha3_new_impl(PyTypeObject *type, PyObject *data, int usedforsecurity)
static void
SHA3_dealloc(SHA3object *self)
{
+ PyTypeObject *tp;
+
if (self->lock) {
PyThread_free_lock(self->lock);
}
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
PyObject_Free(self);
Py_DECREF(tp);
}
@@ -412,10 +414,11 @@ static PyGetSetDef SHA3_getseters[] = {
// cannot be subclassed: it does not have the Py_TPFLAGS_BASETYPE flag.
#define SHA3_TYPE_SPEC(type_spec_obj, type_name, type_slots) \
static PyType_Spec type_spec_obj = { \
- .name = "_sha3." type_name, \
- .basicsize = sizeof(SHA3object), \
- .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE, \
- .slots = type_slots \
+ "_sha3." type_name, \
+ sizeof(SHA3object), \
+ 0, \
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE, \
+ type_slots \
}
PyDoc_STRVAR(sha3_224__doc__,
@@ -646,12 +649,14 @@ static PyModuleDef_Slot _sha3_slots[] = {
/* Initialize this module. */
static struct PyModuleDef _sha3module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_sha3",
- .m_size = sizeof(SHA3State),
- .m_slots = _sha3_slots,
- .m_traverse = _sha3_traverse,
- .m_clear = _sha3_clear,
- .m_free = _sha3_free,
+ "_sha3",
+ NULL,
+ sizeof(SHA3State),
+ NULL,
+ _sha3_slots,
+ _sha3_traverse,
+ _sha3_clear,
+ _sha3_free,
};
diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c
index 3bad9d8..53c8ce0 100644
--- a/Modules/_sre/sre.c
+++ b/Modules/_sre/sre.c
@@ -1655,6 +1655,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
SRE_CODE op;
SRE_CODE arg;
SRE_CODE skip;
+ int rc;
VTRACE(("code=%p, end=%p\n", code, end));
@@ -1922,7 +1923,7 @@ _validate_inner(SRE_CODE *code, SRE_CODE *end, Py_ssize_t groups)
for a JUMP opcode preceding our skip target.
*/
VTRACE(("then part:\n"));
- int rc = _validate_inner(code+1, code+skip-1, groups);
+ rc = _validate_inner(code+1, code+skip-1, groups);
if (rc == 1) {
VTRACE(("else part:\n"));
code += skip-2; /* Position after JUMP, at <skipno> */
@@ -2822,12 +2823,12 @@ static PyType_Slot pattern_slots[] = {
};
static PyType_Spec pattern_spec = {
- .name = "re.Pattern",
- .basicsize = sizeof(PatternObject),
- .itemsize = sizeof(SRE_CODE),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
- Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC),
- .slots = pattern_slots,
+ "re.Pattern",
+ sizeof(PatternObject),
+ sizeof(SRE_CODE),
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
+ Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC),
+ pattern_slots,
};
static PyMethodDef match_methods[] = {
@@ -2890,12 +2891,12 @@ static PyType_Slot match_slots[] = {
};
static PyType_Spec match_spec = {
- .name = "re.Match",
- .basicsize = sizeof(MatchObject),
- .itemsize = sizeof(Py_ssize_t),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
- Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC),
- .slots = match_slots,
+ "re.Match",
+ sizeof(MatchObject),
+ sizeof(Py_ssize_t),
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
+ Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC),
+ match_slots,
};
static PyMethodDef scanner_methods[] = {
@@ -2920,11 +2921,12 @@ static PyType_Slot scanner_slots[] = {
};
static PyType_Spec scanner_spec = {
- .name = "_" SRE_MODULE ".SRE_Scanner",
- .basicsize = sizeof(ScannerObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
- Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC),
- .slots = scanner_slots,
+ "_" SRE_MODULE ".SRE_Scanner",
+ sizeof(ScannerObject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
+ Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_HAVE_GC),
+ scanner_slots,
};
static PyMethodDef _functions[] = {
@@ -2978,9 +2980,10 @@ do { \
#define ADD_ULONG_CONSTANT(module, name, value) \
do { \
PyObject *o = PyLong_FromUnsignedLong(value); \
+ int res; \
if (!o) \
goto error; \
- int res = PyModule_AddObjectRef(module, name, o); \
+ res = PyModule_AddObjectRef(module, name, o); \
Py_DECREF(o); \
if (res < 0) { \
goto error; \
@@ -3025,14 +3028,15 @@ static PyModuleDef_Slot sre_slots[] = {
};
static struct PyModuleDef sremodule = {
- .m_base = PyModuleDef_HEAD_INIT,
- .m_name = "_" SRE_MODULE,
- .m_size = sizeof(_sremodulestate),
- .m_methods = _functions,
- .m_slots = sre_slots,
- .m_traverse = sre_traverse,
- .m_free = sre_free,
- .m_clear = sre_clear,
+ PyModuleDef_HEAD_INIT,
+ "_" SRE_MODULE,
+ NULL,
+ sizeof(_sremodulestate),
+ _functions,
+ sre_slots,
+ sre_traverse,
+ sre_clear,
+ sre_free,
};
PyMODINIT_FUNC
diff --git a/Modules/_sre/sre_lib.h b/Modules/_sre/sre_lib.h
index 95c1ada..e73bccf 100644
--- a/Modules/_sre/sre_lib.h
+++ b/Modules/_sre/sre_lib.h
@@ -560,6 +560,8 @@ LOCAL(Py_ssize_t)
SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
{
const SRE_CHAR* end = (const SRE_CHAR *)state->end;
+ const SRE_CHAR *ptr;
+ SRE_REPEAT *repeat_of_tail;
Py_ssize_t alloc_pos, ctx_pos = -1;
Py_ssize_t ret = 0;
int jump;
@@ -583,7 +585,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
entrance:
; // Fashion statement.
- const SRE_CHAR *ptr = (SRE_CHAR *)state->ptr;
+ ptr = (SRE_CHAR *)state->ptr;
if (pattern[0] == SRE_OP_INFO) {
/* optimization info block */
@@ -1211,7 +1213,7 @@ SRE(match)(SRE_STATE* state, const SRE_CODE* pattern, int toplevel)
MARK_PUSH(ctx->lastmark);
DO_JUMP(JUMP_MIN_UNTIL_2, jump_min_until_2, pattern);
- SRE_REPEAT *repeat_of_tail = state->repeat;
+ repeat_of_tail = state->repeat;
state->repeat = ctx->u.rep; // restore repeat before return
if (ret) {
diff --git a/Modules/_stat.c b/Modules/_stat.c
index 6e0d690..20f6e58 100644
--- a/Modules/_stat.c
+++ b/Modules/_stat.c
@@ -30,6 +30,19 @@ extern "C" {
#include <windows.h>
typedef unsigned short mode_t;
+/* These constants are not present in the VC6 Windows headers. */
+#ifndef FILE_ATTRIBUTE_DEVICE
+# define FILE_ATTRIBUTE_DEVICE 0x0040
+#endif
+
+#ifndef FILE_ATTRIBUTE_VIRTUAL
+# define FILE_ATTRIBUTE_VIRTUAL 0x10000
+#endif
+
+#ifndef IO_REPARSE_TAG_SYMLINK
+# define IO_REPARSE_TAG_SYMLINK 0xA000000CL
+#endif
+
/* FILE_ATTRIBUTE_INTEGRITY_STREAM and FILE_ATTRIBUTE_NO_SCRUB_DATA
are not present in VC2010, so define them manually */
#ifndef FILE_ATTRIBUTE_INTEGRITY_STREAM
@@ -499,6 +512,20 @@ ST_CTIME\n\
static int
stat_exec(PyObject *module)
{
+ const char* st_constants[] = {
+ "ST_MODE",
+ "ST_INO",
+ "ST_DEV",
+ "ST_NLINK",
+ "ST_UID",
+ "ST_GID",
+ "ST_SIZE",
+ "ST_ATIME",
+ "ST_MTIME",
+ "ST_CTIME"
+ };
+ int i;
+
#define ADD_INT_MACRO(module, macro) \
do { \
if (PyModule_AddIntConstant(module, #macro, macro) < 0) { \
@@ -554,20 +581,7 @@ stat_exec(PyObject *module)
ADD_INT_MACRO(module, SF_NOUNLINK);
ADD_INT_MACRO(module, SF_SNAPSHOT);
- const char* st_constants[] = {
- "ST_MODE",
- "ST_INO",
- "ST_DEV",
- "ST_NLINK",
- "ST_UID",
- "ST_GID",
- "ST_SIZE",
- "ST_ATIME",
- "ST_MTIME",
- "ST_CTIME"
- };
-
- for (int i = 0; i < (int)Py_ARRAY_LENGTH(st_constants); i++) {
+ for (i = 0; i < (int)Py_ARRAY_LENGTH(st_constants); i++) {
if (PyModule_AddIntConstant(module, st_constants[i], i) < 0) {
return -1;
}
@@ -618,11 +632,14 @@ static PyModuleDef_Slot stat_slots[] = {
static struct PyModuleDef statmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_stat",
- .m_doc = module_doc,
- .m_size = 0,
- .m_methods = stat_methods,
- .m_slots = stat_slots,
+ "_stat",
+ module_doc,
+ 0,
+ stat_methods,
+ stat_slots,
+ NULL,
+ NULL,
+ NULL,
};
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 9d66568..97921b1 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -14,6 +14,11 @@
#include "structmember.h" // PyMemberDef
#include <ctype.h>
+#if defined(_MSC_VER) && _MSC_VER < 1300
+/* MSVC6 has no C99 _Bool; preserve the one-byte layout used by struct. */
+typedef unsigned char _Bool;
+#endif
+
/*[clinic input]
class Struct "PyStructObject *" "&PyStructType"
[clinic start generated code]*/
@@ -95,8 +100,8 @@ typedef struct { char c; _Bool x; } st_bool;
/* We can't support q and Q in native mode unless the compiler does;
in std mode, they're 8 bytes on all platforms. */
-typedef struct { char c; long long x; } s_long_long;
-#define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(long long))
+typedef struct { char c; PY_LONG_LONG x; } s_long_long;
+#define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(PY_LONG_LONG))
#ifdef __powerc
#pragma options align=reset
@@ -203,9 +208,9 @@ get_ulong(_structmodulestate *state, PyObject *v, unsigned long *p)
/* Same, but handling native long long. */
static int
-get_longlong(_structmodulestate *state, PyObject *v, long long *p)
+get_longlong(_structmodulestate *state, PyObject *v, PY_LONG_LONG *p)
{
- long long x;
+ PY_LONG_LONG x;
v = get_pylong(state, v);
if (v == NULL)
@@ -213,7 +218,7 @@ get_longlong(_structmodulestate *state, PyObject *v, long long *p)
assert(PyLong_Check(v));
x = PyLong_AsLongLong(v);
Py_DECREF(v);
- if (x == (long long)-1 && PyErr_Occurred()) {
+ if (x == (PY_LONG_LONG)-1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_SetString(state->StructError,
"argument out of range");
@@ -226,9 +231,9 @@ get_longlong(_structmodulestate *state, PyObject *v, long long *p)
/* Same, but handling native unsigned long long. */
static int
-get_ulonglong(_structmodulestate *state, PyObject *v, unsigned long long *p)
+get_ulonglong(_structmodulestate *state, PyObject *v, unsigned PY_LONG_LONG *p)
{
- unsigned long long x;
+ unsigned PY_LONG_LONG x;
v = get_pylong(state, v);
if (v == NULL)
@@ -236,7 +241,7 @@ get_ulonglong(_structmodulestate *state, PyObject *v, unsigned long long *p)
assert(PyLong_Check(v));
x = PyLong_AsUnsignedLongLong(v);
Py_DECREF(v);
- if (x == (unsigned long long)-1 && PyErr_Occurred()) {
+ if (x == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) {
if (PyErr_ExceptionMatches(PyExc_OverflowError))
PyErr_SetString(state->StructError,
"argument out of range");
@@ -485,7 +490,7 @@ nu_size_t(_structmodulestate *state, const char *p, const formatdef *f)
static PyObject *
nu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
{
- long long x;
+ PY_LONG_LONG x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromLongLong(x);
}
@@ -493,7 +498,7 @@ nu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
static PyObject *
nu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
{
- unsigned long long x;
+ unsigned PY_LONG_LONG x;
memcpy((char *)&x, p, sizeof x);
return PyLong_FromUnsignedLongLong(x);
}
@@ -694,7 +699,7 @@ np_size_t(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
static int
np_longlong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{
- long long x;
+ PY_LONG_LONG x;
if (get_longlong(state, v, &x) < 0)
return -1;
memcpy(p, (char *)&x, sizeof x);
@@ -704,7 +709,7 @@ np_longlong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
static int
np_ulonglong(_structmodulestate *state, char *p, PyObject *v, const formatdef *f)
{
- unsigned long long x;
+ unsigned PY_LONG_LONG x;
if (get_ulonglong(state, v, &x) < 0)
return -1;
memcpy(p, (char *)&x, sizeof x);
@@ -793,8 +798,8 @@ static const formatdef native_table[] = {
{'L', sizeof(long), LONG_ALIGN, nu_ulong, np_ulong},
{'n', sizeof(size_t), SIZE_T_ALIGN, nu_ssize_t, np_ssize_t},
{'N', sizeof(size_t), SIZE_T_ALIGN, nu_size_t, np_size_t},
- {'q', sizeof(long long), LONG_LONG_ALIGN, nu_longlong, np_longlong},
- {'Q', sizeof(long long), LONG_LONG_ALIGN, nu_ulonglong,np_ulonglong},
+ {'q', sizeof(PY_LONG_LONG), LONG_LONG_ALIGN, nu_longlong, np_longlong},
+ {'Q', sizeof(PY_LONG_LONG), LONG_LONG_ALIGN, nu_ulonglong,np_ulonglong},
{'?', sizeof(_Bool), BOOL_ALIGN, nu_bool, np_bool},
{'e', sizeof(short), SHORT_ALIGN, nu_halffloat, np_halffloat},
{'f', sizeof(float), FLOAT_ALIGN, nu_float, np_float},
@@ -835,7 +840,7 @@ bu_uint(_structmodulestate *state, const char *p, const formatdef *f)
static PyObject *
bu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
{
- long long x = 0;
+ PY_LONG_LONG x = 0;
Py_ssize_t i = f->size;
const unsigned char *bytes = (const unsigned char *)p;
do {
@@ -843,14 +848,14 @@ bu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
} while (--i > 0);
/* Extend the sign bit. */
if (SIZEOF_LONG_LONG > f->size)
- x |= -(x & ((long long)1 << ((8 * f->size) - 1)));
+ x |= -(x & ((PY_LONG_LONG)1 << ((8 * f->size) - 1)));
return PyLong_FromLongLong(x);
}
static PyObject *
bu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
{
- unsigned long long x = 0;
+ unsigned PY_LONG_LONG x = 0;
Py_ssize_t i = f->size;
const unsigned char *bytes = (const unsigned char *)p;
do {
@@ -1056,7 +1061,7 @@ lu_uint(_structmodulestate *state, const char *p, const formatdef *f)
static PyObject *
lu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
{
- long long x = 0;
+ PY_LONG_LONG x = 0;
Py_ssize_t i = f->size;
const unsigned char *bytes = (const unsigned char *)p;
do {
@@ -1064,14 +1069,14 @@ lu_longlong(_structmodulestate *state, const char *p, const formatdef *f)
} while (i > 0);
/* Extend the sign bit. */
if (SIZEOF_LONG_LONG > f->size)
- x |= -(x & ((long long)1 << ((8 * f->size) - 1)));
+ x |= -(x & ((PY_LONG_LONG)1 << ((8 * f->size) - 1)));
return PyLong_FromLongLong(x);
}
static PyObject *
lu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
{
- unsigned long long x = 0;
+ unsigned PY_LONG_LONG x = 0;
Py_ssize_t i = f->size;
const unsigned char *bytes = (const unsigned char *)p;
do {
@@ -1437,9 +1442,10 @@ static PyObject *
s_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *self;
+ allocfunc alloc_func;
assert(type != NULL);
- allocfunc alloc_func = PyType_GetSlot(type, Py_tp_alloc);
+ alloc_func = PyType_GetSlot(type, Py_tp_alloc);
assert(alloc_func != NULL);
self = alloc_func(type, 0);
@@ -1514,7 +1520,10 @@ s_traverse(PyStructObject *s, visitproc visit, void *arg)
static void
s_dealloc(PyStructObject *s)
{
- PyTypeObject *tp = Py_TYPE(s);
+ PyTypeObject *tp;
+ freefunc free_func;
+
+ tp = Py_TYPE(s);
PyObject_GC_UnTrack(s);
if (s->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)s);
@@ -1522,7 +1531,7 @@ s_dealloc(PyStructObject *s)
PyMem_Free(s->s_codes);
}
Py_XDECREF(s->s_format);
- freefunc free_func = PyType_GetSlot(Py_TYPE(s), Py_tp_free);
+ free_func = PyType_GetSlot(Py_TYPE(s), Py_tp_free);
free_func(s);
Py_DECREF(tp);
}
@@ -1902,6 +1911,7 @@ s_pack(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
char *buf;
PyStructObject *soself;
_structmodulestate *state = get_struct_state_structinst(self);
+ _PyBytesWriter writer;
/* Validate arguments. */
soself = (PyStructObject *)self;
@@ -1915,7 +1925,6 @@ s_pack(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
}
/* Allocate a new string */
- _PyBytesWriter writer;
_PyBytesWriter_Init(&writer);
buf = _PyBytesWriter_Alloc(&writer, soself->s_size);
if (buf == NULL) {
@@ -2472,14 +2481,14 @@ static PyModuleDef_Slot _structmodule_slots[] = {
static struct PyModuleDef _structmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_struct",
- .m_doc = module_doc,
- .m_size = sizeof(_structmodulestate),
- .m_methods = module_functions,
- .m_slots = _structmodule_slots,
- .m_traverse = _structmodule_traverse,
- .m_clear = _structmodule_clear,
- .m_free = _structmodule_free,
+ "_struct",
+ module_doc,
+ sizeof(_structmodulestate),
+ module_functions,
+ _structmodule_slots,
+ _structmodule_traverse,
+ _structmodule_clear,
+ _structmodule_free,
};
PyMODINIT_FUNC
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 7699b19..f05985a 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -258,18 +258,19 @@ static int
u_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
PyObject *u;
+ Py_ssize_t len;
+ wchar_t w;
if (!PyArg_Parse(v, "U;array item must be unicode character", &u)) {
return -1;
}
- Py_ssize_t len = PyUnicode_AsWideChar(u, NULL, 0);
+ len = PyUnicode_AsWideChar(u, NULL, 0);
if (len != 2) {
PyErr_SetString(PyExc_TypeError,
"array item must be unicode character");
return -1;
}
- wchar_t w;
len = PyUnicode_AsWideChar(u, &w, 1);
assert(len == 1);
@@ -445,17 +446,17 @@ LL_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
static PyObject *
q_getitem(arrayobject *ap, Py_ssize_t i)
{
- return PyLong_FromLongLong(((long long *)ap->ob_item)[i]);
+ return PyLong_FromLongLong(((PY_LONG_LONG *)ap->ob_item)[i]);
}
static int
q_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
- long long x;
+ PY_LONG_LONG x;
if (!PyArg_Parse(v, "L;array item must be integer", &x))
return -1;
if (i >= 0)
- ((long long *)ap->ob_item)[i] = x;
+ ((PY_LONG_LONG *)ap->ob_item)[i] = x;
return 0;
}
@@ -463,13 +464,13 @@ static PyObject *
QQ_getitem(arrayobject *ap, Py_ssize_t i)
{
return PyLong_FromUnsignedLongLong(
- ((unsigned long long *)ap->ob_item)[i]);
+ ((unsigned PY_LONG_LONG *)ap->ob_item)[i]);
}
static int
QQ_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
{
- unsigned long long x;
+ unsigned PY_LONG_LONG x;
int do_decref = 0; /* if nb_int was called */
if (!PyLong_Check(v)) {
@@ -480,14 +481,14 @@ QQ_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
do_decref = 1;
}
x = PyLong_AsUnsignedLongLong(v);
- if (x == (unsigned long long)-1 && PyErr_Occurred()) {
+ if (x == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) {
if (do_decref) {
Py_DECREF(v);
}
return -1;
}
if (i >= 0)
- ((unsigned long long *)ap->ob_item)[i] = x;
+ ((unsigned PY_LONG_LONG *)ap->ob_item)[i] = x;
if (do_decref) {
Py_DECREF(v);
@@ -534,7 +535,8 @@ d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
code##_compareitems(const void *lhs, const void *rhs, Py_ssize_t length) \
{ \
const type *a = lhs, *b = rhs; \
- for (Py_ssize_t i = 0; i < length; ++i) \
+ Py_ssize_t i; \
+ for (i = 0; i < length; ++i) \
if (a[i] != b[i]) \
return a[i] < b[i] ? -1 : 1; \
return 0; \
@@ -549,8 +551,8 @@ DEFINE_COMPAREITEMS(i, int)
DEFINE_COMPAREITEMS(II, unsigned int)
DEFINE_COMPAREITEMS(l, long)
DEFINE_COMPAREITEMS(LL, unsigned long)
-DEFINE_COMPAREITEMS(q, long long)
-DEFINE_COMPAREITEMS(QQ, unsigned long long)
+DEFINE_COMPAREITEMS(q, PY_LONG_LONG)
+DEFINE_COMPAREITEMS(QQ, unsigned PY_LONG_LONG)
/* Description of types.
*
@@ -567,8 +569,8 @@ static const struct arraydescr descriptors[] = {
{'I', sizeof(int), II_getitem, II_setitem, II_compareitems, "I", 1, 0},
{'l', sizeof(long), l_getitem, l_setitem, l_compareitems, "l", 1, 1},
{'L', sizeof(long), LL_getitem, LL_setitem, LL_compareitems, "L", 1, 0},
- {'q', sizeof(long long), q_getitem, q_setitem, q_compareitems, "q", 1, 1},
- {'Q', sizeof(long long), QQ_getitem, QQ_setitem, QQ_compareitems, "Q", 1, 0},
+ {'q', sizeof(PY_LONG_LONG), q_getitem, q_setitem, q_compareitems, "q", 1, 1},
+ {'Q', sizeof(PY_LONG_LONG), QQ_getitem, QQ_setitem, QQ_compareitems, "Q", 1, 0},
{'f', sizeof(float), f_getitem, f_setitem, NULL, "f", 0, 0},
{'d', sizeof(double), d_getitem, d_setitem, NULL, "d", 0, 0},
{'\0', 0, 0, 0, 0, 0, 0} /* Sentinel */
@@ -623,11 +625,11 @@ newarrayobject(PyTypeObject *type, Py_ssize_t size, const struct arraydescr *des
static PyObject *
getarrayitem(PyObject *op, Py_ssize_t i)
{
+ arrayobject *ap;
#ifndef NDEBUG
array_state *state = find_array_state_by_type(Py_TYPE(op));
assert(array_Check(op, state));
#endif
- arrayobject *ap;
ap = (arrayobject *)op;
assert(i>=0 && i<Py_SIZE(ap));
return (*ap->ob_descr->getitem)(ap, i);
@@ -693,8 +695,9 @@ array_richcompare(PyObject *v, PyObject *w, int op)
arrayobject *va, *wa;
PyObject *vi = NULL;
PyObject *wi = NULL;
- Py_ssize_t i, k;
+ Py_ssize_t i, k, vs, ws;
PyObject *res;
+ int cmp;
if (!array_Check(v, state) || !array_Check(w, state))
Py_RETURN_NOTIMPLEMENTED;
@@ -721,7 +724,6 @@ array_richcompare(PyObject *v, PyObject *w, int op)
if (result == 0)
goto compare_sizes;
- int cmp;
switch (op) {
case Py_LT: cmp = result < 0; break;
case Py_LE: cmp = result <= 0; break;
@@ -731,7 +733,7 @@ array_richcompare(PyObject *v, PyObject *w, int op)
case Py_GE: cmp = result >= 0; break;
default: return NULL; /* cannot happen */
}
- PyObject *res = cmp ? Py_True : Py_False;
+ res = cmp ? Py_True : Py_False;
Py_INCREF(res);
return res;
}
@@ -761,9 +763,8 @@ array_richcompare(PyObject *v, PyObject *w, int op)
if (k) {
/* No more items to compare -- compare sizes */
compare_sizes: ;
- Py_ssize_t vs = Py_SIZE(va);
- Py_ssize_t ws = Py_SIZE(wa);
- int cmp;
+ vs = Py_SIZE(va);
+ ws = Py_SIZE(wa);
switch (op) {
case Py_LT: cmp = vs < ws; break;
case Py_LE: cmp = vs <= ws; break;
@@ -913,22 +914,27 @@ static PyObject *
array_repeat(arrayobject *a, Py_ssize_t n)
{
array_state *state = find_array_state_by_type(Py_TYPE(a));
+ Py_ssize_t array_length;
+ Py_ssize_t size;
+ arrayobject *np;
+ Py_ssize_t oldbytes;
+ Py_ssize_t newbytes;
if (n < 0)
n = 0;
- const Py_ssize_t array_length = Py_SIZE(a);
+ array_length = Py_SIZE(a);
if ((array_length != 0) && (n > PY_SSIZE_T_MAX / array_length)) {
return PyErr_NoMemory();
}
- Py_ssize_t size = array_length * n;
- arrayobject* np = (arrayobject *) newarrayobject(state->ArrayType, size, a->ob_descr);
+ size = array_length * n;
+ np = (arrayobject *) newarrayobject(state->ArrayType, size, a->ob_descr);
if (np == NULL)
return NULL;
if (size == 0)
return (PyObject *)np;
- const Py_ssize_t oldbytes = array_length * a->ob_descr->itemsize;
- const Py_ssize_t newbytes = oldbytes * n;
+ oldbytes = array_length * a->ob_descr->itemsize;
+ newbytes = oldbytes * n;
_PyBytes_Repeat(np->ob_item, newbytes, a->ob_item, oldbytes);
return (PyObject *)np;
@@ -1069,6 +1075,7 @@ static PyObject *
array_inplace_repeat(arrayobject *self, Py_ssize_t n)
{
const Py_ssize_t array_size = Py_SIZE(self);
+ Py_ssize_t size;
if (array_size > 0 && n != 1 ) {
if (n < 0)
@@ -1077,7 +1084,7 @@ array_inplace_repeat(arrayobject *self, Py_ssize_t n)
(array_size > PY_SSIZE_T_MAX / self->ob_descr->itemsize)) {
return PyErr_NoMemory();
}
- Py_ssize_t size = array_size * self->ob_descr->itemsize;
+ size = array_size * self->ob_descr->itemsize;
if (n > 0 && size > PY_SSIZE_T_MAX / n) {
return PyErr_NoMemory();
}
@@ -1151,6 +1158,8 @@ array_array_index_impl(arrayobject *self, PyObject *v, Py_ssize_t start,
Py_ssize_t stop)
/*[clinic end generated code: output=c45e777880c99f52 input=089dff7baa7e5a7e]*/
{
+ Py_ssize_t i;
+
if (start < 0) {
start += Py_SIZE(self);
if (start < 0) {
@@ -1162,7 +1171,7 @@ array_array_index_impl(arrayobject *self, PyObject *v, Py_ssize_t start,
}
// Use Py_SIZE() for every iteration in case the array is mutated
// during PyObject_RichCompareBool()
- for (Py_ssize_t i = start; i < stop && i < Py_SIZE(self); i++) {
+ for (i = start; i < stop && i < Py_SIZE(self); i++) {
PyObject *selfi;
int cmp;
@@ -1474,6 +1483,7 @@ array_array_fromfile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f,
Py_ssize_t itemsize = self->ob_descr->itemsize;
Py_ssize_t nbytes;
int not_enough_bytes;
+ array_state *state;
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "negative count");
@@ -1485,7 +1495,7 @@ array_array_fromfile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f,
}
- array_state *state = get_array_state_by_class(cls);
+ state = get_array_state_by_class(cls);
assert(state != NULL);
nbytes = n * itemsize;
@@ -1538,12 +1548,13 @@ array_array_tofile_impl(arrayobject *self, PyTypeObject *cls, PyObject *f)
int BLOCKSIZE = 64*1024;
Py_ssize_t nblocks = (nbytes + BLOCKSIZE - 1) / BLOCKSIZE;
Py_ssize_t i;
+ array_state *state;
if (Py_SIZE(self) == 0)
goto done;
- array_state *state = get_array_state_by_class(cls);
+ state = get_array_state_by_class(cls);
assert(state != NULL);
for (i = 0; i < nblocks; i++) {
@@ -1725,6 +1736,8 @@ static PyObject *
array_array_fromunicode_impl(arrayobject *self, PyObject *ustr)
/*[clinic end generated code: output=24359f5e001a7f2b input=025db1fdade7a4ce]*/
{
+ Py_ssize_t ustr_length;
+
if (self->ob_descr->typecode != 'u') {
PyErr_SetString(PyExc_ValueError,
"fromunicode() may only be called on "
@@ -1732,11 +1745,13 @@ array_array_fromunicode_impl(arrayobject *self, PyObject *ustr)
return NULL;
}
- Py_ssize_t ustr_length = PyUnicode_AsWideChar(ustr, NULL, 0);
+ ustr_length = PyUnicode_AsWideChar(ustr, NULL, 0);
assert(ustr_length > 0);
if (ustr_length > 1) {
+ Py_ssize_t old_size;
+
ustr_length--; /* trim trailing NUL character */
- Py_ssize_t old_size = Py_SIZE(self);
+ old_size = Py_SIZE(self);
if (array_resize(self, old_size + ustr_length) == -1) {
return NULL;
}
@@ -1893,11 +1908,11 @@ typecode_to_mformat_code(char typecode)
is_signed = 0;
break;
case 'q':
- intsize = sizeof(long long);
+ intsize = sizeof(PY_LONG_LONG);
is_signed = 1;
break;
case 'Q':
- intsize = sizeof(long long);
+ intsize = sizeof(PY_LONG_LONG);
is_signed = 0;
break;
default:
@@ -2788,8 +2803,8 @@ narrow builds this is 2-bytes on wide builds this is 4-bytes.\n\
NOTE: The 'q' and 'Q' type codes are only available if the platform\n\
C compiler used to build Python supports 'long long', or, on Windows,\n\
'__int64'.\n\
-\n\
-Methods:\n\
+\n"
+"Methods:\n\
\n\
append() -- append a new item to the end of the array\n\
buffer_info() -- return information giving the current memory info\n\
@@ -2858,12 +2873,13 @@ static PyType_Slot array_slots[] = {
};
static PyType_Spec array_spec = {
- .name = "array.array",
- .basicsize = sizeof(arrayobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_SEQUENCE),
- .slots = array_slots,
+ "array.array",
+ sizeof(arrayobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_SEQUENCE),
+ array_slots,
};
/*********************** Array Iterator **************************/
@@ -2900,10 +2916,11 @@ static PyObject *
arrayiter_next(arrayiterobject *it)
{
arrayobject *ao;
+ array_state *state;
assert(it != NULL);
#ifndef NDEBUG
- array_state *state = find_array_state_by_type(Py_TYPE(it));
+ state = find_array_state_by_type(Py_TYPE(it));
assert(PyObject_TypeCheck(it, state->ArrayIterType));
#endif
ao = it->ao;
@@ -2953,10 +2970,12 @@ static PyObject *
array_arrayiterator___reduce___impl(arrayiterobject *self, PyTypeObject *cls)
/*[clinic end generated code: output=4b032417a2c8f5e6 input=ac64e65a87ad452e]*/
{
+ array_state *state;
+ PyObject *func;
- array_state *state = get_array_state_by_class(cls);
+ state = get_array_state_by_class(cls);
assert(state != NULL);
- PyObject *func = _PyEval_GetBuiltin(state->str_iter);
+ func = _PyEval_GetBuiltin(state->str_iter);
if (self->ao == NULL) {
return Py_BuildValue("N(())", func);
}
@@ -3004,11 +3023,12 @@ static PyType_Slot arrayiter_slots[] = {
};
static PyType_Spec arrayiter_spec = {
- .name = "array.arrayiterator",
- .basicsize = sizeof(arrayiterobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = arrayiter_slots,
+ "array.arrayiterator",
+ sizeof(arrayiterobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
+ arrayiter_slots,
};
@@ -3072,6 +3092,9 @@ array_modexec(PyObject *m)
array_state *state = get_array_state(m);
char buffer[Py_ARRAY_LENGTH(descriptors)], *p;
PyObject *typecodes;
+ PyObject *abc_mod;
+ PyObject *mutablesequence;
+ PyObject *res;
const struct arraydescr *descr;
/* Add interned strings */
@@ -3091,18 +3114,18 @@ array_modexec(PyObject *m)
return -1;
}
- PyObject *abc_mod = PyImport_ImportModule("collections.abc");
+ abc_mod = PyImport_ImportModule("collections.abc");
if (!abc_mod) {
Py_DECREF((PyObject *)state->ArrayType);
return -1;
}
- PyObject *mutablesequence = PyObject_GetAttrString(abc_mod, "MutableSequence");
+ mutablesequence = PyObject_GetAttrString(abc_mod, "MutableSequence");
Py_DECREF(abc_mod);
if (!mutablesequence) {
Py_DECREF((PyObject *)state->ArrayType);
return -1;
}
- PyObject *res = PyObject_CallMethod(mutablesequence, "register", "O",
+ res = PyObject_CallMethod(mutablesequence, "register", "O",
(PyObject *)state->ArrayType);
Py_DECREF(mutablesequence);
if (!res) {
@@ -3135,15 +3158,15 @@ static PyModuleDef_Slot arrayslots[] = {
static struct PyModuleDef arraymodule = {
- .m_base = PyModuleDef_HEAD_INIT,
- .m_name = "array",
- .m_size = sizeof(array_state),
- .m_doc = module_doc,
- .m_methods = a_methods,
- .m_slots = arrayslots,
- .m_traverse = array_traverse,
- .m_clear = array_clear,
- .m_free = array_free,
+ PyModuleDef_HEAD_INIT,
+ "array",
+ module_doc,
+ sizeof(array_state),
+ a_methods,
+ arrayslots,
+ array_traverse,
+ array_clear,
+ array_free,
};
diff --git a/Modules/atexitmodule.c b/Modules/atexitmodule.c
index a1c511e..08a5a53 100644
--- a/Modules/atexitmodule.c
+++ b/Modules/atexitmodule.c
@@ -40,7 +40,8 @@ static void
atexit_cleanup(struct atexit_state *state)
{
atexit_callback *cb;
- for (int i = 0; i < state->ncallbacks; i++) {
+ int i;
+ for (i = 0; i < state->ncallbacks; i++) {
cb = state->callbacks[i];
if (cb == NULL)
continue;
@@ -81,21 +82,24 @@ _PyAtExit_Fini(PyInterpreterState *interp)
static void
atexit_callfuncs(struct atexit_state *state)
{
+ int i;
+ PyObject *the_func;
+ PyObject *res;
assert(!PyErr_Occurred());
if (state->ncallbacks == 0) {
return;
}
- for (int i = state->ncallbacks - 1; i >= 0; i--) {
+ for (i = state->ncallbacks - 1; i >= 0; i--) {
atexit_callback *cb = state->callbacks[i];
if (cb == NULL) {
continue;
}
// bpo-46025: Increment the refcount of cb->func as the call itself may unregister it
- PyObject* the_func = Py_NewRef(cb->func);
- PyObject *res = PyObject_Call(cb->func, cb->args, cb->kwargs);
+ the_func = Py_NewRef(cb->func);
+ res = PyObject_Call(cb->func, cb->args, cb->kwargs);
if (res == NULL) {
_PyErr_WriteUnraisableMsg("in atexit callback", the_func);
}
@@ -137,24 +141,29 @@ Register a function to be executed upon normal program termination\n\
static PyObject *
atexit_register(PyObject *module, PyObject *args, PyObject *kwargs)
{
+ PyObject *func;
+ struct atexit_state *state;
+ atexit_callback **r;
+ size_t size;
+ atexit_callback *callback;
+
if (PyTuple_GET_SIZE(args) == 0) {
PyErr_SetString(PyExc_TypeError,
"register() takes at least 1 argument (0 given)");
return NULL;
}
- PyObject *func = PyTuple_GET_ITEM(args, 0);
+ func = PyTuple_GET_ITEM(args, 0);
if (!PyCallable_Check(func)) {
PyErr_SetString(PyExc_TypeError,
"the first argument must be callable");
return NULL;
}
- struct atexit_state *state = get_atexit_state();
+ state = get_atexit_state();
if (state->ncallbacks >= state->callback_len) {
- atexit_callback **r;
state->callback_len += 16;
- size_t size = sizeof(atexit_callback*) * (size_t)state->callback_len;
+ size = sizeof(atexit_callback*) * (size_t)state->callback_len;
r = (atexit_callback**)PyMem_Realloc(state->callbacks, size);
if (r == NULL) {
return PyErr_NoMemory();
@@ -162,7 +171,7 @@ atexit_register(PyObject *module, PyObject *args, PyObject *kwargs)
state->callbacks = r;
}
- atexit_callback *callback = PyMem_Malloc(sizeof(atexit_callback));
+ callback = PyMem_Malloc(sizeof(atexit_callback));
if (callback == NULL) {
return PyErr_NoMemory();
}
@@ -231,14 +240,18 @@ static PyObject *
atexit_unregister(PyObject *module, PyObject *func)
{
struct atexit_state *state = get_atexit_state();
- for (int i = 0; i < state->ncallbacks; i++)
+ int i;
+ atexit_callback *cb;
+ int eq;
+
+ for (i = 0; i < state->ncallbacks; i++)
{
- atexit_callback *cb = state->callbacks[i];
+ cb = state->callbacks[i];
if (cb == NULL) {
continue;
}
- int eq = PyObject_RichCompareBool(cb->func, func, Py_EQ);
+ eq = PyObject_RichCompareBool(cb->func, func, Py_EQ);
if (eq < 0) {
return NULL;
}
@@ -277,10 +290,10 @@ Two public functions, register and unregister, are defined.\n\
static struct PyModuleDef atexitmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "atexit",
- .m_doc = atexit__doc__,
- .m_size = 0,
- .m_methods = atexit_methods,
+ "atexit",
+ atexit__doc__,
+ 0,
+ atexit_methods,
};
PyMODINIT_FUNC
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 88bb4c1..73bee0d 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1372,7 +1372,7 @@ audioop_ratecv_impl(PyObject *module, Py_buffer *fragment, int width,
weightA /= d;
weightB /= d;
- if ((size_t)nchannels > SIZE_MAX/sizeof(int)) {
+ if ((size_t)nchannels > ((size_t)-1)/sizeof(int)) {
PyErr_SetString(PyExc_MemoryError,
"not enough memory for output buffer");
return NULL;
diff --git a/Modules/binascii.c b/Modules/binascii.c
index de3c2d8..d1dfc0d 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -388,21 +388,34 @@ static PyObject *
binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
/*[clinic end generated code: output=5409557788d4f975 input=3a30c4e3528317c6]*/
{
+ const unsigned char *ascii_data;
+ size_t ascii_len;
+ binascii_state *state;
+ char padding_started;
+ Py_ssize_t bin_len;
+ _PyBytesWriter writer;
+ unsigned char *bin_data;
+ unsigned char *bin_data_start;
+ int quad_pos;
+ unsigned char leftchar;
+ int pads;
+ size_t i;
+ unsigned char this_ch;
+
assert(data->len >= 0);
- const unsigned char *ascii_data = data->buf;
- size_t ascii_len = data->len;
- binascii_state *state = NULL;
- char padding_started = 0;
+ ascii_data = data->buf;
+ ascii_len = data->len;
+ state = NULL;
+ padding_started = 0;
/* Allocate the buffer */
- Py_ssize_t bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
- _PyBytesWriter writer;
+ bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
_PyBytesWriter_Init(&writer);
- unsigned char *bin_data = _PyBytesWriter_Alloc(&writer, bin_len);
+ bin_data = _PyBytesWriter_Alloc(&writer, bin_len);
if (bin_data == NULL)
return NULL;
- unsigned char *bin_data_start = bin_data;
+ bin_data_start = bin_data;
if (strict_mode && ascii_len > 0 && ascii_data[0] == '=') {
state = get_binascii_state(module);
@@ -412,11 +425,11 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
goto error_end;
}
- int quad_pos = 0;
- unsigned char leftchar = 0;
- int pads = 0;
- for (size_t i = 0; i < ascii_len; i++) {
- unsigned char this_ch = ascii_data[i];
+ quad_pos = 0;
+ leftchar = 0;
+ pads = 0;
+ for (i = 0; i < ascii_len; i++) {
+ this_ch = ascii_data[i];
/* Check for pad sequences and ignore
** the invalid ones.
diff --git a/Modules/clinic/_codecsmodule.c.h b/Modules/clinic/_codecsmodule.c.h
index 29e9d5e..7bc9c5c 100644
--- a/Modules/clinic/_codecsmodule.c.h
+++ b/Modules/clinic/_codecsmodule.c.h
@@ -43,12 +43,12 @@ _codecs_lookup(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
const char *encoding;
+ Py_ssize_t encoding_length;
if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("lookup", "argument", "str", arg);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(arg, &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -93,6 +93,8 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
PyObject *obj;
const char *encoding = NULL;
const char *errors = NULL;
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
if (!args) {
@@ -107,7 +109,6 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
_PyArg_BadArgument("encode", "argument 'encoding'", "str", args[1]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -124,7 +125,6 @@ _codecs_encode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
_PyArg_BadArgument("encode", "argument 'errors'", "str", args[2]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
if (errors == NULL) {
goto exit;
@@ -170,6 +170,8 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
PyObject *obj;
const char *encoding = NULL;
const char *errors = NULL;
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
if (!args) {
@@ -184,7 +186,6 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
_PyArg_BadArgument("decode", "argument 'encoding'", "str", args[1]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(args[1], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -201,7 +202,6 @@ _codecs_decode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
_PyArg_BadArgument("decode", "argument 'errors'", "str", args[2]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[2], &errors_length);
if (errors == NULL) {
goto exit;
@@ -2730,6 +2730,7 @@ _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs
PyObject *return_value = NULL;
const char *errors;
PyObject *handler;
+ Py_ssize_t errors_length;
if (!_PyArg_CheckPositional("register_error", nargs, 2, 2)) {
goto exit;
@@ -2738,7 +2739,6 @@ _codecs_register_error(PyObject *module, PyObject *const *args, Py_ssize_t nargs
_PyArg_BadArgument("register_error", "argument 1", "str", args[0]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[0], &errors_length);
if (errors == NULL) {
goto exit;
@@ -2774,12 +2774,12 @@ _codecs_lookup_error(PyObject *module, PyObject *arg)
{
PyObject *return_value = NULL;
const char *name;
+ Py_ssize_t name_length;
if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("lookup_error", "argument", "str", arg);
goto exit;
}
- Py_ssize_t name_length;
name = PyUnicode_AsUTF8AndSize(arg, &name_length);
if (name == NULL) {
goto exit;
diff --git a/Modules/clinic/_pickle.c.h b/Modules/clinic/_pickle.c.h
index 5dc62fe..7f4e83f 100644
--- a/Modules/clinic/_pickle.c.h
+++ b/Modules/clinic/_pickle.c.h
@@ -336,6 +336,8 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
int fix_imports = 1;
const char *encoding = "ASCII";
const char *errors = "strict";
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
PyObject *buffers = NULL;
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
@@ -360,7 +362,6 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -378,7 +379,6 @@ _pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(fastargs[3], &errors_length);
if (errors == NULL) {
goto exit;
@@ -671,6 +671,8 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
int fix_imports = 1;
const char *encoding = "ASCII";
const char *errors = "strict";
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
PyObject *buffers = NULL;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
@@ -695,7 +697,6 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
_PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -713,7 +714,6 @@ _pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
_PyArg_BadArgument("load", "argument 'errors'", "str", args[3]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
if (errors == NULL) {
goto exit;
@@ -774,6 +774,8 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
int fix_imports = 1;
const char *encoding = "ASCII";
const char *errors = "strict";
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
PyObject *buffers = NULL;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
@@ -798,7 +800,6 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
_PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -816,7 +817,6 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
_PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
if (errors == NULL) {
goto exit;
diff --git a/Modules/cmathmodule.c b/Modules/cmathmodule.c
index 7fffb31..51f5782 100644
--- a/Modules/cmathmodule.c
+++ b/Modules/cmathmodule.c
@@ -1414,11 +1414,11 @@ static PyModuleDef_Slot cmath_slots[] = {
static struct PyModuleDef cmathmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "cmath",
- .m_doc = module_doc,
- .m_size = 0,
- .m_methods = cmath_methods,
- .m_slots = cmath_slots
+ "cmath",
+ module_doc,
+ 0,
+ cmath_methods,
+ cmath_slots
};
PyMODINIT_FUNC
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index a63ac72..9a065af 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -49,18 +49,22 @@ static PyMethodDef errno_methods[] = {
static int
_add_errcode(PyObject *module_dict, PyObject *error_dict, const char *name_str, int code_int)
{
- PyObject *name = PyUnicode_FromString(name_str);
+ PyObject *name;
+ PyObject *code;
+ int ret;
+
+ name = PyUnicode_FromString(name_str);
if (!name) {
return -1;
}
- PyObject *code = PyLong_FromLong(code_int);
+ code = PyLong_FromLong(code_int);
if (!code) {
Py_DECREF(name);
return -1;
}
- int ret = -1;
+ ret = -1;
/* insert in modules dict */
if (PyDict_SetItem(module_dict, name, code) < 0) {
goto end;
@@ -79,11 +83,14 @@ _add_errcode(PyObject *module_dict, PyObject *error_dict, const char *name_str,
static int
errno_exec(PyObject *module)
{
- PyObject *module_dict = PyModule_GetDict(module); // Borrowed ref.
+ PyObject *module_dict;
+ PyObject *error_dict;
+
+ module_dict = PyModule_GetDict(module); // Borrowed ref.
if (module_dict == NULL) {
return -1;
}
- PyObject *error_dict = PyDict_New();
+ error_dict = PyDict_New();
if (error_dict == NULL) {
return -1;
}
@@ -960,11 +967,14 @@ e.g. os.strerror(2) could return 'No such file or directory'.");
static struct PyModuleDef errnomodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "errno",
- .m_doc = errno__doc__,
- .m_size = 0,
- .m_methods = errno_methods,
- .m_slots = errno_slots,
+ "errno",
+ errno__doc__,
+ 0,
+ errno_methods,
+ errno_slots,
+ NULL,
+ NULL,
+ NULL
};
PyMODINIT_FUNC
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index 520b7b6..67d9fc1 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -231,6 +231,7 @@ faulthandler_dump_traceback(int fd, int all_threads,
PyInterpreterState *interp)
{
static volatile int reentrant = 0;
+ PyThreadState *tstate;
if (reentrant)
return;
@@ -245,7 +246,7 @@ faulthandler_dump_traceback(int fd, int all_threads,
fault if the thread released the GIL, and so this function cannot be
used. Read the thread specific storage (TSS) instead: call
PyGILState_GetThisThreadState(). */
- PyThreadState *tstate = PyGILState_GetThisThreadState();
+ tstate = PyGILState_GetThisThreadState();
if (all_threads) {
(void)_Py_DumpTracebackThreads(fd, NULL, tstate);
@@ -406,8 +407,13 @@ static LONG WINAPI
faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
{
const int fd = fatal_error.fd;
- DWORD code = exc_info->ExceptionRecord->ExceptionCode;
- DWORD flags = exc_info->ExceptionRecord->ExceptionFlags;
+ DWORD code;
+ DWORD flags;
+ size_t i;
+ fault_handler_t *handler;
+
+ code = exc_info->ExceptionRecord->ExceptionCode;
+ flags = exc_info->ExceptionRecord->ExceptionFlags;
if (faulthandler_ignore_exception(code)) {
/* ignore the exception: call the next exception handler */
@@ -433,8 +439,8 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
if (code == EXCEPTION_ACCESS_VIOLATION) {
/* disable signal handler for SIGSEGV */
- for (size_t i=0; i < faulthandler_nsignals; i++) {
- fault_handler_t *handler = &faulthandler_handlers[i];
+ for (i = 0; i < faulthandler_nsignals; i++) {
+ handler = &faulthandler_handlers[i];
if (handler->signum == SIGSEGV) {
faulthandler_disable_fatal_handler(handler);
break;
@@ -455,6 +461,8 @@ faulthandler_exc_handler(struct _EXCEPTION_POINTERS *exc_info)
static int
faulthandler_allocate_stack(void)
{
+ int err;
+
if (stack.ss_sp != NULL) {
return 0;
}
@@ -466,7 +474,7 @@ faulthandler_allocate_stack(void)
return -1;
}
- int err = sigaltstack(&stack, &old_stack);
+ err = sigaltstack(&stack, &old_stack);
if (err) {
PyErr_SetFromErrno(PyExc_OSError);
/* Release the stack to retry sigaltstack() next time */
@@ -484,6 +492,10 @@ faulthandler_allocate_stack(void)
static int
faulthandler_enable(void)
{
+ size_t i;
+ fault_handler_t *handler;
+ int err;
+
if (fatal_error.enabled) {
return 0;
}
@@ -495,10 +507,7 @@ faulthandler_enable(void)
}
#endif
- for (size_t i=0; i < faulthandler_nsignals; i++) {
- fault_handler_t *handler;
- int err;
-
+ for (i = 0; i < faulthandler_nsignals; i++) {
handler = &faulthandler_handlers[i];
assert(!handler->enabled);
#ifdef HAVE_SIGACTION
@@ -572,10 +581,12 @@ faulthandler_py_enable(PyObject *self, PyObject *args, PyObject *kwargs)
static void
faulthandler_disable(void)
{
+ size_t i;
+ fault_handler_t *handler;
+
if (fatal_error.enabled) {
fatal_error.enabled = 0;
- for (size_t i=0; i < faulthandler_nsignals; i++) {
- fault_handler_t *handler;
+ for (i = 0; i < faulthandler_nsignals; i++) {
handler = &faulthandler_handlers[i];
faulthandler_disable_fatal_handler(handler);
}
@@ -1027,8 +1038,10 @@ faulthandler_suppress_crash_report(void)
#ifdef _MSC_VER
/* Visual Studio: configure abort() to not display an error message nor
open a popup asking to report the fault. */
+#if defined(_WRITE_ABORT_MSG) && defined(_CALL_REPORTFAULT)
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif
+#endif
}
static PyObject* _Py_NO_SANITIZE_UNDEFINED
@@ -1087,7 +1100,7 @@ faulthandler_sigsegv(PyObject *self, PyObject *args)
static void _Py_NO_RETURN
faulthandler_fatal_error_thread(void *plock)
{
- Py_FatalError("in new thread");
+ _Py_FatalErrorFunc("faulthandler_fatal_error_thread", "in new thread");
}
static PyObject *
@@ -1123,11 +1136,16 @@ faulthandler_fatal_error_c_thread(PyObject *self, PyObject *args)
static PyObject* _Py_NO_SANITIZE_UNDEFINED
faulthandler_sigfpe(PyObject *self, PyObject *args)
{
+ volatile int x;
+ volatile int y;
+ volatile int z;
+
faulthandler_suppress_crash_report();
/* Do an integer division by zero: raise a SIGFPE on Intel CPU, but not on
PowerPC. Use volatile to disable compile-time optimizations. */
- volatile int x = 1, y = 0, z;
+ x = 1;
+ y = 0;
z = x / y;
/* If the division by zero didn't raise a SIGFPE (e.g. on PowerPC),
@@ -1332,11 +1350,14 @@ static PyModuleDef_Slot faulthandler_slots[] = {
static struct PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
- .m_name = "faulthandler",
- .m_doc = module_doc,
- .m_methods = module_methods,
- .m_traverse = faulthandler_traverse,
- .m_slots = faulthandler_slots
+ "faulthandler",
+ module_doc,
+ -1,
+ module_methods,
+ faulthandler_slots,
+ faulthandler_traverse,
+ NULL,
+ NULL
};
PyMODINIT_FUNC
@@ -1348,12 +1369,15 @@ PyInit_faulthandler(void)
static int
faulthandler_init_enable(void)
{
- PyObject *module = PyImport_ImportModule("faulthandler");
+ PyObject *module;
+ PyObject *res;
+
+ module = PyImport_ImportModule("faulthandler");
if (module == NULL) {
return -1;
}
- PyObject *res = PyObject_CallMethodNoArgs(module, &_Py_ID(enable));
+ res = PyObject_CallMethodNoArgs(module, &_Py_ID(enable));
Py_DECREF(module);
if (res == NULL) {
return -1;
diff --git a/Modules/getpath.c b/Modules/getpath.c
index 61d6540..e7489ee 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -12,6 +12,9 @@
#ifdef MS_WINDOWS
# include <windows.h> // GetFullPathNameW(), MAX_PATH
# include <pathcch.h>
+# if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(INVALID_FILE_ATTRIBUTES)
+# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+# endif
#endif
#ifdef __APPLE__
@@ -60,10 +63,10 @@ getpath_abspath(PyObject *Py_UNUSED(self), PyObject *args)
PyObject *r = NULL;
PyObject *pathobj;
wchar_t *path;
+ Py_ssize_t len;
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
return NULL;
}
- Py_ssize_t len;
path = PyUnicode_AsWideCharString(pathobj, &len);
if (path) {
wchar_t *abs;
@@ -83,11 +86,13 @@ static PyObject *
getpath_basename(PyObject *Py_UNUSED(self), PyObject *args)
{
PyObject *path;
+ Py_ssize_t end;
+ Py_ssize_t pos;
if (!PyArg_ParseTuple(args, "U", &path)) {
return NULL;
}
- Py_ssize_t end = PyUnicode_GET_LENGTH(path);
- Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
+ end = PyUnicode_GET_LENGTH(path);
+ pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
if (pos < 0) {
return Py_NewRef(path);
}
@@ -99,11 +104,13 @@ static PyObject *
getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
{
PyObject *path;
+ Py_ssize_t end;
+ Py_ssize_t pos;
if (!PyArg_ParseTuple(args, "U", &path)) {
return NULL;
}
- Py_ssize_t end = PyUnicode_GET_LENGTH(path);
- Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
+ end = PyUnicode_GET_LENGTH(path);
+ pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
if (pos < 0) {
return PyUnicode_FromStringAndSize(NULL, 0);
}
@@ -138,10 +145,10 @@ getpath_hassuffix(PyObject *Py_UNUSED(self), PyObject *args)
PyObject *suffixobj;
const wchar_t *path;
const wchar_t *suffix;
+ Py_ssize_t len, suffixLen;
if (!PyArg_ParseTuple(args, "UU", &pathobj, &suffixobj)) {
return NULL;
}
- Py_ssize_t len, suffixLen;
path = PyUnicode_AsWideCharString(pathobj, &len);
if (path) {
suffix = PyUnicode_AsWideCharString(suffixobj, &suffixLen);
@@ -172,17 +179,21 @@ getpath_isdir(PyObject *Py_UNUSED(self), PyObject *args)
PyObject *r = NULL;
PyObject *pathobj;
const wchar_t *path;
+#ifdef MS_WINDOWS
+ DWORD attr;
+#else
+ struct stat st;
+#endif
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
return NULL;
}
path = PyUnicode_AsWideCharString(pathobj, NULL);
if (path) {
#ifdef MS_WINDOWS
- DWORD attr = GetFileAttributesW(path);
+ attr = GetFileAttributesW(path);
r = (attr != INVALID_FILE_ATTRIBUTES) &&
(attr & FILE_ATTRIBUTE_DIRECTORY) ? Py_True : Py_False;
#else
- struct stat st;
r = (_Py_wstat(path, &st) == 0) && S_ISDIR(st.st_mode) ? Py_True : Py_False;
#endif
PyMem_Free((void *)path);
@@ -198,17 +209,21 @@ getpath_isfile(PyObject *Py_UNUSED(self), PyObject *args)
PyObject *r = NULL;
PyObject *pathobj;
const wchar_t *path;
+#ifdef MS_WINDOWS
+ DWORD attr;
+#else
+ struct stat st;
+#endif
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
return NULL;
}
path = PyUnicode_AsWideCharString(pathobj, NULL);
if (path) {
#ifdef MS_WINDOWS
- DWORD attr = GetFileAttributesW(path);
+ attr = GetFileAttributesW(path);
r = (attr != INVALID_FILE_ATTRIBUTES) &&
!(attr & FILE_ATTRIBUTE_DIRECTORY) ? Py_True : Py_False;
#else
- struct stat st;
r = (_Py_wstat(path, &st) == 0) && S_ISREG(st.st_mode) ? Py_True : Py_False;
#endif
PyMem_Free((void *)path);
@@ -225,21 +240,25 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
PyObject *pathobj;
const wchar_t *path;
Py_ssize_t cchPath;
+#ifdef MS_WINDOWS
+ const wchar_t *ext;
+ DWORD attr;
+#else
+ struct stat st;
+#endif
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
return NULL;
}
path = PyUnicode_AsWideCharString(pathobj, &cchPath);
if (path) {
#ifdef MS_WINDOWS
- const wchar_t *ext;
- DWORD attr = GetFileAttributesW(path);
+ attr = GetFileAttributesW(path);
r = (attr != INVALID_FILE_ATTRIBUTES) &&
!(attr & FILE_ATTRIBUTE_DIRECTORY) &&
SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) &&
(CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL)
? Py_True : Py_False;
#else
- struct stat st;
r = (_Py_wstat(path, &st) == 0) &&
S_ISREG(st.st_mode) &&
(st.st_mode & 0111)
@@ -255,27 +274,35 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
static PyObject *
getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
{
+ Py_ssize_t n;
+ wchar_t **parts;
+ Py_ssize_t cchFinal;
+ Py_ssize_t first;
+ Py_ssize_t i;
+ PyObject *s;
+ Py_ssize_t cch;
+ wchar_t *final;
+ PyObject *r;
if (!PyTuple_Check(args)) {
PyErr_SetString(PyExc_TypeError, "requires tuple of arguments");
return NULL;
}
- Py_ssize_t n = PyTuple_GET_SIZE(args);
+ n = PyTuple_GET_SIZE(args);
if (n == 0) {
return PyUnicode_FromStringAndSize(NULL, 0);
}
/* Convert all parts to wchar and accumulate max final length */
- wchar_t **parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
+ parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
if (parts == NULL) {
PyErr_NoMemory();
return NULL;
}
memset(parts, 0, n * sizeof(wchar_t *));
- Py_ssize_t cchFinal = 0;
- Py_ssize_t first = 0;
+ cchFinal = 0;
+ first = 0;
- for (Py_ssize_t i = 0; i < n; ++i) {
- PyObject *s = PyTuple_GET_ITEM(args, i);
- Py_ssize_t cch;
+ for (i = 0; i < n; ++i) {
+ s = PyTuple_GET_ITEM(args, i);
if (s == Py_None) {
cch = 0;
} else if (PyUnicode_Check(s)) {
@@ -295,9 +322,9 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
cchFinal += cch + 1;
}
- wchar_t *final = cchFinal > 0 ? (wchar_t *)PyMem_Malloc(cchFinal * sizeof(wchar_t)) : NULL;
+ final = cchFinal > 0 ? (wchar_t *)PyMem_Malloc(cchFinal * sizeof(wchar_t)) : NULL;
if (!final) {
- for (Py_ssize_t i = 0; i < n; ++i) {
+ for (i = 0; i < n; ++i) {
PyMem_Free(parts[i]);
}
PyMem_Free(parts);
@@ -310,7 +337,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
final[0] = '\0';
/* Now join all the paths. The final result should be shorter than the buffer */
- for (Py_ssize_t i = 0; i < n; ++i) {
+ for (i = 0; i < n; ++i) {
if (!parts[i]) {
continue;
}
@@ -331,7 +358,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
PyErr_SetString(PyExc_SystemError, "failed to join paths");
return NULL;
}
- PyObject *r = PyUnicode_FromWideChar(_Py_normpath(final, -1), -1);
+ r = PyUnicode_FromWideChar(_Py_normpath(final, -1), -1);
PyMem_Free(final);
return r;
}
@@ -343,6 +370,16 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
PyObject *r = NULL;
PyObject *pathobj;
const wchar_t *path;
+ FILE *fp;
+ const size_t MAX_FILE = 32 * 1024;
+ char *buffer;
+ size_t cb;
+ size_t len;
+ wchar_t *wbuffer;
+ wchar_t *p1;
+ wchar_t *p2;
+ Py_ssize_t line_len;
+ PyObject *u;
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
return NULL;
}
@@ -350,7 +387,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
if (!path) {
return NULL;
}
- FILE *fp = _Py_wfopen(path, L"rb");
+ fp = _Py_wfopen(path, L"rb");
if (!fp) {
PyErr_SetFromErrno(PyExc_OSError);
PyMem_Free((void *)path);
@@ -363,15 +400,14 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
fclose(fp);
return NULL;
}
- const size_t MAX_FILE = 32 * 1024;
- char *buffer = (char *)PyMem_Malloc(MAX_FILE);
+ buffer = (char *)PyMem_Malloc(MAX_FILE);
if (!buffer) {
Py_DECREF(r);
fclose(fp);
return NULL;
}
- size_t cb = fread(buffer, 1, MAX_FILE, fp);
+ cb = fread(buffer, 1, MAX_FILE, fp);
fclose(fp);
if (!cb) {
return r;
@@ -384,8 +420,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
}
buffer[cb] = '\0';
- size_t len;
- wchar_t *wbuffer = _Py_DecodeUTF8_surrogateescape(buffer, cb, &len);
+ wbuffer = _Py_DecodeUTF8_surrogateescape(buffer, cb, &len);
PyMem_Free((void *)buffer);
if (!wbuffer) {
Py_DECREF(r);
@@ -393,14 +428,14 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
return NULL;
}
- wchar_t *p1 = wbuffer;
- wchar_t *p2 = p1;
+ p1 = wbuffer;
+ p2 = p1;
while ((p2 = wcschr(p1, L'\n')) != NULL) {
- Py_ssize_t cb = p2 - p1;
- while (cb >= 0 && (p1[cb] == L'\n' || p1[cb] == L'\r')) {
- --cb;
+ line_len = p2 - p1;
+ while (line_len >= 0 && (p1[line_len] == L'\n' || p1[line_len] == L'\r')) {
+ --line_len;
}
- PyObject *u = PyUnicode_FromWideChar(p1, cb >= 0 ? cb + 1 : 0);
+ u = PyUnicode_FromWideChar(p1, line_len >= 0 ? line_len + 1 : 0);
if (!u || PyList_Append(r, u) < 0) {
Py_XDECREF(u);
Py_CLEAR(r);
@@ -410,7 +445,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
p1 = p2 + 1;
}
if (r && p1 && *p1) {
- PyObject *u = PyUnicode_FromWideChar(p1, -1);
+ u = PyUnicode_FromWideChar(p1, -1);
if (!u || PyList_Append(r, u) < 0) {
Py_CLEAR(r);
}
@@ -562,8 +597,11 @@ static PyMethodDef getpath_nowarn_method = {"warn", getpath_nowarn, METH_VARARGS
static int
funcs_to_dict(PyObject *dict, int warnings)
{
- for (PyMethodDef *m = getpath_methods; m->ml_name; ++m) {
- PyObject *f = PyCFunction_NewEx(m, NULL, NULL);
+ PyMethodDef *m;
+ PyMethodDef *m2;
+ PyObject *f;
+ for (m = getpath_methods; m->ml_name; ++m) {
+ f = PyCFunction_NewEx(m, NULL, NULL);
if (!f) {
return 0;
}
@@ -573,8 +611,8 @@ funcs_to_dict(PyObject *dict, int warnings)
}
Py_DECREF(f);
}
- PyMethodDef *m2 = warnings ? &getpath_warn_method : &getpath_nowarn_method;
- PyObject *f = PyCFunction_NewEx(m2, NULL, NULL);
+ m2 = warnings ? &getpath_warn_method : &getpath_nowarn_method;
+ f = PyCFunction_NewEx(m2, NULL, NULL);
if (!f) {
return 0;
}
@@ -614,9 +652,10 @@ decode_to_dict(PyObject *dict, const char *key, const char *s)
{
PyObject *u = NULL;
int r;
+ size_t len;
+ const wchar_t *w;
if (s && s[0]) {
- size_t len;
- const wchar_t *w = Py_DecodeLocale(s, &len);
+ w = Py_DecodeLocale(s, &len);
if (w) {
u = PyUnicode_FromWideChar(w, len);
PyMem_RawFree((void *)w);
@@ -639,18 +678,27 @@ env_to_dict(PyObject *dict, const char *key, int and_clear)
{
PyObject *u = NULL;
int r = 0;
+#ifdef MS_WINDOWS
+ wchar_t wkey[64];
+ wchar_t *wp;
+ const char *p;
+ const wchar_t *v;
+#else
+ const char *v;
+ size_t len;
+ const wchar_t *w;
+#endif
assert(strncmp(key, "ENV_", 4) == 0);
assert(strlen(key) < 64);
#ifdef MS_WINDOWS
- wchar_t wkey[64];
// Quick convert to wchar_t, since we know key is ASCII
- wchar_t *wp = wkey;
- for (const char *p = &key[4]; *p; ++p) {
+ wp = wkey;
+ for (p = &key[4]; *p; ++p) {
assert(*p < 128);
*wp++ = *p;
}
*wp = L'\0';
- const wchar_t *v = _wgetenv(wkey);
+ v = _wgetenv(wkey);
if (v) {
u = PyUnicode_FromWideChar(v, -1);
if (!u) {
@@ -658,10 +706,9 @@ env_to_dict(PyObject *dict, const char *key, int and_clear)
}
}
#else
- const char *v = getenv(&key[4]);
+ v = getenv(&key[4]);
if (v) {
- size_t len;
- const wchar_t *w = Py_DecodeLocale(v, &len);
+ w = Py_DecodeLocale(v, &len);
if (w) {
u = PyUnicode_FromWideChar(w, len);
if (!u) {
@@ -709,7 +756,9 @@ static int
winmodule_to_dict(PyObject *dict, const char *key, HMODULE mod)
{
wchar_t *buffer = NULL;
- for (DWORD cch = 256; buffer == NULL && cch < (1024 * 1024); cch *= 2) {
+ DWORD cch;
+ int r;
+ for (cch = 256; buffer == NULL && cch < (1024 * 1024); cch *= 2) {
buffer = (wchar_t*)PyMem_RawMalloc(cch * sizeof(wchar_t));
if (buffer) {
if (GetModuleFileNameW(mod, buffer, cch) == cch) {
@@ -718,7 +767,7 @@ winmodule_to_dict(PyObject *dict, const char *key, HMODULE mod)
}
}
}
- int r = wchar_to_dict(dict, key, buffer);
+ r = wchar_to_dict(dict, key, buffer);
PyMem_RawFree(buffer);
return r;
}
@@ -826,6 +875,13 @@ PyStatus
_PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
{
PyStatus status = _PyPathConfig_ReadGlobal(config);
+ PyObject *configDict;
+ PyObject *dict;
+ PyObject *co;
+#ifdef MS_WINDOWS
+ PyObject *winreg;
+#endif
+ PyObject *r;
if (_PyStatus_EXCEPTION(status) || !compute_path_config) {
return status;
@@ -835,13 +891,13 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
return PyStatus_Error("cannot calculate path configuration without GIL");
}
- PyObject *configDict = _PyConfig_AsDict(config);
+ configDict = _PyConfig_AsDict(config);
if (!configDict) {
PyErr_Clear();
return PyStatus_NoMemory();
}
- PyObject *dict = PyDict_New();
+ dict = PyDict_New();
if (!dict) {
PyErr_Clear();
Py_DECREF(configDict);
@@ -857,7 +913,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
/* reference now held by dict */
Py_DECREF(configDict);
- PyObject *co = _Py_Get_Getpath_CodeObject();
+ co = _Py_Get_Getpath_CodeObject();
if (!co || !PyCode_Check(co)) {
PyErr_Clear();
Py_XDECREF(co);
@@ -866,7 +922,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
}
#ifdef MS_WINDOWS
- PyObject *winreg = PyImport_ImportModule("winreg");
+ winreg = PyImport_ImportModule("winreg");
if (!winreg || PyDict_SetItemString(dict, "winreg", winreg) < 0) {
PyErr_Clear();
Py_XDECREF(winreg);
@@ -924,7 +980,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
return PyStatus_Error("error evaluating initial values");
}
- PyObject *r = PyEval_EvalCode(co, dict, dict);
+ r = PyEval_EvalCode(co, dict, dict);
Py_DECREF(co);
if (!r) {
diff --git a/Modules/main.c b/Modules/main.c
index f6dade1..011ae59 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -35,13 +35,14 @@ static PyStatus
pymain_init(const _PyArgv *args)
{
PyStatus status;
+ PyPreConfig preconfig;
+ PyConfig config;
status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- PyPreConfig preconfig;
PyPreConfig_InitPythonConfig(&preconfig);
status = _Py_PreInitializeFromPyArgv(&preconfig, args);
@@ -49,7 +50,6 @@ pymain_init(const _PyArgv *args)
return status;
}
- PyConfig config;
PyConfig_InitPythonConfig(&config);
/* pass NULL as the config: config is read from command line arguments,
@@ -68,7 +68,13 @@ pymain_init(const _PyArgv *args)
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
- status = _PyStatus_OK();
+ /* VC6 (MSVC600) has no C99 compound literals, so _PyStatus_OK() (a
+ compound literal macro) cannot be used here; PyStatus_Ok() is the
+ public API function that returns the identical value
+ (Python/initconfig.c: `PyStatus PyStatus_Ok(void) { return
+ _PyStatus_OK(); }`), so this is not a behavior change for any
+ compiler. */
+ status = PyStatus_Ok();
done:
PyConfig_Clear(&config);
@@ -202,6 +208,8 @@ pymain_header(const PyConfig *config)
static void
pymain_import_readline(const PyConfig *config)
{
+ PyObject *mod;
+
if (config->isolated) {
return;
}
@@ -212,7 +220,7 @@ pymain_import_readline(const PyConfig *config)
return;
}
- PyObject *mod = PyImport_ImportModule("readline");
+ mod = PyImport_ImportModule("readline");
if (mod == NULL) {
PyErr_Clear();
}
@@ -234,6 +242,7 @@ pymain_run_command(wchar_t *command)
{
PyObject *unicode, *bytes;
int ret;
+ PyCompilerFlags cf;
unicode = PyUnicode_FromWideChar(command, -1);
if (unicode == NULL) {
@@ -250,7 +259,12 @@ pymain_run_command(wchar_t *command)
goto error;
}
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
+ /* VC6 has no C99 compound literals/designated initializers, so
+ _PyCompilerFlags_INIT (`(PyCompilerFlags){.cf_flags = 0,
+ .cf_feature_version = PY_MINOR_VERSION}`) cannot be used as an
+ initializer here; assign the same two fields explicitly instead. */
+ cf.cf_flags = 0;
+ cf.cf_feature_version = PY_MINOR_VERSION;
cf.cf_flags |= PyCF_IGNORE_COOKIE;
ret = PyRun_SimpleStringFlags(PyBytes_AsString(bytes), &cf);
Py_DECREF(bytes);
@@ -317,11 +331,16 @@ static int
pymain_run_file_obj(PyObject *program_name, PyObject *filename,
int skip_source_first_line)
{
+ FILE *fp;
+ struct _Py_stat_struct sb;
+ PyCompilerFlags cf;
+ int run;
+
if (PySys_Audit("cpython.run_file", "O", filename) < 0) {
return pymain_exit_err_print();
}
- FILE *fp = _Py_fopen_obj(filename, "rb");
+ fp = _Py_fopen_obj(filename, "rb");
if (fp == NULL) {
// Ignore the OSError
PyErr_Clear();
@@ -341,7 +360,6 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename,
}
}
- struct _Py_stat_struct sb;
if (_Py_fstat_noraise(fileno(fp), &sb) == 0 && S_ISDIR(sb.st_mode)) {
PySys_FormatStderr("%S: %R is a directory, cannot continue\n",
program_name, filename);
@@ -356,28 +374,35 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename,
}
/* PyRun_AnyFileExFlags(closeit=1) calls fclose(fp) before running code */
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
- int run = _PyRun_AnyFileObject(fp, filename, 1, &cf);
+ /* See pymain_run_command() above for why this is not
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
+ cf.cf_flags = 0;
+ cf.cf_feature_version = PY_MINOR_VERSION;
+ run = _PyRun_AnyFileObject(fp, filename, 1, &cf);
return (run != 0);
}
static int
pymain_run_file(const PyConfig *config)
{
- PyObject *filename = PyUnicode_FromWideChar(config->run_filename, -1);
+ PyObject *filename;
+ PyObject *program_name;
+ int res;
+
+ filename = PyUnicode_FromWideChar(config->run_filename, -1);
if (filename == NULL) {
PyErr_Print();
return -1;
}
- PyObject *program_name = PyUnicode_FromWideChar(config->program_name, -1);
+ program_name = PyUnicode_FromWideChar(config->program_name, -1);
if (program_name == NULL) {
Py_DECREF(filename);
PyErr_Print();
return -1;
}
- int res = pymain_run_file_obj(program_name, filename,
- config->skip_source_first_line);
+ res = pymain_run_file_obj(program_name, filename,
+ config->skip_source_first_line);
Py_DECREF(filename);
Py_DECREF(program_name);
return res;
@@ -388,12 +413,20 @@ static int
pymain_run_startup(PyConfig *config, int *exitcode)
{
int ret;
+ PyObject *startup = NULL;
+#ifdef MS_WINDOWS
+ const wchar_t *env;
+#else
+ const char *env;
+#endif
+ FILE *fp;
+ PyCompilerFlags cf;
+
if (!config->use_environment) {
return 0;
}
- PyObject *startup = NULL;
#ifdef MS_WINDOWS
- const wchar_t *env = _wgetenv(L"PYTHONSTARTUP");
+ env = _wgetenv(L"PYTHONSTARTUP");
if (env == NULL || env[0] == L'\0') {
return 0;
}
@@ -402,7 +435,7 @@ pymain_run_startup(PyConfig *config, int *exitcode)
goto error;
}
#else
- const char *env = _Py_GetEnv(config->use_environment, "PYTHONSTARTUP");
+ env = _Py_GetEnv(config->use_environment, "PYTHONSTARTUP");
if (env == NULL) {
return 0;
}
@@ -415,7 +448,7 @@ pymain_run_startup(PyConfig *config, int *exitcode)
goto error;
}
- FILE *fp = _Py_fopen_obj(startup, "r");
+ fp = _Py_fopen_obj(startup, "r");
if (fp == NULL) {
int save_errno = errno;
PyErr_Clear();
@@ -426,7 +459,10 @@ pymain_run_startup(PyConfig *config, int *exitcode)
goto error;
}
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
+ /* See pymain_run_command() above for why this is not
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
+ cf.cf_flags = 0;
+ cf.cf_feature_version = PY_MINOR_VERSION;
(void) _PyRun_SimpleFileObject(fp, startup, 0, &cf);
PyErr_Clear();
fclose(fp);
@@ -482,11 +518,15 @@ pymain_run_interactive_hook(int *exitcode)
static int
pymain_run_stdin(PyConfig *config)
{
+ PyCompilerFlags cf;
+ int run;
+
if (stdin_is_interactive(config)) {
+ int exitcode;
+
config->inspect = 0;
Py_InspectFlag = 0; /* do exit on SystemExit */
- int exitcode;
if (pymain_run_startup(config, &exitcode)) {
return exitcode;
}
@@ -505,8 +545,11 @@ pymain_run_stdin(PyConfig *config)
return pymain_exit_err_print();
}
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
- int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
+ /* See pymain_run_command() above for why this is not
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
+ cf.cf_flags = 0;
+ cf.cf_feature_version = PY_MINOR_VERSION;
+ run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
return (run != 0);
}
@@ -514,6 +557,9 @@ pymain_run_stdin(PyConfig *config)
static void
pymain_repl(PyConfig *config, int *exitcode)
{
+ PyCompilerFlags cf;
+ int res;
+
/* Check this environment variable at the end, to give programs the
opportunity to set it from Python. */
if (!config->inspect && _Py_GetEnv(config->use_environment, "PYTHONINSPECT")) {
@@ -535,8 +581,11 @@ pymain_repl(PyConfig *config, int *exitcode)
return;
}
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
- int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
+ /* See pymain_run_command() above for why this is not
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
+ cf.cf_flags = 0;
+ cf.cf_feature_version = PY_MINOR_VERSION;
+ res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
*exitcode = (res != 0);
}
@@ -718,11 +767,15 @@ pymain_main(_PyArgv *args)
int
Py_Main(int argc, wchar_t **argv)
{
- _PyArgv args = {
- .argc = argc,
- .use_bytes_argv = 0,
- .bytes_argv = NULL,
- .wchar_argv = argv};
+ /* VC6 has no C99 designated initializers, so the aggregate initializer
+ below cannot be used; assign each field explicitly instead (field
+ order does not matter for plain assignment, unlike the initializer
+ list it replaces). */
+ _PyArgv args;
+ args.argc = argc;
+ args.use_bytes_argv = 0;
+ args.bytes_argv = NULL;
+ args.wchar_argv = argv;
return pymain_main(&args);
}
@@ -730,11 +783,12 @@ Py_Main(int argc, wchar_t **argv)
int
Py_BytesMain(int argc, char **argv)
{
- _PyArgv args = {
- .argc = argc,
- .use_bytes_argv = 1,
- .bytes_argv = argv,
- .wchar_argv = NULL};
+ /* See Py_Main() above: VC6 has no C99 designated initializers. */
+ _PyArgv args;
+ args.argc = argc;
+ args.use_bytes_argv = 1;
+ args.bytes_argv = argv;
+ args.wchar_argv = NULL;
return pymain_main(&args);
}
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index 959b851..6d8ce84 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -256,6 +256,19 @@ typedef int pid_t;
# define PY_ULLONG_MAX _UI64_MAX
#endif
+/* Spelling of 64 bit integer literal suffixes. MSVC before Visual C++ .NET
+ (_MSC_VER < 1300, i.e. Visual C++ 6.0 and earlier) rejects the C99 LL/ULL
+ suffixes and spells them i64/ui64 instead. */
+#ifndef PY_LL
+# if defined(_MSC_VER) && _MSC_VER < 1300
+# define PY_LL(x) x##i64
+# define PY_ULL(x) x##ui64
+# else
+# define PY_LL(x) x##LL
+# define PY_ULL(x) x##ULL
+# endif
+#endif
+
/* For Windows the Python core is in a DLL by default. Test
Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
#if !defined(MS_NO_COREDLL) && !defined(Py_NO_ENABLE_SHARED)
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 9248e97..4abd5d4 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -88,8 +88,14 @@ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
#if defined(MS_WINDOWS)
+# if defined(_MSC_VER) && _MSC_VER < 1300
+/* VC6 does not support #pragma section plus __declspec(allocate()).
+ Use its older data_seg spelling for this initialized object instead. */
+# pragma data_seg("PyRuntime")
+# else
#pragma section("PyRuntime", read, write)
__declspec(allocate("PyRuntime"))
+# endif
#elif defined(__APPLE__)
@@ -103,10 +109,20 @@ _PyRuntimeState _PyRuntime
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
__attribute__ ((section (".PyRuntime")))
#endif
+#if defined(_MSC_VER) && _MSC_VER < 1300
+;
+#else
= _PyRuntimeState_INIT;
+#endif
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+# pragma data_seg()
+#endif
_Py_COMP_DIAG_POP
static int runtime_initialized = 0;
+#if defined(_MSC_VER) && _MSC_VER < 1300
+static int runtime_static_initialized = 0;
+#endif
PyStatus
_PyRuntime_Initialize(void)
@@ -117,6 +133,12 @@ _PyRuntime_Initialize(void)
every Py_Initialize() call, but doing so breaks the runtime.
This is because the runtime state is not properly finalized
currently. */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ if (!runtime_static_initialized) {
+ _PyRuntimeState_InitStaticDefaults(&_PyRuntime);
+ runtime_static_initialized = 1;
+ }
+#endif
if (runtime_initialized) {
return _PyStatus_OK();
}
@@ -175,10 +197,16 @@ Py_IsInitialized(void)
static int
init_importlib(PyThreadState *tstate, PyObject *sysmod)
{
+ PyInterpreterState *interp;
+ int verbose;
+ PyObject *importlib;
+ PyObject *imp_mod;
+ PyObject *value;
+
assert(!_PyErr_Occurred(tstate));
- PyInterpreterState *interp = tstate->interp;
- int verbose = _PyInterpreterState_GetConfig(interp)->verbose;
+ interp = tstate->interp;
+ verbose = _PyInterpreterState_GetConfig(interp)->verbose;
// Import _importlib through its frozen version, _frozen_importlib.
if (verbose) {
@@ -187,7 +215,7 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) {
return -1;
}
- PyObject *importlib = PyImport_AddModule("_frozen_importlib"); // borrowed
+ importlib = PyImport_AddModule("_frozen_importlib"); // borrowed
if (importlib == NULL) {
return -1;
}
@@ -197,7 +225,7 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
if (verbose) {
PySys_FormatStderr("import _imp # builtin\n");
}
- PyObject *imp_mod = _PyImport_BootstrapImp(tstate);
+ imp_mod = _PyImport_BootstrapImp(tstate);
if (imp_mod == NULL) {
return -1;
}
@@ -207,8 +235,8 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
}
// Install importlib as the implementation of import
- PyObject *value = PyObject_CallMethod(importlib, "_install",
- "OO", sysmod, imp_mod);
+ value = PyObject_CallMethod(importlib, "_install",
+ "OO", sysmod, imp_mod);
Py_DECREF(imp_mod);
if (value == NULL) {
return -1;
@@ -464,9 +492,10 @@ static int
interpreter_update_config(PyThreadState *tstate, int only_update_path_config)
{
const PyConfig *config = &tstate->interp->config;
+ PyStatus status;
if (!only_update_path_config) {
- PyStatus status = _PyConfig_Write(config, tstate->interp->runtime);
+ status = _PyConfig_Write(config, tstate->interp->runtime);
if (_PyStatus_EXCEPTION(status)) {
_PyErr_SetFromPyStatus(status);
return -1;
@@ -474,7 +503,7 @@ interpreter_update_config(PyThreadState *tstate, int only_update_path_config)
}
if (_Py_IsMainInterpreter(tstate->interp)) {
- PyStatus status = _PyPathConfig_UpdateGlobal(config);
+ status = _PyPathConfig_UpdateGlobal(config);
if (_PyStatus_EXCEPTION(status)) {
_PyErr_SetFromPyStatus(status);
return -1;
@@ -494,10 +523,11 @@ _PyInterpreterState_SetConfig(const PyConfig *src_config)
{
PyThreadState *tstate = _PyThreadState_GET();
int res = -1;
-
PyConfig config;
+ PyStatus status;
+
PyConfig_InitPythonConfig(&config);
- PyStatus status = _PyConfig_Copy(&config, src_config);
+ status = _PyConfig_Copy(&config, src_config);
if (_PyStatus_EXCEPTION(status)) {
_PyErr_SetFromPyStatus(status);
goto done;
@@ -542,12 +572,13 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime,
{
PyStatus status;
PyThreadState *tstate = _PyThreadState_GET();
+ PyInterpreterState *interp;
if (!tstate) {
return _PyStatus_ERR("failed to read thread state");
}
*tstate_p = tstate;
- PyInterpreterState *interp = tstate->interp;
+ interp = tstate->interp;
if (interp == NULL) {
return _PyStatus_ERR("can't make main interpreter");
}
@@ -577,11 +608,13 @@ static PyStatus
pycore_init_runtime(_PyRuntimeState *runtime,
const PyConfig *config)
{
+ PyStatus status;
+
if (runtime->initialized) {
return _PyStatus_ERR("main interpreter already initialized");
}
- PyStatus status = _PyConfig_Write(config, runtime);
+ status = _PyConfig_Write(config, runtime);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
@@ -640,13 +673,17 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
const PyConfig *config,
PyThreadState **tstate_p)
{
+ PyStatus status;
+ PyInterpreterState *interp;
+ PyThreadState *tstate;
+
/* Auto-thread-state API */
- PyStatus status = _PyGILState_Init(runtime);
+ status = _PyGILState_Init(runtime);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- PyInterpreterState *interp = PyInterpreterState_New();
+ interp = PyInterpreterState_New();
if (interp == NULL) {
return _PyStatus_ERR("can't make main interpreter");
}
@@ -657,7 +694,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return status;
}
- PyThreadState *tstate = PyThreadState_New(interp);
+ tstate = PyThreadState_New(interp);
if (tstate == NULL) {
return _PyStatus_ERR("can't make first thread");
}
@@ -762,8 +799,14 @@ static PyStatus
pycore_init_builtins(PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
-
- PyObject *bimod = _PyBuiltin_Init(interp);
+ PyObject *bimod;
+ PyObject *builtins_dict;
+ PyObject *isinstance;
+ PyObject *len;
+ PyObject *list_append;
+ PyObject *import_func;
+
+ bimod = _PyBuiltin_Init(interp);
if (bimod == NULL) {
goto error;
}
@@ -772,20 +815,20 @@ pycore_init_builtins(PyThreadState *tstate)
goto error;
}
- PyObject *builtins_dict = PyModule_GetDict(bimod);
+ builtins_dict = PyModule_GetDict(bimod);
if (builtins_dict == NULL) {
goto error;
}
Py_INCREF(builtins_dict);
interp->builtins = builtins_dict;
- PyObject *isinstance = PyDict_GetItem(builtins_dict, &_Py_ID(isinstance));
+ isinstance = PyDict_GetItem(builtins_dict, &_Py_ID(isinstance));
assert(isinstance);
interp->callable_cache.isinstance = isinstance;
- PyObject *len = PyDict_GetItem(builtins_dict, &_Py_ID(len));
+ len = PyDict_GetItem(builtins_dict, &_Py_ID(len));
assert(len);
interp->callable_cache.len = len;
- PyObject *list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
+ list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
assert(list_append);
interp->callable_cache.list_append = list_append;
@@ -800,8 +843,8 @@ pycore_init_builtins(PyThreadState *tstate)
Py_DECREF(bimod);
// Get the __import__ function
- PyObject *import_func = _PyDict_GetItemStringWithError(interp->builtins,
- "__import__");
+ import_func = _PyDict_GetItemStringWithError(interp->builtins,
+ "__import__");
if (import_func == NULL) {
goto error;
}
@@ -822,6 +865,7 @@ pycore_interp_init(PyThreadState *tstate)
PyInterpreterState *interp = tstate->interp;
PyStatus status;
PyObject *sysmod = NULL;
+ const PyConfig *config;
// Create singletons before the first PyType_Ready() call, since
// PyType_Ready() uses singletons like the Unicode empty string (tp_doc)
@@ -866,7 +910,7 @@ pycore_interp_init(PyThreadState *tstate)
goto done;
}
- const PyConfig *config = _PyInterpreterState_GetConfig(interp);
+ config = _PyInterpreterState_GetConfig(interp);
if (config->_install_importlib) {
/* This call sets up builtin and frozen import support */
if (init_importlib(tstate, sysmod) < 0) {
@@ -886,12 +930,14 @@ pyinit_config(_PyRuntimeState *runtime,
PyThreadState **tstate_p,
const PyConfig *config)
{
- PyStatus status = pycore_init_runtime(runtime, config);
+ PyStatus status;
+ PyThreadState *tstate;
+
+ status = pycore_init_runtime(runtime, config);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- PyThreadState *tstate;
status = pycore_create_interpreter(runtime, config, &tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
@@ -913,6 +959,8 @@ PyStatus
_Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
{
PyStatus status;
+ _PyRuntimeState *runtime;
+ PyPreConfig config;
if (src_config == NULL) {
return _PyStatus_ERR("preinitialization config is NULL");
@@ -922,7 +970,7 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ runtime = &_PyRuntime;
if (runtime->preinitialized) {
/* If it's already configured: ignored the new configuration */
@@ -933,8 +981,6 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
at exit on success. */
runtime->preinitializing = 1;
- PyPreConfig config;
-
status = _PyPreConfig_InitFromPreConfig(&config, src_config);
if (_PyStatus_EXCEPTION(status)) {
return status;
@@ -959,7 +1005,11 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
PyStatus
Py_PreInitializeFromBytesArgs(const PyPreConfig *src_config, Py_ssize_t argc, char **argv)
{
- _PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv};
+ _PyArgv args;
+
+ args.use_bytes_argv = 1;
+ args.argc = argc;
+ args.bytes_argv = argv;
return _Py_PreInitializeFromPyArgv(src_config, &args);
}
@@ -967,7 +1017,11 @@ Py_PreInitializeFromBytesArgs(const PyPreConfig *src_config, Py_ssize_t argc, ch
PyStatus
Py_PreInitializeFromArgs(const PyPreConfig *src_config, Py_ssize_t argc, wchar_t **argv)
{
- _PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv};
+ _PyArgv args;
+
+ args.use_bytes_argv = 0;
+ args.argc = argc;
+ args.wchar_argv = argv;
return _Py_PreInitializeFromPyArgv(src_config, &args);
}
@@ -983,31 +1037,33 @@ PyStatus
_Py_PreInitializeFromConfig(const PyConfig *config,
const _PyArgv *args)
{
+ PyStatus status;
+ _PyRuntimeState *runtime;
+ PyPreConfig preconfig;
+ _PyArgv config_args;
+
assert(config != NULL);
- PyStatus status = _PyRuntime_Initialize();
+ status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ runtime = &_PyRuntime;
if (runtime->preinitialized) {
/* Already initialized: do nothing */
return _PyStatus_OK();
}
- PyPreConfig preconfig;
-
_PyPreConfig_InitFromConfig(&preconfig, config);
if (!config->parse_argv) {
return Py_PreInitialize(&preconfig);
}
else if (args == NULL) {
- _PyArgv config_args = {
- .use_bytes_argv = 0,
- .argc = config->argv.length,
- .wchar_argv = config->argv.items};
+ config_args.use_bytes_argv = 0;
+ config_args.argc = config->argv.length;
+ config_args.wchar_argv = config->argv.items;
return _Py_PreInitializeFromPyArgv(&preconfig, &config_args);
}
else {
@@ -1039,13 +1095,13 @@ pyinit_core(_PyRuntimeState *runtime,
PyThreadState **tstate_p)
{
PyStatus status;
+ PyConfig config;
status = _Py_PreInitializeFromConfig(src_config, NULL);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- PyConfig config;
PyConfig_InitPythonConfig(&config);
status = _PyConfig_Copy(&config, src_config);
@@ -1093,14 +1149,13 @@ static PyStatus
init_interp_main(PyThreadState *tstate)
{
extern void _PyThread_debug_deprecation(void);
-
- assert(!_PyErr_Occurred(tstate));
-
PyStatus status;
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
PyInterpreterState *interp = tstate->interp;
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
+ assert(!_PyErr_Occurred(tstate));
+
if (!config->_install_importlib) {
/* Special mode for freeze_importlib: run with no import system
*
@@ -1218,7 +1273,10 @@ init_interp_main(PyThreadState *tstate)
static PyStatus
pyinit_main(PyThreadState *tstate)
{
- PyInterpreterState *interp = tstate->interp;
+ PyInterpreterState *interp;
+ PyStatus status;
+
+ interp = tstate->interp;
if (!interp->runtime->core_initialized) {
return _PyStatus_ERR("runtime core not initialized");
}
@@ -1227,7 +1285,7 @@ pyinit_main(PyThreadState *tstate)
return pyinit_main_reconfigure(tstate);
}
- PyStatus status = init_interp_main(tstate);
+ status = init_interp_main(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
@@ -1238,19 +1296,21 @@ pyinit_main(PyThreadState *tstate)
PyStatus
Py_InitializeFromConfig(const PyConfig *config)
{
+ PyStatus status;
+ _PyRuntimeState *runtime;
+ PyThreadState *tstate;
+
if (config == NULL) {
return _PyStatus_ERR("initialization config is NULL");
}
- PyStatus status;
-
status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ runtime = &_PyRuntime;
- PyThreadState *tstate = NULL;
+ tstate = NULL;
status = pyinit_core(runtime, config, &tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
@@ -1272,19 +1332,20 @@ void
Py_InitializeEx(int install_sigs)
{
PyStatus status;
+ _PyRuntimeState *runtime;
+ PyConfig config;
status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
Py_ExitStatusException(status);
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ runtime = &_PyRuntime;
if (runtime->initialized) {
/* bpo-33932: Calling Py_Initialize() twice does nothing. */
return;
}
- PyConfig config;
_PyConfig_InitCompatConfig(&config);
config.install_signal_handlers = install_sigs;
@@ -1302,20 +1363,24 @@ Py_Initialize(void)
Py_InitializeEx(1);
}
-
PyStatus
_Py_InitializeMain(void)
{
- PyStatus status = _PyRuntime_Initialize();
+ PyStatus status;
+ _PyRuntimeState *runtime;
+ PyThreadState *tstate;
+
+ status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- _PyRuntimeState *runtime = &_PyRuntime;
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+ runtime = &_PyRuntime;
+ tstate = _PyRuntimeState_GetThreadState(runtime);
return pyinit_main(tstate);
}
+
static void
finalize_modules_delete_special(PyThreadState *tstate, int verbose)
{
@@ -1336,6 +1401,9 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
};
PyInterpreterState *interp = tstate->interp;
+ const char * const *p;
+ PyObject *value;
+
if (verbose) {
PySys_WriteStderr("# clear builtins._\n");
}
@@ -1343,8 +1411,8 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
PyErr_WriteUnraisable(NULL);
}
- const char * const *p;
- for (p = sys_deletes; *p != NULL; p++) {
+ p = sys_deletes;
+ for (; *p != NULL; p++) {
if (verbose) {
PySys_WriteStderr("# clear sys.%s\n", *p);
}
@@ -1358,8 +1426,8 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
if (verbose) {
PySys_WriteStderr("# restore sys.%s\n", name);
}
- PyObject *value = _PyDict_GetItemStringWithError(interp->sysdict,
- orig_name);
+ value = _PyDict_GetItemStringWithError(interp->sysdict,
+ orig_name);
if (value == NULL) {
if (_PyErr_Occurred(tstate)) {
PyErr_WriteUnraisable(NULL);
@@ -1479,16 +1547,22 @@ static void
finalize_modules_clear_weaklist(PyInterpreterState *interp,
PyObject *weaklist, int verbose)
{
+ Py_ssize_t i;
+ PyObject *tup;
+ PyObject *name;
+ PyObject *mod;
+ PyObject *dict;
+
// First clear modules imported later
- for (Py_ssize_t i = PyList_GET_SIZE(weaklist) - 1; i >= 0; i--) {
- PyObject *tup = PyList_GET_ITEM(weaklist, i);
- PyObject *name = PyTuple_GET_ITEM(tup, 0);
- PyObject *mod = PyWeakref_GET_OBJECT(PyTuple_GET_ITEM(tup, 1));
+ for (i = PyList_GET_SIZE(weaklist) - 1; i >= 0; i--) {
+ tup = PyList_GET_ITEM(weaklist, i);
+ name = PyTuple_GET_ITEM(tup, 0);
+ mod = PyWeakref_GET_OBJECT(PyTuple_GET_ITEM(tup, 1));
if (mod == Py_None) {
continue;
}
assert(PyModule_Check(mod));
- PyObject *dict = PyModule_GetDict(mod);
+ dict = PyModule_GetDict(mod);
if (dict == interp->builtins || dict == interp->sysdict) {
continue;
}
@@ -1525,11 +1599,14 @@ finalize_modules(PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
PyObject *modules = interp->modules;
+ int verbose;
+ PyObject *weaklist;
+
if (modules == NULL) {
// Already done
return;
}
- int verbose = _PyInterpreterState_GetConfig(interp)->verbose;
+ verbose = _PyInterpreterState_GetConfig(interp)->verbose;
// Delete some special builtins._ and sys attributes first. These are
// common places where user values hide and people complain when their
@@ -1547,7 +1624,7 @@ finalize_modules(PyThreadState *tstate)
// modules when they are removed from sys.modules. The name is used
// for diagnosis messages (in verbose mode), while the weakref helps
// detect those modules which have been held alive.
- PyObject *weaklist = finalize_remove_modules(modules, verbose);
+ weaklist = finalize_remove_modules(modules, verbose);
// Clear the modules dict
finalize_clear_modules_dict(modules);
@@ -1751,14 +1828,26 @@ int
Py_FinalizeEx(void)
{
int status = 0;
-
_PyRuntimeState *runtime = &_PyRuntime;
+ PyThreadState *tstate;
+#ifdef Py_REF_DEBUG
+ int show_ref_count;
+#endif
+#ifdef Py_TRACE_REFS
+ int dump_refs;
+ wchar_t *dump_refs_file;
+ FILE *dump_refs_fp;
+#endif
+#ifdef WITH_PYMALLOC
+ int malloc_stats;
+#endif
+
if (!runtime->initialized) {
return status;
}
/* Get current thread state and interpreter pointer */
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
+ tstate = _PyRuntimeState_GetThreadState(runtime);
// Wrap up existing "threading"-module-created, non-daemon threads.
wait_for_thread_shutdown(tstate);
@@ -1781,14 +1870,14 @@ Py_FinalizeEx(void)
/* Copy the core config, PyInterpreterState_Delete() free
the core config memory */
#ifdef Py_REF_DEBUG
- int show_ref_count = tstate->interp->config.show_ref_count;
+ show_ref_count = tstate->interp->config.show_ref_count;
#endif
#ifdef Py_TRACE_REFS
- int dump_refs = tstate->interp->config.dump_refs;
- wchar_t *dump_refs_file = tstate->interp->config.dump_refs_file;
+ dump_refs = tstate->interp->config.dump_refs;
+ dump_refs_file = tstate->interp->config.dump_refs_file;
#endif
#ifdef WITH_PYMALLOC
- int malloc_stats = tstate->interp->config.malloc_stats;
+ malloc_stats = tstate->interp->config.malloc_stats;
#endif
/* Remaining daemon threads will automatically exit
@@ -1879,7 +1968,7 @@ Py_FinalizeEx(void)
* up later.
*/
- FILE *dump_refs_fp = NULL;
+ dump_refs_fp = NULL;
if (dump_refs_file != NULL) {
dump_refs_fp = _Py_wfopen(dump_refs_file, L"w");
if (dump_refs_fp == NULL) {
@@ -1956,12 +2045,17 @@ static PyStatus
new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
{
PyStatus status;
+ _PyRuntimeState *runtime;
+ PyInterpreterState *interp;
+ PyThreadState *tstate;
+ PyThreadState *save_tstate;
+ const PyConfig *config;
status = _PyRuntime_Initialize();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ runtime = &_PyRuntime;
if (!runtime->initialized) {
return _PyStatus_ERR("Py_Initialize must be called first");
@@ -1971,23 +2065,22 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
interpreters: disable PyGILState_Check(). */
runtime->gilstate.check_enabled = 0;
- PyInterpreterState *interp = PyInterpreterState_New();
+ interp = PyInterpreterState_New();
if (interp == NULL) {
*tstate_p = NULL;
return _PyStatus_OK();
}
- PyThreadState *tstate = PyThreadState_New(interp);
+ tstate = PyThreadState_New(interp);
if (tstate == NULL) {
PyInterpreterState_Delete(interp);
*tstate_p = NULL;
return _PyStatus_OK();
}
- PyThreadState *save_tstate = PyThreadState_Swap(tstate);
+ save_tstate = PyThreadState_Swap(tstate);
/* Copy the current interpreter config into the new interpreter */
- const PyConfig *config;
if (save_tstate != NULL) {
config = _PyInterpreterState_GetConfig(save_tstate->interp);
}
@@ -2099,7 +2192,7 @@ Py_EndInterpreter(PyThreadState *tstate)
static PyStatus
add_main_module(PyInterpreterState *interp)
{
- PyObject *m, *d, *loader, *ann_dict;
+ PyObject *m, *d, *loader, *ann_dict, *bimod, *loader_obj;
m = PyImport_AddModule("__main__");
if (m == NULL)
return _PyStatus_ERR("can't create __main__ module");
@@ -2116,7 +2209,7 @@ add_main_module(PyInterpreterState *interp)
if (PyErr_Occurred()) {
return _PyStatus_ERR("Failed to test __main__.__builtins__");
}
- PyObject *bimod = PyImport_ImportModule("builtins");
+ bimod = PyImport_ImportModule("builtins");
if (bimod == NULL) {
return _PyStatus_ERR("Failed to retrieve builtins module");
}
@@ -2137,15 +2230,15 @@ add_main_module(PyInterpreterState *interp)
if (PyErr_Occurred()) {
return _PyStatus_ERR("Failed to test __main__.__loader__");
}
- PyObject *loader = PyObject_GetAttrString(interp->importlib,
- "BuiltinImporter");
- if (loader == NULL) {
+ loader_obj = PyObject_GetAttrString(interp->importlib,
+ "BuiltinImporter");
+ if (loader_obj == NULL) {
return _PyStatus_ERR("Failed to retrieve BuiltinImporter");
}
- if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
+ if (PyDict_SetItemString(d, "__loader__", loader_obj) < 0) {
return _PyStatus_ERR("Failed to initialize __main__.__loader__");
}
- Py_DECREF(loader);
+ Py_DECREF(loader_obj);
}
return _PyStatus_OK();
}
@@ -2185,6 +2278,18 @@ is_valid_fd(int fd)
Only use dup() on Linux where dup() is enough to detect invalid FD
(bpo-32849).
*/
+#if defined(F_GETFD) && ( \
+ defined(__linux__) || \
+ defined(__APPLE__) || \
+ defined(__wasm__))
+#elif defined(__linux__)
+ int fd2;
+#elif defined(MS_WINDOWS)
+ HANDLE hfile;
+#else
+ struct stat st;
+#endif
+
if (fd < 0) {
return 0;
}
@@ -2194,20 +2299,18 @@ is_valid_fd(int fd)
defined(__wasm__))
return fcntl(fd, F_GETFD) >= 0;
#elif defined(__linux__)
- int fd2 = dup(fd);
+ fd2 = dup(fd);
if (fd2 >= 0) {
close(fd2);
}
return (fd2 >= 0);
#elif defined(MS_WINDOWS)
- HANDLE hfile;
_Py_BEGIN_SUPPRESS_IPH
hfile = (HANDLE)_get_osfhandle(fd);
_Py_END_SUPPRESS_IPH
return (hfile != INVALID_HANDLE_VALUE
&& GetFileType(hfile) != FILE_TYPE_UNKNOWN);
#else
- struct stat st;
return (fstat(fd, &st) == 0);
#endif
}
@@ -2219,6 +2322,7 @@ create_stdio(const PyConfig *config, PyObject* io,
const wchar_t* encoding, const wchar_t* errors)
{
PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res;
+ PyObject *encoding_str, *errors_str;
const char* mode;
const char* newline;
PyObject *line_buffering, *write_through;
@@ -2297,13 +2401,13 @@ create_stdio(const PyConfig *config, PyObject* io,
newline = "\n";
#endif
- PyObject *encoding_str = PyUnicode_FromWideChar(encoding, -1);
+ encoding_str = PyUnicode_FromWideChar(encoding, -1);
if (encoding_str == NULL) {
Py_CLEAR(buf);
goto error;
}
- PyObject *errors_str = PyUnicode_FromWideChar(errors, -1);
+ errors_str = PyUnicode_FromWideChar(errors, -1);
if (errors_str == NULL) {
Py_CLEAR(buf);
Py_CLEAR(encoding_str);
@@ -2590,8 +2694,10 @@ fatal_output_debug(const char *msg)
static void
fatal_error_dump_runtime(int fd, _PyRuntimeState *runtime)
{
+ PyThreadState *finalizing;
+
PUTS(fd, "Python runtime state: ");
- PyThreadState *finalizing = _PyRuntimeState_GetFinalizing(runtime);
+ finalizing = _PyRuntimeState_GetFinalizing(runtime);
if (finalizing) {
PUTS(fd, "finalizing (tstate=0x");
_Py_DumpHexadecimal(fd, (uintptr_t)finalizing, sizeof(finalizing) * 2);
@@ -2640,21 +2746,25 @@ fatal_error_exit(int status)
void
_Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
{
+ PyObject *modules;
+ Py_ssize_t pos;
+ PyObject *key, *value;
+ PyObject *stdlib_module_names;
+ int header;
+ Py_ssize_t count;
+
if (interp == NULL) {
return;
}
- PyObject *modules = interp->modules;
+ modules = interp->modules;
if (modules == NULL || !PyDict_Check(modules)) {
return;
}
- Py_ssize_t pos;
- PyObject *key, *value;
-
// Avoid PyDict_GetItemString() which calls PyUnicode_FromString(),
// memory cannot be allocated on the heap in a signal handler.
// Iterate on the dict instead.
- PyObject *stdlib_module_names = NULL;
+ stdlib_module_names = NULL;
if (interp->sysdict != NULL) {
pos = 0;
while (PyDict_Next(interp->sysdict, &pos, &key, &value)) {
@@ -2672,8 +2782,8 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
}
// List extensions
- int header = 1;
- Py_ssize_t count = 0;
+ header = 1;
+ count = 0;
pos = 0;
while (PyDict_Next(modules, &pos, &key, &value)) {
if (!PyUnicode_Check(key)) {
@@ -2730,6 +2840,11 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
int status)
{
static int reentrant = 0;
+ _PyRuntimeState *runtime;
+ PyThreadState *tstate;
+ PyInterpreterState *interp;
+ PyThreadState *tss_tstate;
+ int has_tstate_and_gil;
if (reentrant) {
/* Py_FatalError() caused a second fatal error.
@@ -2753,7 +2868,7 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
PUTS(fd, "\n");
}
- _PyRuntimeState *runtime = &_PyRuntime;
+ runtime = &_PyRuntime;
fatal_error_dump_runtime(fd, runtime);
/* Check if the current thread has a Python thread state
@@ -2764,16 +2879,16 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
tss_tstate != tstate if the current Python thread does not hold the GIL.
*/
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
- PyInterpreterState *interp = NULL;
- PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
+ tstate = _PyRuntimeState_GetThreadState(runtime);
+ interp = NULL;
+ tss_tstate = PyGILState_GetThisThreadState();
if (tstate != NULL) {
interp = tstate->interp;
}
else if (tss_tstate != NULL) {
interp = tss_tstate->interp;
}
- int has_tstate_and_gil = (tss_tstate != NULL && tss_tstate == tstate);
+ has_tstate_and_gil = (tss_tstate != NULL && tss_tstate == tstate);
if (has_tstate_and_gil) {
/* If an exception is set, print the exception with its traceback */
@@ -2828,21 +2943,24 @@ void _Py_NO_RETURN
_Py_FatalErrorFormat(const char *func, const char *format, ...)
{
static int reentrant = 0;
+ FILE *stream;
+ int fd;
+ va_list vargs;
+
if (reentrant) {
/* _Py_FatalErrorFormat() caused a second fatal error */
fatal_error_exit(-1);
}
reentrant = 1;
- FILE *stream = stderr;
- const int fd = fileno(stream);
+ stream = stderr;
+ fd = fileno(stream);
PUTS(fd, "Fatal Python error: ");
if (func) {
PUTS(fd, func);
PUTS(fd, ": ");
}
- va_list vargs;
#ifdef HAVE_STDARG_PROTOTYPES
va_start(vargs, format);
#else
@@ -2921,10 +3039,12 @@ int Py_AtExit(void (*func)(void))
static void
call_ll_exitfuncs(_PyRuntimeState *runtime)
{
+ void (*exitfunc)(void);
+
while (runtime->nexitfuncs > 0) {
/* pop last function from the list */
runtime->nexitfuncs--;
- void (*exitfunc)(void) = runtime->exitfuncs[runtime->nexitfuncs];
+ exitfunc = runtime->exitfuncs[runtime->nexitfuncs];
runtime->exitfuncs[runtime->nexitfuncs] = NULL;
exitfunc();
diff --git a/Python/pystate.c b/Python/pystate.c
index a451166..f26d2c2 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -50,9 +50,1127 @@ static void _PyThreadState_Delete(PyThreadState *tstate, int check_current);
/* Suppress deprecation warning for PyBytesObject.ob_shash */
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
+#if defined(_MSC_VER) && _MSC_VER < 1300
+/* We use an explicit field-by-field initializer on VC6, which cannot parse
+ the C99 designated initializer used by _PyRuntimeState_INIT. */
+
+static void
+init_immortal_object(PyObject *op, PyTypeObject *type)
+{
+#ifdef Py_TRACE_REFS
+ op->_ob_next = NULL;
+ op->_ob_prev = NULL;
+#endif
+ op->ob_refcnt = 999999999;
+ op->ob_type = type;
+}
+
+static void
+init_immortal_varobject(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)
+{
+ init_immortal_object(&op->ob_base, type);
+ op->ob_size = size;
+}
+
+static void
+init_ascii_object(PyASCIIObject *ascii, uint8_t *data,
+ const char *literal, int is_ascii)
+{
+ size_t len = strlen(literal);
+ init_immortal_object(&ascii->ob_base, &PyUnicode_Type);
+ ascii->length = (Py_ssize_t)len;
+ ascii->hash = -1;
+ ascii->state.interned = 0;
+ ascii->state.kind = 1;
+ ascii->state.compact = 1;
+ ascii->state.ascii = is_ascii;
+ ascii->state.ready = 1;
+ ascii->wstr = NULL;
+ memcpy(data, literal, len + 1);
+}
+
+static void
+init_latin1_object(PyCompactUnicodeObject *latin1, uint8_t *data,
+ unsigned char ch)
+{
+ char literal[2];
+ literal[0] = (char)ch;
+ literal[1] = '\0';
+ init_ascii_object(&latin1->_base, data, literal, 0);
+ latin1->utf8_length = 0;
+ latin1->utf8 = NULL;
+ latin1->wstr_length = 0;
+}
+
+static void
+init_static_threadstate(PyThreadState *tstate)
+{
+ tstate->_static = 1;
+ tstate->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
+ tstate->context_ver = 1;
+}
+
+static void
+init_static_interpreter(PyInterpreterState *interp)
+{
+ interp->_static = 1;
+ interp->id_refcount = -1;
+#ifdef HAVE_DLOPEN
+ interp->dlopenflags = _Py_DLOPEN_FLAGS;
+#endif
+ interp->ceval.recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
+ interp->gc.enabled = 1;
+ interp->gc.generations[0].threshold = 700;
+ interp->gc.generations[1].threshold = 10;
+ interp->gc.generations[2].threshold = 10;
+ init_static_threadstate(&interp->_initial_thread);
+}
+
+static void
+init_small_int(PyLongObject *op, int value)
+{
+ int size = 0;
+ int digit_value = value;
+ if (value < 0) {
+ size = -1;
+ digit_value = -value;
+ }
+ else if (value > 0) {
+ size = 1;
+ }
+ init_immortal_varobject(&op->ob_base, &PyLong_Type, size);
+ op->ob_digit[0] = (digit)digit_value;
+}
+
+static void
+init_static_global_objects(struct _Py_global_objects *objects)
+{
+ int i;
+
+ for (i = 0; i < _PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS; i++) {
+ init_small_int(&objects->singletons.small_ints[i],
+ i - _PY_NSMALLNEGINTS);
+ }
+
+ init_immortal_varobject(&objects->singletons.bytes_empty.ob_base,
+ &PyBytes_Type, 0);
+ objects->singletons.bytes_empty.ob_shash = -1;
+ objects->singletons.bytes_empty.ob_sval[0] = '\0';
+
+ for (i = 0; i < 256; i++) {
+ init_immortal_varobject(&objects->singletons.bytes_characters[i].ob.ob_base,
+ &PyBytes_Type, 1);
+ objects->singletons.bytes_characters[i].ob.ob_shash = -1;
+ objects->singletons.bytes_characters[i].ob.ob_sval[0] = (char)i;
+ objects->singletons.bytes_characters[i].eos = '\0';
+ }
+ init_ascii_object(&objects->singletons.strings.literals._anon_dictcomp._ascii,
+ objects->singletons.strings.literals._anon_dictcomp._data,
+ "<dictcomp>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._anon_genexpr._ascii,
+ objects->singletons.strings.literals._anon_genexpr._data,
+ "<genexpr>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._anon_lambda._ascii,
+ objects->singletons.strings.literals._anon_lambda._data,
+ "<lambda>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._anon_listcomp._ascii,
+ objects->singletons.strings.literals._anon_listcomp._data,
+ "<listcomp>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._anon_module._ascii,
+ objects->singletons.strings.literals._anon_module._data,
+ "<module>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._anon_setcomp._ascii,
+ objects->singletons.strings.literals._anon_setcomp._data,
+ "<setcomp>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._anon_string._ascii,
+ objects->singletons.strings.literals._anon_string._data,
+ "<string>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._anon_unknown._ascii,
+ objects->singletons.strings.literals._anon_unknown._data,
+ "<unknown>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._close_br._ascii,
+ objects->singletons.strings.literals._close_br._data,
+ "}", 1);
+ init_ascii_object(&objects->singletons.strings.literals._comma_sep._ascii,
+ objects->singletons.strings.literals._comma_sep._data,
+ ", ", 1);
+ init_ascii_object(&objects->singletons.strings.literals._dbl_close_br._ascii,
+ objects->singletons.strings.literals._dbl_close_br._data,
+ "}}", 1);
+ init_ascii_object(&objects->singletons.strings.literals._dbl_open_br._ascii,
+ objects->singletons.strings.literals._dbl_open_br._data,
+ "{{", 1);
+ init_ascii_object(&objects->singletons.strings.literals._dbl_percent._ascii,
+ objects->singletons.strings.literals._dbl_percent._data,
+ "%%", 1);
+ init_ascii_object(&objects->singletons.strings.literals._dot._ascii,
+ objects->singletons.strings.literals._dot._data,
+ ".", 1);
+ init_ascii_object(&objects->singletons.strings.literals._dot_locals._ascii,
+ objects->singletons.strings.literals._dot_locals._data,
+ ".<locals>", 1);
+ init_ascii_object(&objects->singletons.strings.literals._empty._ascii,
+ objects->singletons.strings.literals._empty._data,
+ "", 1);
+ init_ascii_object(&objects->singletons.strings.literals._list_err._ascii,
+ objects->singletons.strings.literals._list_err._data,
+ "list index out of range", 1);
+ init_ascii_object(&objects->singletons.strings.literals._newline._ascii,
+ objects->singletons.strings.literals._newline._data,
+ "\n", 1);
+ init_ascii_object(&objects->singletons.strings.literals._open_br._ascii,
+ objects->singletons.strings.literals._open_br._data,
+ "{", 1);
+ init_ascii_object(&objects->singletons.strings.literals._percent._ascii,
+ objects->singletons.strings.literals._percent._data,
+ "%", 1);
+ init_ascii_object(&objects->singletons.strings.literals._utf_8._ascii,
+ objects->singletons.strings.literals._utf_8._data,
+ "utf-8", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._False._ascii,
+ objects->singletons.strings.identifiers._False._data,
+ "False", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._Py_Repr._ascii,
+ objects->singletons.strings.identifiers._Py_Repr._data,
+ "Py_Repr", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._TextIOWrapper._ascii,
+ objects->singletons.strings.identifiers._TextIOWrapper._data,
+ "TextIOWrapper", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._True._ascii,
+ objects->singletons.strings.identifiers._True._data,
+ "True", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._WarningMessage._ascii,
+ objects->singletons.strings.identifiers._WarningMessage._data,
+ "WarningMessage", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__._ascii,
+ objects->singletons.strings.identifiers.__._data,
+ "_", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___IOBase_closed._ascii,
+ objects->singletons.strings.identifiers.___IOBase_closed._data,
+ "__IOBase_closed", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___abc_tpflags__._ascii,
+ objects->singletons.strings.identifiers.___abc_tpflags__._data,
+ "__abc_tpflags__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___abs__._ascii,
+ objects->singletons.strings.identifiers.___abs__._data,
+ "__abs__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___abstractmethods__._ascii,
+ objects->singletons.strings.identifiers.___abstractmethods__._data,
+ "__abstractmethods__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___add__._ascii,
+ objects->singletons.strings.identifiers.___add__._data,
+ "__add__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___aenter__._ascii,
+ objects->singletons.strings.identifiers.___aenter__._data,
+ "__aenter__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___aexit__._ascii,
+ objects->singletons.strings.identifiers.___aexit__._data,
+ "__aexit__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___aiter__._ascii,
+ objects->singletons.strings.identifiers.___aiter__._data,
+ "__aiter__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___all__._ascii,
+ objects->singletons.strings.identifiers.___all__._data,
+ "__all__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___and__._ascii,
+ objects->singletons.strings.identifiers.___and__._data,
+ "__and__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___anext__._ascii,
+ objects->singletons.strings.identifiers.___anext__._data,
+ "__anext__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___annotations__._ascii,
+ objects->singletons.strings.identifiers.___annotations__._data,
+ "__annotations__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___args__._ascii,
+ objects->singletons.strings.identifiers.___args__._data,
+ "__args__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___await__._ascii,
+ objects->singletons.strings.identifiers.___await__._data,
+ "__await__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___bases__._ascii,
+ objects->singletons.strings.identifiers.___bases__._data,
+ "__bases__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___bool__._ascii,
+ objects->singletons.strings.identifiers.___bool__._data,
+ "__bool__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___build_class__._ascii,
+ objects->singletons.strings.identifiers.___build_class__._data,
+ "__build_class__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___builtins__._ascii,
+ objects->singletons.strings.identifiers.___builtins__._data,
+ "__builtins__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___bytes__._ascii,
+ objects->singletons.strings.identifiers.___bytes__._data,
+ "__bytes__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___call__._ascii,
+ objects->singletons.strings.identifiers.___call__._data,
+ "__call__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___cantrace__._ascii,
+ objects->singletons.strings.identifiers.___cantrace__._data,
+ "__cantrace__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___class__._ascii,
+ objects->singletons.strings.identifiers.___class__._data,
+ "__class__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___class_getitem__._ascii,
+ objects->singletons.strings.identifiers.___class_getitem__._data,
+ "__class_getitem__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___classcell__._ascii,
+ objects->singletons.strings.identifiers.___classcell__._data,
+ "__classcell__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___complex__._ascii,
+ objects->singletons.strings.identifiers.___complex__._data,
+ "__complex__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___contains__._ascii,
+ objects->singletons.strings.identifiers.___contains__._data,
+ "__contains__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___copy__._ascii,
+ objects->singletons.strings.identifiers.___copy__._data,
+ "__copy__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___del__._ascii,
+ objects->singletons.strings.identifiers.___del__._data,
+ "__del__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___delattr__._ascii,
+ objects->singletons.strings.identifiers.___delattr__._data,
+ "__delattr__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___delete__._ascii,
+ objects->singletons.strings.identifiers.___delete__._data,
+ "__delete__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___delitem__._ascii,
+ objects->singletons.strings.identifiers.___delitem__._data,
+ "__delitem__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___dict__._ascii,
+ objects->singletons.strings.identifiers.___dict__._data,
+ "__dict__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___dir__._ascii,
+ objects->singletons.strings.identifiers.___dir__._data,
+ "__dir__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___divmod__._ascii,
+ objects->singletons.strings.identifiers.___divmod__._data,
+ "__divmod__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___doc__._ascii,
+ objects->singletons.strings.identifiers.___doc__._data,
+ "__doc__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___enter__._ascii,
+ objects->singletons.strings.identifiers.___enter__._data,
+ "__enter__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___eq__._ascii,
+ objects->singletons.strings.identifiers.___eq__._data,
+ "__eq__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___exit__._ascii,
+ objects->singletons.strings.identifiers.___exit__._data,
+ "__exit__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___file__._ascii,
+ objects->singletons.strings.identifiers.___file__._data,
+ "__file__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___float__._ascii,
+ objects->singletons.strings.identifiers.___float__._data,
+ "__float__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___floordiv__._ascii,
+ objects->singletons.strings.identifiers.___floordiv__._data,
+ "__floordiv__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___format__._ascii,
+ objects->singletons.strings.identifiers.___format__._data,
+ "__format__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___fspath__._ascii,
+ objects->singletons.strings.identifiers.___fspath__._data,
+ "__fspath__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ge__._ascii,
+ objects->singletons.strings.identifiers.___ge__._data,
+ "__ge__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___get__._ascii,
+ objects->singletons.strings.identifiers.___get__._data,
+ "__get__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___getattr__._ascii,
+ objects->singletons.strings.identifiers.___getattr__._data,
+ "__getattr__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___getattribute__._ascii,
+ objects->singletons.strings.identifiers.___getattribute__._data,
+ "__getattribute__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___getinitargs__._ascii,
+ objects->singletons.strings.identifiers.___getinitargs__._data,
+ "__getinitargs__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___getitem__._ascii,
+ objects->singletons.strings.identifiers.___getitem__._data,
+ "__getitem__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___getnewargs__._ascii,
+ objects->singletons.strings.identifiers.___getnewargs__._data,
+ "__getnewargs__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___getnewargs_ex__._ascii,
+ objects->singletons.strings.identifiers.___getnewargs_ex__._data,
+ "__getnewargs_ex__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___getstate__._ascii,
+ objects->singletons.strings.identifiers.___getstate__._data,
+ "__getstate__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___gt__._ascii,
+ objects->singletons.strings.identifiers.___gt__._data,
+ "__gt__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___hash__._ascii,
+ objects->singletons.strings.identifiers.___hash__._data,
+ "__hash__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___iadd__._ascii,
+ objects->singletons.strings.identifiers.___iadd__._data,
+ "__iadd__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___iand__._ascii,
+ objects->singletons.strings.identifiers.___iand__._data,
+ "__iand__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ifloordiv__._ascii,
+ objects->singletons.strings.identifiers.___ifloordiv__._data,
+ "__ifloordiv__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ilshift__._ascii,
+ objects->singletons.strings.identifiers.___ilshift__._data,
+ "__ilshift__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___imatmul__._ascii,
+ objects->singletons.strings.identifiers.___imatmul__._data,
+ "__imatmul__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___imod__._ascii,
+ objects->singletons.strings.identifiers.___imod__._data,
+ "__imod__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___import__._ascii,
+ objects->singletons.strings.identifiers.___import__._data,
+ "__import__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___imul__._ascii,
+ objects->singletons.strings.identifiers.___imul__._data,
+ "__imul__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___index__._ascii,
+ objects->singletons.strings.identifiers.___index__._data,
+ "__index__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___init__._ascii,
+ objects->singletons.strings.identifiers.___init__._data,
+ "__init__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___init_subclass__._ascii,
+ objects->singletons.strings.identifiers.___init_subclass__._data,
+ "__init_subclass__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___instancecheck__._ascii,
+ objects->singletons.strings.identifiers.___instancecheck__._data,
+ "__instancecheck__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___int__._ascii,
+ objects->singletons.strings.identifiers.___int__._data,
+ "__int__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___invert__._ascii,
+ objects->singletons.strings.identifiers.___invert__._data,
+ "__invert__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ior__._ascii,
+ objects->singletons.strings.identifiers.___ior__._data,
+ "__ior__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ipow__._ascii,
+ objects->singletons.strings.identifiers.___ipow__._data,
+ "__ipow__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___irshift__._ascii,
+ objects->singletons.strings.identifiers.___irshift__._data,
+ "__irshift__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___isabstractmethod__._ascii,
+ objects->singletons.strings.identifiers.___isabstractmethod__._data,
+ "__isabstractmethod__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___isub__._ascii,
+ objects->singletons.strings.identifiers.___isub__._data,
+ "__isub__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___iter__._ascii,
+ objects->singletons.strings.identifiers.___iter__._data,
+ "__iter__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___itruediv__._ascii,
+ objects->singletons.strings.identifiers.___itruediv__._data,
+ "__itruediv__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ixor__._ascii,
+ objects->singletons.strings.identifiers.___ixor__._data,
+ "__ixor__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___le__._ascii,
+ objects->singletons.strings.identifiers.___le__._data,
+ "__le__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___len__._ascii,
+ objects->singletons.strings.identifiers.___len__._data,
+ "__len__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___length_hint__._ascii,
+ objects->singletons.strings.identifiers.___length_hint__._data,
+ "__length_hint__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___lltrace__._ascii,
+ objects->singletons.strings.identifiers.___lltrace__._data,
+ "__lltrace__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___loader__._ascii,
+ objects->singletons.strings.identifiers.___loader__._data,
+ "__loader__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___lshift__._ascii,
+ objects->singletons.strings.identifiers.___lshift__._data,
+ "__lshift__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___lt__._ascii,
+ objects->singletons.strings.identifiers.___lt__._data,
+ "__lt__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___main__._ascii,
+ objects->singletons.strings.identifiers.___main__._data,
+ "__main__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___matmul__._ascii,
+ objects->singletons.strings.identifiers.___matmul__._data,
+ "__matmul__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___missing__._ascii,
+ objects->singletons.strings.identifiers.___missing__._data,
+ "__missing__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___mod__._ascii,
+ objects->singletons.strings.identifiers.___mod__._data,
+ "__mod__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___module__._ascii,
+ objects->singletons.strings.identifiers.___module__._data,
+ "__module__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___mro_entries__._ascii,
+ objects->singletons.strings.identifiers.___mro_entries__._data,
+ "__mro_entries__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___mul__._ascii,
+ objects->singletons.strings.identifiers.___mul__._data,
+ "__mul__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___name__._ascii,
+ objects->singletons.strings.identifiers.___name__._data,
+ "__name__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ne__._ascii,
+ objects->singletons.strings.identifiers.___ne__._data,
+ "__ne__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___neg__._ascii,
+ objects->singletons.strings.identifiers.___neg__._data,
+ "__neg__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___new__._ascii,
+ objects->singletons.strings.identifiers.___new__._data,
+ "__new__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___newobj__._ascii,
+ objects->singletons.strings.identifiers.___newobj__._data,
+ "__newobj__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___newobj_ex__._ascii,
+ objects->singletons.strings.identifiers.___newobj_ex__._data,
+ "__newobj_ex__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___next__._ascii,
+ objects->singletons.strings.identifiers.___next__._data,
+ "__next__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___notes__._ascii,
+ objects->singletons.strings.identifiers.___notes__._data,
+ "__notes__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___or__._ascii,
+ objects->singletons.strings.identifiers.___or__._data,
+ "__or__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___orig_class__._ascii,
+ objects->singletons.strings.identifiers.___orig_class__._data,
+ "__orig_class__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___origin__._ascii,
+ objects->singletons.strings.identifiers.___origin__._data,
+ "__origin__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___package__._ascii,
+ objects->singletons.strings.identifiers.___package__._data,
+ "__package__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___parameters__._ascii,
+ objects->singletons.strings.identifiers.___parameters__._data,
+ "__parameters__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___path__._ascii,
+ objects->singletons.strings.identifiers.___path__._data,
+ "__path__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___pos__._ascii,
+ objects->singletons.strings.identifiers.___pos__._data,
+ "__pos__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___pow__._ascii,
+ objects->singletons.strings.identifiers.___pow__._data,
+ "__pow__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___prepare__._ascii,
+ objects->singletons.strings.identifiers.___prepare__._data,
+ "__prepare__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___qualname__._ascii,
+ objects->singletons.strings.identifiers.___qualname__._data,
+ "__qualname__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___radd__._ascii,
+ objects->singletons.strings.identifiers.___radd__._data,
+ "__radd__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rand__._ascii,
+ objects->singletons.strings.identifiers.___rand__._data,
+ "__rand__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rdivmod__._ascii,
+ objects->singletons.strings.identifiers.___rdivmod__._data,
+ "__rdivmod__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___reduce__._ascii,
+ objects->singletons.strings.identifiers.___reduce__._data,
+ "__reduce__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___reduce_ex__._ascii,
+ objects->singletons.strings.identifiers.___reduce_ex__._data,
+ "__reduce_ex__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___repr__._ascii,
+ objects->singletons.strings.identifiers.___repr__._data,
+ "__repr__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___reversed__._ascii,
+ objects->singletons.strings.identifiers.___reversed__._data,
+ "__reversed__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rfloordiv__._ascii,
+ objects->singletons.strings.identifiers.___rfloordiv__._data,
+ "__rfloordiv__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rlshift__._ascii,
+ objects->singletons.strings.identifiers.___rlshift__._data,
+ "__rlshift__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rmatmul__._ascii,
+ objects->singletons.strings.identifiers.___rmatmul__._data,
+ "__rmatmul__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rmod__._ascii,
+ objects->singletons.strings.identifiers.___rmod__._data,
+ "__rmod__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rmul__._ascii,
+ objects->singletons.strings.identifiers.___rmul__._data,
+ "__rmul__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___ror__._ascii,
+ objects->singletons.strings.identifiers.___ror__._data,
+ "__ror__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___round__._ascii,
+ objects->singletons.strings.identifiers.___round__._data,
+ "__round__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rpow__._ascii,
+ objects->singletons.strings.identifiers.___rpow__._data,
+ "__rpow__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rrshift__._ascii,
+ objects->singletons.strings.identifiers.___rrshift__._data,
+ "__rrshift__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rshift__._ascii,
+ objects->singletons.strings.identifiers.___rshift__._data,
+ "__rshift__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rsub__._ascii,
+ objects->singletons.strings.identifiers.___rsub__._data,
+ "__rsub__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rtruediv__._ascii,
+ objects->singletons.strings.identifiers.___rtruediv__._data,
+ "__rtruediv__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___rxor__._ascii,
+ objects->singletons.strings.identifiers.___rxor__._data,
+ "__rxor__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___set__._ascii,
+ objects->singletons.strings.identifiers.___set__._data,
+ "__set__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___set_name__._ascii,
+ objects->singletons.strings.identifiers.___set_name__._data,
+ "__set_name__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___setattr__._ascii,
+ objects->singletons.strings.identifiers.___setattr__._data,
+ "__setattr__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___setitem__._ascii,
+ objects->singletons.strings.identifiers.___setitem__._data,
+ "__setitem__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___setstate__._ascii,
+ objects->singletons.strings.identifiers.___setstate__._data,
+ "__setstate__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___sizeof__._ascii,
+ objects->singletons.strings.identifiers.___sizeof__._data,
+ "__sizeof__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___slotnames__._ascii,
+ objects->singletons.strings.identifiers.___slotnames__._data,
+ "__slotnames__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___slots__._ascii,
+ objects->singletons.strings.identifiers.___slots__._data,
+ "__slots__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___spec__._ascii,
+ objects->singletons.strings.identifiers.___spec__._data,
+ "__spec__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___str__._ascii,
+ objects->singletons.strings.identifiers.___str__._data,
+ "__str__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___sub__._ascii,
+ objects->singletons.strings.identifiers.___sub__._data,
+ "__sub__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___subclasscheck__._ascii,
+ objects->singletons.strings.identifiers.___subclasscheck__._data,
+ "__subclasscheck__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___subclasshook__._ascii,
+ objects->singletons.strings.identifiers.___subclasshook__._data,
+ "__subclasshook__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___truediv__._ascii,
+ objects->singletons.strings.identifiers.___truediv__._data,
+ "__truediv__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___trunc__._ascii,
+ objects->singletons.strings.identifiers.___trunc__._data,
+ "__trunc__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_is_unpacked_typevartuple__._ascii,
+ objects->singletons.strings.identifiers.___typing_is_unpacked_typevartuple__._data,
+ "__typing_is_unpacked_typevartuple__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_prepare_subst__._ascii,
+ objects->singletons.strings.identifiers.___typing_prepare_subst__._data,
+ "__typing_prepare_subst__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_subst__._ascii,
+ objects->singletons.strings.identifiers.___typing_subst__._data,
+ "__typing_subst__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_unpacked_tuple_args__._ascii,
+ objects->singletons.strings.identifiers.___typing_unpacked_tuple_args__._data,
+ "__typing_unpacked_tuple_args__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___warningregistry__._ascii,
+ objects->singletons.strings.identifiers.___warningregistry__._data,
+ "__warningregistry__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___weakref__._ascii,
+ objects->singletons.strings.identifiers.___weakref__._data,
+ "__weakref__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.___xor__._ascii,
+ objects->singletons.strings.identifiers.___xor__._data,
+ "__xor__", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__abc_impl._ascii,
+ objects->singletons.strings.identifiers.__abc_impl._data,
+ "_abc_impl", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__annotation._ascii,
+ objects->singletons.strings.identifiers.__annotation._data,
+ "_annotation", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__blksize._ascii,
+ objects->singletons.strings.identifiers.__blksize._data,
+ "_blksize", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__bootstrap._ascii,
+ objects->singletons.strings.identifiers.__bootstrap._data,
+ "_bootstrap", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__dealloc_warn._ascii,
+ objects->singletons.strings.identifiers.__dealloc_warn._data,
+ "_dealloc_warn", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__finalizing._ascii,
+ objects->singletons.strings.identifiers.__finalizing._data,
+ "_finalizing", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__find_and_load._ascii,
+ objects->singletons.strings.identifiers.__find_and_load._data,
+ "_find_and_load", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__fix_up_module._ascii,
+ objects->singletons.strings.identifiers.__fix_up_module._data,
+ "_fix_up_module", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__get_sourcefile._ascii,
+ objects->singletons.strings.identifiers.__get_sourcefile._data,
+ "_get_sourcefile", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__handle_fromlist._ascii,
+ objects->singletons.strings.identifiers.__handle_fromlist._data,
+ "_handle_fromlist", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__initializing._ascii,
+ objects->singletons.strings.identifiers.__initializing._data,
+ "_initializing", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__is_text_encoding._ascii,
+ objects->singletons.strings.identifiers.__is_text_encoding._data,
+ "_is_text_encoding", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__lock_unlock_module._ascii,
+ objects->singletons.strings.identifiers.__lock_unlock_module._data,
+ "_lock_unlock_module", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__showwarnmsg._ascii,
+ objects->singletons.strings.identifiers.__showwarnmsg._data,
+ "_showwarnmsg", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__shutdown._ascii,
+ objects->singletons.strings.identifiers.__shutdown._data,
+ "_shutdown", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__slotnames._ascii,
+ objects->singletons.strings.identifiers.__slotnames._data,
+ "_slotnames", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__strptime_time._ascii,
+ objects->singletons.strings.identifiers.__strptime_time._data,
+ "_strptime_time", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__uninitialized_submodules._ascii,
+ objects->singletons.strings.identifiers.__uninitialized_submodules._data,
+ "_uninitialized_submodules", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__warn_unawaited_coroutine._ascii,
+ objects->singletons.strings.identifiers.__warn_unawaited_coroutine._data,
+ "_warn_unawaited_coroutine", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers.__xoptions._ascii,
+ objects->singletons.strings.identifiers.__xoptions._data,
+ "_xoptions", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._add._ascii,
+ objects->singletons.strings.identifiers._add._data,
+ "add", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._append._ascii,
+ objects->singletons.strings.identifiers._append._data,
+ "append", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._big._ascii,
+ objects->singletons.strings.identifiers._big._data,
+ "big", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._buffer._ascii,
+ objects->singletons.strings.identifiers._buffer._data,
+ "buffer", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._builtins._ascii,
+ objects->singletons.strings.identifiers._builtins._data,
+ "builtins", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._c_call._ascii,
+ objects->singletons.strings.identifiers._c_call._data,
+ "c_call", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._c_exception._ascii,
+ objects->singletons.strings.identifiers._c_exception._data,
+ "c_exception", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._c_return._ascii,
+ objects->singletons.strings.identifiers._c_return._data,
+ "c_return", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._call._ascii,
+ objects->singletons.strings.identifiers._call._data,
+ "call", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._clear._ascii,
+ objects->singletons.strings.identifiers._clear._data,
+ "clear", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._close._ascii,
+ objects->singletons.strings.identifiers._close._data,
+ "close", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._closed._ascii,
+ objects->singletons.strings.identifiers._closed._data,
+ "closed", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._code._ascii,
+ objects->singletons.strings.identifiers._code._data,
+ "code", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._copy._ascii,
+ objects->singletons.strings.identifiers._copy._data,
+ "copy", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._copyreg._ascii,
+ objects->singletons.strings.identifiers._copyreg._data,
+ "copyreg", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._decode._ascii,
+ objects->singletons.strings.identifiers._decode._data,
+ "decode", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._default._ascii,
+ objects->singletons.strings.identifiers._default._data,
+ "default", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._defaultaction._ascii,
+ objects->singletons.strings.identifiers._defaultaction._data,
+ "defaultaction", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._dictcomp._ascii,
+ objects->singletons.strings.identifiers._dictcomp._data,
+ "dictcomp", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._difference_update._ascii,
+ objects->singletons.strings.identifiers._difference_update._data,
+ "difference_update", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._dispatch_table._ascii,
+ objects->singletons.strings.identifiers._dispatch_table._data,
+ "dispatch_table", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._displayhook._ascii,
+ objects->singletons.strings.identifiers._displayhook._data,
+ "displayhook", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._enable._ascii,
+ objects->singletons.strings.identifiers._enable._data,
+ "enable", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._encode._ascii,
+ objects->singletons.strings.identifiers._encode._data,
+ "encode", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._encoding._ascii,
+ objects->singletons.strings.identifiers._encoding._data,
+ "encoding", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._end_lineno._ascii,
+ objects->singletons.strings.identifiers._end_lineno._data,
+ "end_lineno", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._end_offset._ascii,
+ objects->singletons.strings.identifiers._end_offset._data,
+ "end_offset", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._errors._ascii,
+ objects->singletons.strings.identifiers._errors._data,
+ "errors", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._excepthook._ascii,
+ objects->singletons.strings.identifiers._excepthook._data,
+ "excepthook", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._exception._ascii,
+ objects->singletons.strings.identifiers._exception._data,
+ "exception", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._extend._ascii,
+ objects->singletons.strings.identifiers._extend._data,
+ "extend", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._filename._ascii,
+ objects->singletons.strings.identifiers._filename._data,
+ "filename", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._fileno._ascii,
+ objects->singletons.strings.identifiers._fileno._data,
+ "fileno", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._fillvalue._ascii,
+ objects->singletons.strings.identifiers._fillvalue._data,
+ "fillvalue", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._filters._ascii,
+ objects->singletons.strings.identifiers._filters._data,
+ "filters", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._find_class._ascii,
+ objects->singletons.strings.identifiers._find_class._data,
+ "find_class", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._flush._ascii,
+ objects->singletons.strings.identifiers._flush._data,
+ "flush", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._genexpr._ascii,
+ objects->singletons.strings.identifiers._genexpr._data,
+ "genexpr", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._get._ascii,
+ objects->singletons.strings.identifiers._get._data,
+ "get", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._get_source._ascii,
+ objects->singletons.strings.identifiers._get_source._data,
+ "get_source", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._getattr._ascii,
+ objects->singletons.strings.identifiers._getattr._data,
+ "getattr", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._getstate._ascii,
+ objects->singletons.strings.identifiers._getstate._data,
+ "getstate", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._ignore._ascii,
+ objects->singletons.strings.identifiers._ignore._data,
+ "ignore", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._importlib._ascii,
+ objects->singletons.strings.identifiers._importlib._data,
+ "importlib", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._inf._ascii,
+ objects->singletons.strings.identifiers._inf._data,
+ "inf", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._intersection._ascii,
+ objects->singletons.strings.identifiers._intersection._data,
+ "intersection", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._isatty._ascii,
+ objects->singletons.strings.identifiers._isatty._data,
+ "isatty", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._isinstance._ascii,
+ objects->singletons.strings.identifiers._isinstance._data,
+ "isinstance", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._items._ascii,
+ objects->singletons.strings.identifiers._items._data,
+ "items", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._iter._ascii,
+ objects->singletons.strings.identifiers._iter._data,
+ "iter", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._join._ascii,
+ objects->singletons.strings.identifiers._join._data,
+ "join", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._keys._ascii,
+ objects->singletons.strings.identifiers._keys._data,
+ "keys", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._lambda._ascii,
+ objects->singletons.strings.identifiers._lambda._data,
+ "lambda", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._last_traceback._ascii,
+ objects->singletons.strings.identifiers._last_traceback._data,
+ "last_traceback", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._last_type._ascii,
+ objects->singletons.strings.identifiers._last_type._data,
+ "last_type", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._last_value._ascii,
+ objects->singletons.strings.identifiers._last_value._data,
+ "last_value", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._latin1._ascii,
+ objects->singletons.strings.identifiers._latin1._data,
+ "latin1", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._len._ascii,
+ objects->singletons.strings.identifiers._len._data,
+ "len", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._line._ascii,
+ objects->singletons.strings.identifiers._line._data,
+ "line", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._lineno._ascii,
+ objects->singletons.strings.identifiers._lineno._data,
+ "lineno", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._listcomp._ascii,
+ objects->singletons.strings.identifiers._listcomp._data,
+ "listcomp", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._little._ascii,
+ objects->singletons.strings.identifiers._little._data,
+ "little", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._locale._ascii,
+ objects->singletons.strings.identifiers._locale._data,
+ "locale", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._match._ascii,
+ objects->singletons.strings.identifiers._match._data,
+ "match", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._metaclass._ascii,
+ objects->singletons.strings.identifiers._metaclass._data,
+ "metaclass", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._mode._ascii,
+ objects->singletons.strings.identifiers._mode._data,
+ "mode", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._modules._ascii,
+ objects->singletons.strings.identifiers._modules._data,
+ "modules", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._mro._ascii,
+ objects->singletons.strings.identifiers._mro._data,
+ "mro", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._msg._ascii,
+ objects->singletons.strings.identifiers._msg._data,
+ "msg", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._n_fields._ascii,
+ objects->singletons.strings.identifiers._n_fields._data,
+ "n_fields", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._n_sequence_fields._ascii,
+ objects->singletons.strings.identifiers._n_sequence_fields._data,
+ "n_sequence_fields", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._n_unnamed_fields._ascii,
+ objects->singletons.strings.identifiers._n_unnamed_fields._data,
+ "n_unnamed_fields", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._name._ascii,
+ objects->singletons.strings.identifiers._name._data,
+ "name", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._newlines._ascii,
+ objects->singletons.strings.identifiers._newlines._data,
+ "newlines", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._next._ascii,
+ objects->singletons.strings.identifiers._next._data,
+ "next", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._obj._ascii,
+ objects->singletons.strings.identifiers._obj._data,
+ "obj", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._offset._ascii,
+ objects->singletons.strings.identifiers._offset._data,
+ "offset", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._onceregistry._ascii,
+ objects->singletons.strings.identifiers._onceregistry._data,
+ "onceregistry", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._opcode._ascii,
+ objects->singletons.strings.identifiers._opcode._data,
+ "opcode", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._open._ascii,
+ objects->singletons.strings.identifiers._open._data,
+ "open", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._parent._ascii,
+ objects->singletons.strings.identifiers._parent._data,
+ "parent", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._partial._ascii,
+ objects->singletons.strings.identifiers._partial._data,
+ "partial", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._path._ascii,
+ objects->singletons.strings.identifiers._path._data,
+ "path", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._peek._ascii,
+ objects->singletons.strings.identifiers._peek._data,
+ "peek", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._persistent_id._ascii,
+ objects->singletons.strings.identifiers._persistent_id._data,
+ "persistent_id", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._persistent_load._ascii,
+ objects->singletons.strings.identifiers._persistent_load._data,
+ "persistent_load", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._print_file_and_line._ascii,
+ objects->singletons.strings.identifiers._print_file_and_line._data,
+ "print_file_and_line", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._ps1._ascii,
+ objects->singletons.strings.identifiers._ps1._data,
+ "ps1", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._ps2._ascii,
+ objects->singletons.strings.identifiers._ps2._data,
+ "ps2", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._raw._ascii,
+ objects->singletons.strings.identifiers._raw._data,
+ "raw", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._read._ascii,
+ objects->singletons.strings.identifiers._read._data,
+ "read", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._read1._ascii,
+ objects->singletons.strings.identifiers._read1._data,
+ "read1", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._readable._ascii,
+ objects->singletons.strings.identifiers._readable._data,
+ "readable", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._readall._ascii,
+ objects->singletons.strings.identifiers._readall._data,
+ "readall", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._readinto._ascii,
+ objects->singletons.strings.identifiers._readinto._data,
+ "readinto", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._readinto1._ascii,
+ objects->singletons.strings.identifiers._readinto1._data,
+ "readinto1", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._readline._ascii,
+ objects->singletons.strings.identifiers._readline._data,
+ "readline", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._reducer_override._ascii,
+ objects->singletons.strings.identifiers._reducer_override._data,
+ "reducer_override", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._reload._ascii,
+ objects->singletons.strings.identifiers._reload._data,
+ "reload", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._replace._ascii,
+ objects->singletons.strings.identifiers._replace._data,
+ "replace", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._reset._ascii,
+ objects->singletons.strings.identifiers._reset._data,
+ "reset", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._return._ascii,
+ objects->singletons.strings.identifiers._return._data,
+ "return", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._reversed._ascii,
+ objects->singletons.strings.identifiers._reversed._data,
+ "reversed", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._seek._ascii,
+ objects->singletons.strings.identifiers._seek._data,
+ "seek", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._seekable._ascii,
+ objects->singletons.strings.identifiers._seekable._data,
+ "seekable", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._send._ascii,
+ objects->singletons.strings.identifiers._send._data,
+ "send", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._setcomp._ascii,
+ objects->singletons.strings.identifiers._setcomp._data,
+ "setcomp", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._setstate._ascii,
+ objects->singletons.strings.identifiers._setstate._data,
+ "setstate", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._sort._ascii,
+ objects->singletons.strings.identifiers._sort._data,
+ "sort", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._stderr._ascii,
+ objects->singletons.strings.identifiers._stderr._data,
+ "stderr", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._stdin._ascii,
+ objects->singletons.strings.identifiers._stdin._data,
+ "stdin", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._stdout._ascii,
+ objects->singletons.strings.identifiers._stdout._data,
+ "stdout", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._strict._ascii,
+ objects->singletons.strings.identifiers._strict._data,
+ "strict", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._symmetric_difference_update._ascii,
+ objects->singletons.strings.identifiers._symmetric_difference_update._data,
+ "symmetric_difference_update", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._tell._ascii,
+ objects->singletons.strings.identifiers._tell._data,
+ "tell", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._text._ascii,
+ objects->singletons.strings.identifiers._text._data,
+ "text", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._threading._ascii,
+ objects->singletons.strings.identifiers._threading._data,
+ "threading", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._throw._ascii,
+ objects->singletons.strings.identifiers._throw._data,
+ "throw", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._top._ascii,
+ objects->singletons.strings.identifiers._top._data,
+ "top", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._truncate._ascii,
+ objects->singletons.strings.identifiers._truncate._data,
+ "truncate", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._unraisablehook._ascii,
+ objects->singletons.strings.identifiers._unraisablehook._data,
+ "unraisablehook", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._values._ascii,
+ objects->singletons.strings.identifiers._values._data,
+ "values", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._version._ascii,
+ objects->singletons.strings.identifiers._version._data,
+ "version", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._warnings._ascii,
+ objects->singletons.strings.identifiers._warnings._data,
+ "warnings", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._warnoptions._ascii,
+ objects->singletons.strings.identifiers._warnoptions._data,
+ "warnoptions", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._writable._ascii,
+ objects->singletons.strings.identifiers._writable._data,
+ "writable", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._write._ascii,
+ objects->singletons.strings.identifiers._write._data,
+ "write", 1);
+ init_ascii_object(&objects->singletons.strings.identifiers._zipimporter._ascii,
+ objects->singletons.strings.identifiers._zipimporter._data,
+ "zipimporter", 1);
+
+ for (i = 0; i < 128; i++) {
+ char literal[2];
+ literal[0] = (char)i;
+ literal[1] = '\0';
+ init_ascii_object(&objects->singletons.strings.ascii[i]._ascii,
+ objects->singletons.strings.ascii[i]._data,
+ literal, 1);
+ init_latin1_object(&objects->singletons.strings.latin1[i]._latin1,
+ objects->singletons.strings.latin1[i]._data,
+ (unsigned char)(i + 128));
+ }
+
+ init_immortal_varobject(&objects->singletons.tuple_empty.ob_base,
+ &PyTuple_Type, 0);
+}
+
+void
+_PyRuntimeState_InitStaticDefaults(_PyRuntimeState *runtime)
+{
+ memset(runtime, 0, sizeof(*runtime));
+ runtime->gilstate.check_enabled = 1;
+ runtime->interpreters.next_id = -1;
+ init_static_global_objects(&runtime->global_objects);
+ init_static_interpreter(&runtime->_main_interpreter);
+}
+
+#else
/* We use "initial" if the runtime gets re-used
(e.g. Py_Finalize() followed by Py_Initialize(). */
static const _PyRuntimeState initial = _PyRuntimeState_INIT;
+#endif
_Py_COMP_DIAG_POP
static int
@@ -62,20 +1180,23 @@ alloc_for_runtime(PyThread_type_lock *plock1, PyThread_type_lock *plock2,
/* Force default allocator, since _PyRuntimeState_Fini() must
use the same allocator than this function. */
PyMemAllocatorEx old_alloc;
+ PyThread_type_lock lock1;
+ PyThread_type_lock lock2;
+ PyThread_type_lock lock3;
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
- PyThread_type_lock lock1 = PyThread_allocate_lock();
+ lock1 = PyThread_allocate_lock();
if (lock1 == NULL) {
return -1;
}
- PyThread_type_lock lock2 = PyThread_allocate_lock();
+ lock2 = PyThread_allocate_lock();
if (lock2 == NULL) {
PyThread_free_lock(lock1);
return -1;
}
- PyThread_type_lock lock3 = PyThread_allocate_lock();
+ lock3 = PyThread_allocate_lock();
if (lock3 == NULL) {
PyThread_free_lock(lock1);
PyThread_free_lock(lock2);
@@ -149,7 +1270,11 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
if (runtime->_initialized) {
// Py_Initialize() must be running again.
// Reset to _PyRuntimeState_INIT.
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ _PyRuntimeState_InitStaticDefaults(runtime);
+#else
memcpy(runtime, &initial, sizeof(*runtime));
+#endif
}
init_runtime(runtime, open_code_hook, open_code_userdata, audit_hook_head,
unicode_next_index, lock1, lock2, lock3);
@@ -302,15 +1427,21 @@ PyInterpreterState *
PyInterpreterState_New(void)
{
PyInterpreterState *interp;
- PyThreadState *tstate = _PyThreadState_GET();
+ PyThreadState *tstate;
+ PyThread_type_lock pending_lock;
+ _PyRuntimeState *runtime;
+ struct pyinterpreters *interpreters;
+ int64_t id;
+ PyInterpreterState *old_head;
/* tstate is NULL when Py_InitializeFromConfig() calls
PyInterpreterState_New() to create the main interpreter. */
+ tstate = _PyThreadState_GET();
if (_PySys_Audit(tstate, "cpython.PyInterpreterState_New", NULL) < 0) {
return NULL;
}
- PyThread_type_lock pending_lock = PyThread_allocate_lock();
+ pending_lock = PyThread_allocate_lock();
if (pending_lock == NULL) {
if (tstate != NULL) {
_PyErr_NoMemory(tstate);
@@ -319,8 +1450,8 @@ PyInterpreterState_New(void)
}
/* Don't get runtime from tstate since tstate can be NULL. */
- _PyRuntimeState *runtime = &_PyRuntime;
- struct pyinterpreters *interpreters = &runtime->interpreters;
+ runtime = &_PyRuntime;
+ interpreters = &runtime->interpreters;
/* We completely serialize creation of multiple interpreters, since
it simplifies things here and blocking concurrent calls isn't a problem.
@@ -328,11 +1459,11 @@ PyInterpreterState_New(void)
after the main interpreter is created. */
HEAD_LOCK(runtime);
- int64_t id = interpreters->next_id;
+ id = interpreters->next_id;
interpreters->next_id += 1;
// Allocate the interpreter and add it to the runtime state.
- PyInterpreterState *old_head = interpreters->head;
+ old_head = interpreters->head;
if (old_head == NULL) {
// We are creating the main interpreter.
assert(interpreters->main == NULL);
@@ -354,8 +1485,13 @@ PyInterpreterState_New(void)
goto error;
}
// Set to _PyInterpreterState_INIT.
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ memset(interp, 0, sizeof(*interp));
+ init_static_interpreter(interp);
+#else
memcpy(interp, &initial._main_interpreter,
sizeof(*interp));
+#endif
// We need to adjust any fields that are different from the initial
// interpreter (as defined in _PyInterpreterState_INIT):
interp->_static = false;
@@ -391,6 +1527,7 @@ static void
interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
{
_PyRuntimeState *runtime = interp->runtime;
+ PyThreadState *p;
if (_PySys_Audit(tstate, "cpython.PyInterpreterState_Clear", NULL) < 0) {
_PyErr_Clear(tstate);
@@ -398,7 +1535,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
// Clear the current/main thread state last.
HEAD_LOCK(runtime);
- PyThreadState *p = interp->threads.head;
+ p = interp->threads.head;
HEAD_UNLOCK(runtime);
while (p != NULL) {
// See https://github.com/python/cpython/issues/102126
@@ -490,6 +1627,7 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
{
_PyRuntimeState *runtime = interp->runtime;
struct pyinterpreters *interpreters = &runtime->interpreters;
+ PyInterpreterState **p;
zapthreads(interp, 0);
_PyEval_FiniState(&interp->ceval);
@@ -498,7 +1636,6 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
_PyThreadState_Swap(&runtime->gilstate, NULL);
HEAD_LOCK(runtime);
- PyInterpreterState **p;
for (p = &interpreters->head; ; p = &(*p)->next) {
if (*p == NULL) {
Py_FatalError("NULL interpreter");
@@ -577,9 +1714,12 @@ _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime)
PyInterpreterState *
PyInterpreterState_Get(void)
{
- PyThreadState *tstate = _PyThreadState_GET();
+ PyThreadState *tstate;
+ PyInterpreterState *interp;
+
+ tstate = _PyThreadState_GET();
_Py_EnsureTstateNotNULL(tstate);
- PyInterpreterState *interp = tstate->interp;
+ interp = tstate->interp;
if (interp == NULL) {
Py_FatalError("no current interpreter");
}
@@ -667,20 +1807,25 @@ _PyInterpreterState_IDIncref(PyInterpreterState *interp)
void
_PyInterpreterState_IDDecref(PyInterpreterState *interp)
{
+ struct _gilstate_runtime_state *gilstate;
+ int64_t refcount;
+ PyThreadState *tstate;
+ PyThreadState *save_tstate;
+
assert(interp->id_mutex != NULL);
- struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
+ gilstate = &_PyRuntime.gilstate;
PyThread_acquire_lock(interp->id_mutex, WAIT_LOCK);
assert(interp->id_refcount != 0);
interp->id_refcount -= 1;
- int64_t refcount = interp->id_refcount;
+ refcount = interp->id_refcount;
PyThread_release_lock(interp->id_mutex);
if (refcount == 0 && interp->requires_idref) {
// XXX Using the "head" thread isn't strictly correct.
- PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
+ tstate = PyInterpreterState_ThreadHead(interp);
// XXX Possible GILState issues?
- PyThreadState *save_tstate = _PyThreadState_Swap(gilstate, tstate);
+ save_tstate = _PyThreadState_Swap(gilstate, tstate);
Py_EndInterpreter(tstate);
_PyThreadState_Swap(gilstate, save_tstate);
}
@@ -727,8 +1872,10 @@ PyInterpreterState_GetDict(PyInterpreterState *interp)
static _PyStackChunk*
allocate_chunk(int size_in_bytes, _PyStackChunk* previous)
{
+ _PyStackChunk *res;
+
assert(size_in_bytes % sizeof(PyObject **) == 0);
- _PyStackChunk *res = _PyObject_VirtualAlloc(size_in_bytes);
+ res = _PyObject_VirtualAlloc(size_in_bytes);
if (res == NULL) {
return NULL;
}
@@ -807,12 +1954,15 @@ new_threadstate(PyInterpreterState *interp)
{
PyThreadState *tstate;
_PyRuntimeState *runtime = interp->runtime;
+ PyThreadState *new_tstate;
+ int used_newtstate;
+ uint64_t id;
+ PyThreadState *old_head;
// We don't need to allocate a thread state for the main interpreter
// (the common case), but doing it later for the other case revealed a
// reentrancy problem (deadlock). So for now we always allocate before
// taking the interpreters lock. See GH-96071.
- PyThreadState *new_tstate = alloc_threadstate();
- int used_newtstate;
+ new_tstate = alloc_threadstate();
if (new_tstate == NULL) {
return NULL;
}
@@ -820,10 +1970,10 @@ new_threadstate(PyInterpreterState *interp)
HEAD_LOCK(runtime);
interp->threads.next_unique_id += 1;
- uint64_t id = interp->threads.next_unique_id;
+ id = interp->threads.next_unique_id;
// Allocate the thread state and add it to the interpreter.
- PyThreadState *old_head = interp->threads.head;
+ old_head = interp->threads.head;
if (old_head == NULL) {
// It's the interpreter's initial thread state.
assert(id == 1);
@@ -838,9 +1988,14 @@ new_threadstate(PyInterpreterState *interp)
used_newtstate = 1;
tstate = new_tstate;
// Set to _PyThreadState_INIT.
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ memset(tstate, 0, sizeof(*tstate));
+ init_static_threadstate(tstate);
+#else
memcpy(tstate,
&initial._main_interpreter._initial_thread,
sizeof(*tstate));
+#endif
// We need to adjust any fields that are different from the initial
// thread (as defined in _PyThreadState_INIT):
tstate->_static = false;
@@ -911,6 +2066,8 @@ PyState_FindModule(PyModuleDef* module)
int
_PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
{
+ PyInterpreterState *interp;
+
if (!def) {
assert(_PyErr_Occurred(tstate));
return -1;
@@ -922,7 +2079,7 @@ _PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
return -1;
}
- PyInterpreterState *interp = tstate->interp;
+ interp = tstate->interp;
if (!interp->modules_by_index) {
interp->modules_by_index = PyList_New(0);
if (!interp->modules_by_index) {
@@ -944,14 +2101,18 @@ _PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
int
PyState_AddModule(PyObject* module, PyModuleDef* def)
{
+ PyThreadState *tstate;
+ PyInterpreterState *interp;
+ Py_ssize_t index;
+
if (!def) {
Py_FatalError("module definition is NULL");
return -1;
}
- PyThreadState *tstate = _PyThreadState_GET();
- PyInterpreterState *interp = tstate->interp;
- Py_ssize_t index = def->m_base.m_index;
+ tstate = _PyThreadState_GET();
+ interp = tstate->interp;
+ index = def->m_base.m_index;
if (interp->modules_by_index &&
index < PyList_GET_SIZE(interp->modules_by_index) &&
module == PyList_GET_ITEM(interp->modules_by_index, index))
@@ -965,8 +2126,12 @@ PyState_AddModule(PyObject* module, PyModuleDef* def)
int
PyState_RemoveModule(PyModuleDef* def)
{
- PyThreadState *tstate = _PyThreadState_GET();
- PyInterpreterState *interp = tstate->interp;
+ PyThreadState *tstate;
+ PyInterpreterState *interp;
+ Py_ssize_t index;
+
+ tstate = _PyThreadState_GET();
+ interp = tstate->interp;
if (def->m_slots) {
_PyErr_SetString(tstate,
@@ -975,7 +2140,7 @@ PyState_RemoveModule(PyModuleDef* def)
return -1;
}
- Py_ssize_t index = def->m_base.m_index;
+ index = def->m_base.m_index;
if (index == 0) {
Py_FatalError("invalid module index");
}
@@ -994,16 +2159,18 @@ PyState_RemoveModule(PyModuleDef* def)
void
_PyInterpreterState_ClearModules(PyInterpreterState *interp)
{
+ Py_ssize_t i;
+
if (!interp->modules_by_index) {
return;
}
- Py_ssize_t i;
for (i = 0; i < PyList_GET_SIZE(interp->modules_by_index); i++) {
PyObject *m = PyList_GET_ITEM(interp->modules_by_index, i);
if (PyModule_Check(m)) {
+ PyModuleDef *md;
/* cleanup the saved copy of module dicts */
- PyModuleDef *md = PyModule_GetDef(m);
+ md = PyModule_GetDef(m);
if (md) {
Py_CLEAR(md->m_base.m_copy);
}
@@ -1074,12 +2241,16 @@ static void
tstate_delete_common(PyThreadState *tstate,
struct _gilstate_runtime_state *gilstate)
{
+ PyInterpreterState *interp;
+ _PyRuntimeState *runtime;
+ _PyStackChunk *chunk;
+
_Py_EnsureTstateNotNULL(tstate);
- PyInterpreterState *interp = tstate->interp;
+ interp = tstate->interp;
if (interp == NULL) {
Py_FatalError("NULL interpreter");
}
- _PyRuntimeState *runtime = interp->runtime;
+ runtime = interp->runtime;
HEAD_LOCK(runtime);
if (tstate->prev) {
@@ -1098,7 +2269,7 @@ tstate_delete_common(PyThreadState *tstate,
{
PyThread_tss_set(&gilstate->autoTSSkey, NULL);
}
- _PyStackChunk *chunk = tstate->datastack_chunk;
+ chunk = tstate->datastack_chunk;
tstate->datastack_chunk = NULL;
while (chunk != NULL) {
_PyStackChunk *prev = chunk->previous;
@@ -1131,8 +2302,10 @@ PyThreadState_Delete(PyThreadState *tstate)
void
_PyThreadState_DeleteCurrent(PyThreadState *tstate)
{
+ struct _gilstate_runtime_state *gilstate;
+
_Py_EnsureTstateNotNULL(tstate);
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
+ gilstate = &tstate->interp->runtime->gilstate;
tstate_delete_common(tstate, gilstate);
_PyRuntimeGILState_SetThreadState(gilstate, NULL);
_PyEval_ReleaseLock(tstate);
@@ -1159,12 +2332,14 @@ void
_PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate)
{
PyInterpreterState *interp = tstate->interp;
+ PyThreadState *list;
+ PyThreadState *p, *next;
HEAD_LOCK(runtime);
/* Remove all thread states, except tstate, from the linked list of
thread states. This will allow calling PyThreadState_Clear()
without holding the lock. */
- PyThreadState *list = interp->threads.head;
+ list = interp->threads.head;
if (list == tstate) {
list = tstate->next;
}
@@ -1181,7 +2356,6 @@ _PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate)
/* Clear and deallocate all stale thread states. Even if this
executes Python code, we should be safe since it executes
in the current thread, not one of the stale threads. */
- PyThreadState *p, *next;
for (p = list; p; p = next) {
next = p->next;
PyThreadState_Clear(p);
@@ -1279,15 +2453,18 @@ PyThreadState_GetInterpreter(PyThreadState *tstate)
PyFrameObject*
PyThreadState_GetFrame(PyThreadState *tstate)
{
+ _PyInterpreterFrame *f;
+ PyFrameObject *frame;
+
assert(tstate != NULL);
- _PyInterpreterFrame *f = tstate->cframe->current_frame;
+ f = tstate->cframe->current_frame;
while (f && _PyFrame_IsIncomplete(f)) {
f = f->previous;
}
if (f == NULL) {
return NULL;
}
- PyFrameObject *frame = _PyFrame_GetFrameObject(f);
+ frame = _PyFrame_GetFrameObject(f);
if (frame == NULL) {
PyErr_Clear();
}
@@ -1317,6 +2494,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
{
_PyRuntimeState *runtime = &_PyRuntime;
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
+ PyThreadState *tstate;
/* Although the GIL is held, a few C API functions can be called
* without the GIL held, and in particular some that create and
@@ -1325,7 +2503,9 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
* head_mutex for the duration.
*/
HEAD_LOCK(runtime);
- for (PyThreadState *tstate = interp->threads.head; tstate != NULL; tstate = tstate->next) {
+ for (tstate = interp->threads.head; tstate != NULL; tstate = tstate->next) {
+ PyObject *old_exc;
+
if (tstate->thread_id != id) {
continue;
}
@@ -1337,7 +2517,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
* deadlock, we need to release head_mutex before
* the decref.
*/
- PyObject *old_exc = tstate->async_exc;
+ old_exc = tstate->async_exc;
Py_XINCREF(exc);
tstate->async_exc = exc;
HEAD_UNLOCK(runtime);
@@ -1389,17 +2569,22 @@ PyObject *
_PyThread_CurrentFrames(void)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *result;
+ int gc_was_enabled;
+ _PyRuntimeState *runtime;
+ PyInterpreterState *i;
+
if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) {
return NULL;
}
- PyObject *result = PyDict_New();
+ result = PyDict_New();
if (result == NULL) {
return NULL;
}
// gh-106883: Disable the GC as this can cause the interpreter to deadlock
- int gc_was_enabled = PyGC_Disable();
+ gc_was_enabled = PyGC_Disable();
/* for i in all interpreters:
* for t in all of i's thread states:
@@ -1407,29 +2592,33 @@ _PyThread_CurrentFrames(void)
* Because these lists can mutate even when the GIL is held, we
* need to grab head_mutex for the duration.
*/
- _PyRuntimeState *runtime = tstate->interp->runtime;
+ runtime = tstate->interp->runtime;
HEAD_LOCK(runtime);
- PyInterpreterState *i;
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
PyThreadState *t;
for (t = i->threads.head; t != NULL; t = t->next) {
- _PyInterpreterFrame *frame = t->cframe->current_frame;
+ _PyInterpreterFrame *frame;
+ PyObject *id;
+ PyObject *frameobj;
+ int stat;
+
+ frame = t->cframe->current_frame;
while (frame && _PyFrame_IsIncomplete(frame)) {
frame = frame->previous;
}
if (frame == NULL) {
continue;
}
- PyObject *id = PyLong_FromUnsignedLong(t->thread_id);
+ id = PyLong_FromUnsignedLong(t->thread_id);
if (id == NULL) {
goto fail;
}
- PyObject *frameobj = (PyObject *)_PyFrame_GetFrameObject(frame);
+ frameobj = (PyObject *)_PyFrame_GetFrameObject(frame);
if (frameobj == NULL) {
Py_DECREF(id);
goto fail;
}
- int stat = PyDict_SetItem(result, id, frameobj);
+ stat = PyDict_SetItem(result, id, frameobj);
Py_DECREF(id);
if (stat < 0) {
goto fail;
@@ -1456,6 +2645,10 @@ PyObject *
_PyThread_CurrentExceptions(void)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *result;
+ int gc_was_enabled;
+ _PyRuntimeState *runtime;
+ PyInterpreterState *i;
_Py_EnsureTstateNotNULL(tstate);
@@ -1463,13 +2656,13 @@ _PyThread_CurrentExceptions(void)
return NULL;
}
- PyObject *result = PyDict_New();
+ result = PyDict_New();
if (result == NULL) {
return NULL;
}
// gh-106883: Disable the GC as this can cause the interpreter to deadlock
- int gc_was_enabled = PyGC_Disable();
+ gc_was_enabled = PyGC_Disable();
/* for i in all interpreters:
* for t in all of i's thread states:
@@ -1477,26 +2670,30 @@ _PyThread_CurrentExceptions(void)
* Because these lists can mutate even when the GIL is held, we
* need to grab head_mutex for the duration.
*/
- _PyRuntimeState *runtime = tstate->interp->runtime;
+ runtime = tstate->interp->runtime;
HEAD_LOCK(runtime);
- PyInterpreterState *i;
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
PyThreadState *t;
for (t = i->threads.head; t != NULL; t = t->next) {
- _PyErr_StackItem *err_info = _PyErr_GetTopmostException(t);
+ _PyErr_StackItem *err_info;
+ PyObject *id;
+ PyObject *exc_info;
+ int stat;
+
+ err_info = _PyErr_GetTopmostException(t);
if (err_info == NULL) {
continue;
}
- PyObject *id = PyLong_FromUnsignedLong(t->thread_id);
+ id = PyLong_FromUnsignedLong(t->thread_id);
if (id == NULL) {
goto fail;
}
- PyObject *exc_info = _PyErr_StackItemToExcInfoTuple(err_info);
+ exc_info = _PyErr_StackItemToExcInfoTuple(err_info);
if (exc_info == NULL) {
Py_DECREF(id);
goto fail;
}
- int stat = PyDict_SetItem(result, id, exc_info);
+ stat = PyDict_SetItem(result, id, exc_info);
Py_DECREF(id);
Py_DECREF(exc_info);
if (stat < 0) {
@@ -1559,6 +2756,8 @@ _PyGILState_Init(_PyRuntimeState *runtime)
PyStatus
_PyGILState_SetTstate(PyThreadState *tstate)
{
+ struct _gilstate_runtime_state *gilstate;
+
if (!_Py_IsMainInterpreter(tstate->interp)) {
/* Currently, PyGILState is shared by all interpreters. The main
* interpreter is responsible to initialize it. */
@@ -1569,7 +2768,7 @@ _PyGILState_SetTstate(PyThreadState *tstate)
assert(tstate != NULL);
assert(tstate->interp != NULL);
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
+ gilstate = &tstate->interp->runtime->gilstate;
gilstate->autoInterpreterState = tstate->interp;
assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL);
@@ -1676,6 +2875,7 @@ int
PyGILState_Check(void)
{
struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
+ PyThreadState *tstate;
if (!gilstate->check_enabled) {
return 1;
}
@@ -1684,7 +2884,7 @@ PyGILState_Check(void)
return 1;
}
- PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
+ tstate = _PyRuntimeGILState_GetThreadState(gilstate);
if (tstate == NULL) {
return 0;
}
@@ -1697,6 +2897,8 @@ PyGILState_Ensure(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
struct _gilstate_runtime_state *gilstate = &runtime->gilstate;
+ PyThreadState *tcur;
+ int current;
/* Note that we do not auto-init Python here - apart from
potential races with 2 threads auto-initializing, pep-311
@@ -1708,8 +2910,7 @@ PyGILState_Ensure(void)
assert(_PyEval_ThreadsInitialized(runtime));
assert(gilstate->autoInterpreterState);
- PyThreadState *tcur = (PyThreadState *)PyThread_tss_get(&gilstate->autoTSSkey);
- int current;
+ tcur = (PyThreadState *)PyThread_tss_get(&gilstate->autoTSSkey);
if (tcur == NULL) {
/* Create a new Python thread state for this thread */
tcur = PyThreadState_New(gilstate->autoInterpreterState);
@@ -1841,24 +3042,27 @@ int
_PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyInterpreterState *interp;
+ crossinterpdatafunc getdata;
+ int res;
#ifdef Py_DEBUG
// The caller must hold the GIL
_Py_EnsureTstateNotNULL(tstate);
#endif
- PyInterpreterState *interp = tstate->interp;
+ interp = tstate->interp;
// Reset data before re-populating.
- *data = (_PyCrossInterpreterData){0};
+ memset(data, 0, sizeof(*data));
data->free = PyMem_RawFree; // Set a default that may be overridden.
// Call the "getdata" func for the object.
Py_INCREF(obj);
- crossinterpdatafunc getdata = _lookup_getdata(obj);
+ getdata = _lookup_getdata(obj);
if (getdata == NULL) {
Py_DECREF(obj);
return -1;
}
- int res = getdata(obj, data);
+ res = getdata(obj, data);
Py_DECREF(obj);
if (res != 0) {
return -1;
@@ -1912,13 +3116,16 @@ _call_in_interpreter(struct _gilstate_runtime_state *gilstate,
void
_PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
{
+ PyInterpreterState *interp;
+ struct _gilstate_runtime_state *gilstate;
+
if (data->data == NULL && data->obj == NULL) {
// Nothing to release!
return;
}
// Switch to the original interpreter.
- PyInterpreterState *interp = _PyInterpreterState_LookUpID(data->interp);
+ interp = _PyInterpreterState_LookUpID(data->interp);
if (interp == NULL) {
// The interpreter was already destroyed.
if (data->free != NULL) {
@@ -1928,7 +3135,7 @@ _PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
}
// "Release" the data and/or the object.
- struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
+ gilstate = &_PyRuntime.gilstate;
_call_in_interpreter(gilstate, interp, _release_xidata, data);
}
@@ -1966,6 +3173,9 @@ int
_PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
crossinterpdatafunc getdata)
{
+ struct _xidregistry *xidregistry;
+ int res;
+
if (!PyType_Check(cls)) {
PyErr_Format(PyExc_ValueError, "only classes may be registered");
return -1;
@@ -1978,12 +3188,12 @@ _PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
// Make sure the class isn't ever deallocated.
Py_INCREF((PyObject *)cls);
- struct _xidregistry *xidregistry = &_PyRuntime.xidregistry ;
+ xidregistry = &_PyRuntime.xidregistry;
PyThread_acquire_lock(xidregistry->mutex, WAIT_LOCK);
if (xidregistry->head == NULL) {
_register_builtins_for_crossinterpreter_data(xidregistry);
}
- int res = _register_xidata(xidregistry, cls, getdata);
+ res = _register_xidata(xidregistry, cls, getdata);
PyThread_release_lock(xidregistry->mutex);
return res;
}
@@ -1995,11 +3205,13 @@ _PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
crossinterpdatafunc
_PyCrossInterpreterData_Lookup(PyObject *obj)
{
- struct _xidregistry *xidregistry = &_PyRuntime.xidregistry ;
+ struct _xidregistry *xidregistry = &_PyRuntime.xidregistry;
PyObject *cls = PyObject_Type(obj);
crossinterpdatafunc getdata = NULL;
+ struct _xidregitem *cur;
+
PyThread_acquire_lock(xidregistry->mutex, WAIT_LOCK);
- struct _xidregitem *cur = xidregistry->head;
+ cur = xidregistry->head;
if (cur == NULL) {
_register_builtins_for_crossinterpreter_data(xidregistry);
cur = xidregistry->head;
@@ -2189,8 +3401,10 @@ _PyInterpreterState_GetConfigCopy(PyConfig *config)
const PyConfig*
_Py_GetConfig(void)
{
+ PyThreadState *tstate;
+
assert(PyGILState_Check());
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
return _PyInterpreterState_GetConfig(tstate->interp);
}
@@ -2200,10 +3414,13 @@ static PyObject **
push_chunk(PyThreadState *tstate, int size)
{
int allocate_size = DATA_STACK_CHUNK_SIZE;
+ _PyStackChunk *new;
+ PyObject **res;
+
while (allocate_size < (int)sizeof(PyObject*)*(size + MINIMUM_OVERHEAD)) {
allocate_size *= 2;
}
- _PyStackChunk *new = allocate_chunk(allocate_size, tstate->datastack_chunk);
+ new = allocate_chunk(allocate_size, tstate->datastack_chunk);
if (new == NULL) {
return NULL;
}
@@ -2216,7 +3433,7 @@ push_chunk(PyThreadState *tstate, int size)
// When new is the "root" chunk (i.e. new->previous == NULL), we can keep
// _PyThreadState_PopFrame from freeing it later by "skipping" over the
// first element:
- PyObject **res = &new->data[new->previous == NULL];
+ res = &new->data[new->previous == NULL];
tstate->datastack_top = res + size;
return res;
}
@@ -2239,8 +3456,10 @@ _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size)
void
_PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * frame)
{
+ PyObject **base;
+
assert(tstate->datastack_chunk);
- PyObject **base = (PyObject **)frame;
+ base = (PyObject **)frame;
if (base == &tstate->datastack_chunk->data[0]) {
_PyStackChunk *chunk = tstate->datastack_chunk;
_PyStackChunk *previous = chunk->previous;