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

21370 lines
755 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/cpython/pytime.h b/Include/cpython/pytime.h
index 23d4f16..929bf04 100644
--- a/Include/cpython/pytime.h
+++ b/Include/cpython/pytime.h
@@ -58,9 +58,14 @@ extern "C" {
UNIX epoch). */
typedef int64_t _PyTime_t;
// _PyTime_MIN nanoseconds is around -292.3 years
-#define _PyTime_MIN INT64_MIN
// _PyTime_MAX nanoseconds is around +292.3 years
-#define _PyTime_MAX INT64_MAX
+#if defined(_MSC_VER) && _MSC_VER < 1300
+# define _PyTime_MIN PY_LLONG_MIN
+# define _PyTime_MAX PY_LLONG_MAX
+#else
+# define _PyTime_MIN INT64_MIN
+# define _PyTime_MAX INT64_MAX
+#endif
#define _SIZEOF_PYTIME_T 8
typedef enum {
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_bitutils.h b/Include/internal/pycore_bitutils.h
index e6bf61e..ba46128 100644
--- a/Include/internal/pycore_bitutils.h
+++ b/Include/internal/pycore_bitutils.h
@@ -25,7 +25,7 @@ extern "C" {
# define _PY_HAVE_BUILTIN_BSWAP
#endif
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && _MSC_VER >= 1300
/* Get _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() */
# include <intrin.h>
#endif
@@ -35,7 +35,7 @@ _Py_bswap16(uint16_t word)
{
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap16)
return __builtin_bswap16(word);
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned short));
return _byteswap_ushort(word);
#else
@@ -50,7 +50,7 @@ _Py_bswap32(uint32_t word)
{
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap32)
return __builtin_bswap32(word);
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned long));
return _byteswap_ulong(word);
#else
@@ -67,7 +67,7 @@ _Py_bswap64(uint64_t word)
{
#if defined(_PY_HAVE_BUILTIN_BSWAP) || _Py__has_builtin(__builtin_bswap64)
return __builtin_bswap64(word);
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
return _byteswap_uint64(word);
#else
// Portable implementation which doesn't rely on circular bit shift
@@ -154,7 +154,7 @@ _Py_bit_length(unsigned long x)
else {
return 0;
}
-#elif defined(_MSC_VER)
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
// _BitScanReverse() is documented to search 32 bits.
Py_BUILD_ASSERT(sizeof(unsigned long) <= 4);
unsigned long msb;
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_pystate.h b/Include/internal/pycore_pystate.h
index 7c5aba1..8818e63 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -101,6 +101,11 @@ _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
}
}
+/* Visual C++ 6.0 predates C99's __func__ identifier. */
+#if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(__func__)
+# define __func__ "<unknown>"
+#endif
+
// Call Py_FatalError() if tstate is NULL
#define _Py_EnsureTstateNotNULL(tstate) \
_Py_EnsureFuncTstateNotNULL(__func__, tstate)
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..58b5d58 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -13,6 +13,11 @@
# error "Python's source code assumes C's unsigned char is an 8-bit type"
#endif
+/* Visual C++ 6.0 predates C99's __func__ identifier. */
+#if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(__func__)
+# define __func__ "<unknown>"
+#endif
+
// Macro to use C++ static_cast<> in the Python C API.
#ifdef __cplusplus
@@ -97,6 +102,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 +346,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 +367,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 +444,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/_io/_iomodule.c b/Modules/_io/_iomodule.c
index aa87717..6395120 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -472,6 +472,7 @@ static PyObject *
_io_text_encoding_impl(PyObject *module, PyObject *encoding, int stacklevel)
/*[clinic end generated code: output=91b2cfea6934cc0c input=4999aa8b3d90f3d4]*/
{
+ const PyPreConfig *preconfig;
if (encoding == NULL || encoding == Py_None) {
PyInterpreterState *interp = _PyInterpreterState_GET();
if (_PyInterpreterState_GetConfig(interp)->warn_default_encoding) {
@@ -480,7 +481,7 @@ _io_text_encoding_impl(PyObject *module, PyObject *encoding, int stacklevel)
return NULL;
}
}
- const PyPreConfig *preconfig = &_PyRuntime.preconfig;
+ preconfig = &_PyRuntime.preconfig;
if (preconfig->utf8_mode) {
_Py_DECLARE_STR(utf_8, "utf-8");
encoding = &_Py_STR(utf_8);
@@ -670,7 +671,8 @@ static PyTypeObject* static_types[] = {
void
_PyIO_Fini(void)
{
- for (Py_ssize_t i=Py_ARRAY_LENGTH(static_types) - 1; i >= 0; i--) {
+ Py_ssize_t i;
+ for (i = Py_ARRAY_LENGTH(static_types) - 1; i >= 0; i--) {
PyTypeObject *exc = static_types[i];
_PyStaticType_Dealloc(exc);
}
@@ -680,6 +682,7 @@ _PyIO_Fini(void)
PyMODINIT_FUNC
PyInit__io(void)
{
+ size_t i;
PyObject *m = PyModule_Create(&_PyIO_Module);
_PyIO_State *state = NULL;
if (m == NULL)
@@ -722,7 +725,7 @@ PyInit__io(void)
PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type;
// Add types
- for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) {
+ for (i = 0; i < Py_ARRAY_LENGTH(static_types); i++) {
PyTypeObject *type = static_types[i];
// Private type not exposed in the _io module
if (type == &_PyBytesIOBuffer_Type) {
diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h
index c260080..c53ada0 100644
--- a/Modules/_io/_iomodule.h
+++ b/Modules/_io/_iomodule.h
@@ -92,12 +92,12 @@ extern int _PyIO_trap_eintr(void);
#ifdef MS_WINDOWS
/* Windows uses long long for offsets */
-typedef long long Py_off_t;
+typedef PY_LONG_LONG Py_off_t;
# define PyLong_AsOff_t PyLong_AsLongLong
# define PyLong_FromOff_t PyLong_FromLongLong
-# define PY_OFF_T_MAX LLONG_MAX
-# define PY_OFF_T_MIN LLONG_MIN
-# define PY_OFF_T_COMPAT long long /* type compatible with off_t */
+# define PY_OFF_T_MAX PY_LLONG_MAX
+# define PY_OFF_T_MIN PY_LLONG_MIN
+# define PY_OFF_T_COMPAT PY_LONG_LONG /* type compatible with off_t */
# define PY_PRIdOFF "lld" /* format to use for that type */
#else
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index e84eef4..0435b44 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -124,12 +124,13 @@ unshare_buffer(bytesio *self, size_t size)
static int
resize_buffer(bytesio *self, size_t size)
{
+ size_t alloc;
assert(self->buf != NULL);
assert(self->exports == 0);
/* Here, unsigned types are used to avoid dealing with signed integer
overflow, which is undefined in C. */
- size_t alloc = PyBytes_GET_SIZE(self->buf);
+ alloc = PyBytes_GET_SIZE(self->buf);
/* For simplicity, stay in the range of the signed type. Anyway, Python
doesn't allow strings to be longer than this. */
@@ -180,6 +181,9 @@ resize_buffer(bytesio *self, size_t size)
Py_NO_INLINE static Py_ssize_t
write_bytes(bytesio *self, PyObject *b)
{
+ Py_buffer buf;
+ Py_ssize_t len;
+ size_t endpos;
if (check_closed(self)) {
return -1;
}
@@ -187,17 +191,16 @@ write_bytes(bytesio *self, PyObject *b)
return -1;
}
- Py_buffer buf;
if (PyObject_GetBuffer(b, &buf, PyBUF_CONTIG_RO) < 0) {
return -1;
}
- Py_ssize_t len = buf.len;
+ len = buf.len;
if (len == 0) {
goto done;
}
assert(self->pos >= 0);
- size_t endpos = (size_t)self->pos + len;
+ endpos = (size_t)self->pos + len;
if (endpos > (size_t)PyBytes_GET_SIZE(self->buf)) {
if (resize_buffer(self, endpos) < 0) {
len = -1;
diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h
index 0249dd1..9e774ef 100644
--- a/Modules/_io/clinic/_iomodule.c.h
+++ b/Modules/_io/clinic/_iomodule.c.h
@@ -145,6 +145,7 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
const char *newline = NULL;
int closefd = 1;
PyObject *opener = Py_None;
+ Py_ssize_t mode_length;
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 8, 0, argsbuf);
if (!args) {
@@ -159,7 +160,6 @@ _io_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
_PyArg_BadArgument("open", "argument 'mode'", "str", args[1]);
goto exit;
}
- Py_ssize_t mode_length;
mode = PyUnicode_AsUTF8AndSize(args[1], &mode_length);
if (mode == NULL) {
goto exit;
diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h
index bb0b36c..53f18c3 100644
--- a/Modules/_io/clinic/fileio.c.h
+++ b/Modules/_io/clinic/fileio.c.h
@@ -59,6 +59,7 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
const char *mode = "r";
int closefd = 1;
PyObject *opener = Py_None;
+ Py_ssize_t mode_length;
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 4, 0, argsbuf);
if (!fastargs) {
@@ -73,7 +74,6 @@ _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("FileIO", "argument 'mode'", "str", fastargs[1]);
goto exit;
}
- Py_ssize_t mode_length;
mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length);
if (mode == NULL) {
goto exit;
diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h
index 75102a3..dc45220 100644
--- a/Modules/_io/clinic/winconsoleio.c.h
+++ b/Modules/_io/clinic/winconsoleio.c.h
@@ -58,6 +58,7 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
const char *mode = "r";
int closefd = 1;
PyObject *opener = Py_None;
+ Py_ssize_t mode_length;
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 4, 0, argsbuf);
if (!fastargs) {
@@ -72,7 +73,6 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("_WindowsConsoleIO", "argument 'mode'", "str", fastargs[1]);
goto exit;
}
- Py_ssize_t mode_length;
mode = PyUnicode_AsUTF8AndSize(fastargs[1], &mode_length);
if (mode == NULL) {
goto exit;
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index e9dd85f..011d17d 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -507,7 +507,7 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)
/*[clinic end generated code: output=f0d2c9c136f4e0d0 input=f8ff101825e32e7f]*/
{
PyObject *buffer;
- unsigned long long flag;
+ unsigned PY_LONG_LONG flag;
CHECK_INITIALIZED_DECODER(self);
@@ -553,7 +553,7 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self,
/*[clinic end generated code: output=c10c622508b576cb input=c53fb505a76dbbe2]*/
{
PyObject *buffer;
- unsigned long long flag;
+ unsigned PY_LONG_LONG flag;
CHECK_INITIALIZED_DECODER(self);
@@ -950,19 +950,22 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info,
static int
_textiowrapper_fix_encoder_state(textio *self)
{
+ PyObject *cookieObj;
+ PyObject *res;
+ int cmp;
if (!self->seekable || !self->encoder) {
return 0;
}
self->encoding_start_of_stream = 1;
- PyObject *cookieObj = PyObject_CallMethodNoArgs(
+ cookieObj = PyObject_CallMethodNoArgs(
self->buffer, &_Py_ID(tell));
if (cookieObj == NULL) {
return -1;
}
- int cmp = PyObject_RichCompareBool(cookieObj, _PyLong_GetZero(), Py_EQ);
+ cmp = PyObject_RichCompareBool(cookieObj, _PyLong_GetZero(), Py_EQ);
Py_DECREF(cookieObj);
if (cmp < 0) {
return -1;
@@ -970,7 +973,7 @@ _textiowrapper_fix_encoder_state(textio *self)
if (cmp == 0) {
self->encoding_start_of_stream = 0;
- PyObject *res = PyObject_CallMethodOneArg(
+ res = PyObject_CallMethodOneArg(
self->encoder, &_Py_ID(setstate), _PyLong_GetZero());
if (res == NULL) {
return -1;
@@ -984,9 +987,13 @@ _textiowrapper_fix_encoder_state(textio *self)
static int
io_check_errors(PyObject *errors)
{
+ PyInterpreterState *interp;
+ Py_ssize_t name_length;
+ const char *name;
+ PyObject *handler;
assert(errors != NULL && errors != Py_None);
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ interp = _PyInterpreterState_GET();
#ifndef Py_DEBUG
/* In release mode, only check in development mode (-X dev) */
if (!_PyInterpreterState_GetConfig(interp)->dev_mode) {
@@ -1002,8 +1009,7 @@ io_check_errors(PyObject *errors)
return 0;
}
- Py_ssize_t name_length;
- const char *name = PyUnicode_AsUTF8AndSize(errors, &name_length);
+ name = PyUnicode_AsUTF8AndSize(errors, &name_length);
if (name == NULL) {
return -1;
}
@@ -1011,7 +1017,7 @@ io_check_errors(PyObject *errors)
PyErr_SetString(PyExc_ValueError, "embedded null character in errors");
return -1;
}
- PyObject *handler = PyCodec_LookupError(name);
+ handler = PyCodec_LookupError(name);
if (handler != NULL) {
Py_DECREF(handler);
return 0;
@@ -1069,6 +1075,8 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
{
PyObject *raw, *codec_info = NULL;
PyObject *res;
+ Py_ssize_t errors_len;
+ const char *errors_str;
int r;
self->ok = 0;
@@ -1099,8 +1107,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
else if (io_check_errors(errors)) {
return -1;
}
- Py_ssize_t errors_len;
- const char *errors_str = PyUnicode_AsUTF8AndSize(errors, &errors_len);
+ errors_str = PyUnicode_AsUTF8AndSize(errors, &errors_len);
if (errors_str == NULL) {
return -1;
}
@@ -1256,6 +1263,9 @@ static int
textiowrapper_change_encoding(textio *self, PyObject *encoding,
PyObject *errors, int newline_changed)
{
+ const char *c_encoding;
+ const char *c_errors;
+ PyObject *codec_info;
/* Use existing settings where new settings are not specified */
if (encoding == Py_None && errors == Py_None && !newline_changed) {
return 0; // no change
@@ -1283,13 +1293,13 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
}
Py_INCREF(errors);
- const char *c_encoding = PyUnicode_AsUTF8(encoding);
+ c_encoding = PyUnicode_AsUTF8(encoding);
if (c_encoding == NULL) {
Py_DECREF(encoding);
Py_DECREF(errors);
return -1;
}
- const char *c_errors = PyUnicode_AsUTF8(errors);
+ c_errors = PyUnicode_AsUTF8(errors);
if (c_errors == NULL) {
Py_DECREF(encoding);
Py_DECREF(errors);
@@ -1297,7 +1307,7 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding,
}
// Create new encoder & decoder
- PyObject *codec_info = _PyCodec_LookupTextEncoding(
+ codec_info = _PyCodec_LookupTextEncoding(
c_encoding, "codecs.open()");
if (codec_info == NULL) {
Py_DECREF(encoding);
@@ -1344,6 +1354,7 @@ _io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding,
int line_buffering;
int write_through;
const char *newline = NULL;
+ PyObject *res;
if (encoding != Py_None && !PyUnicode_Check(encoding)) {
PyErr_Format(PyExc_TypeError,
@@ -1392,7 +1403,7 @@ _io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding,
return NULL;
}
- PyObject *res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
+ res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL) {
return NULL;
}
@@ -1546,11 +1557,16 @@ _io_TextIOWrapper_detach_impl(textio *self)
static int
_textiowrapper_writeflush(textio *self)
{
+ PyObject *pending;
+ PyObject *b;
+ char *buf;
+ Py_ssize_t pos;
+ Py_ssize_t i;
+ PyObject *ret;
if (self->pending_bytes == NULL)
return 0;
- PyObject *pending = self->pending_bytes;
- PyObject *b;
+ pending = self->pending_bytes;
if (PyBytes_Check(pending)) {
b = pending;
@@ -1572,10 +1588,10 @@ _textiowrapper_writeflush(textio *self)
return -1;
}
- char *buf = PyBytes_AsString(b);
- Py_ssize_t pos = 0;
+ buf = PyBytes_AsString(b);
+ pos = 0;
- for (Py_ssize_t i = 0; i < PyList_GET_SIZE(pending); i++) {
+ for (i = 0; i < PyList_GET_SIZE(pending); i++) {
PyObject *obj = PyList_GET_ITEM(pending, i);
char *src;
Py_ssize_t len;
@@ -1601,7 +1617,6 @@ _textiowrapper_writeflush(textio *self)
self->pending_bytes = NULL;
Py_DECREF(pending);
- PyObject *ret;
do {
ret = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(write), b);
} while (ret == NULL && _PyIO_trap_eintr());
@@ -1627,6 +1642,8 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
PyObject *ret;
PyObject *b;
Py_ssize_t textlen;
+ Py_ssize_t bytes_len;
+ int list_ret;
int haslf = 0;
int needflush = 0, text_needflush = 0;
@@ -1692,7 +1709,6 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
return NULL;
}
- Py_ssize_t bytes_len;
if (b == text) {
bytes_len = PyUnicode_GET_LENGTH(b);
}
@@ -1745,9 +1761,9 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
}
}
- int ret = PyList_Append(self->pending_bytes, b);
+ list_ret = PyList_Append(self->pending_bytes, b);
Py_DECREF(b);
- if (ret < 0) {
+ if (list_ret < 0) {
return NULL;
}
}
@@ -1836,6 +1852,7 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
PyObject *decoded_chars, *chunk_size;
Py_ssize_t nbytes, nchars;
int eof;
+ PyObject *snapshot;
/* The return value is True unless EOF was reached. The decoded string is
* placed in self._decoded_chars (replacing its previous value). The
@@ -1935,7 +1952,7 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
if (next_input == NULL) {
goto fail;
}
- PyObject *snapshot = Py_BuildValue("NN", dec_flags, next_input);
+ snapshot = Py_BuildValue("NN", dec_flags, next_input);
if (snapshot == NULL) {
dec_flags = NULL;
goto fail;
@@ -2511,6 +2528,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
PyObject *res;
int cmp;
PyObject *snapshot;
+ PyObject *zero;
CHECK_ATTACHED(self);
CHECK_CLOSED(self);
@@ -2522,7 +2540,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
goto fail;
}
- PyObject *zero = _PyLong_GetZero(); // borrowed reference
+ zero = _PyLong_GetZero(); // borrowed reference
switch (whence) {
case SEEK_CUR:
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index dcb7d32..ca4ce32 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -62,18 +62,23 @@ char _get_console_type(HANDLE handle) {
}
char _PyIO_get_console_type(PyObject *path_or_fd) {
- int fd = PyLong_AsLong(path_or_fd);
+ int fd;
+ HANDLE handle;
+ PyObject *decoded;
+ wchar_t *decoded_wstr;
+ char m;
+ DWORD length;
+ wchar_t name_buf[MAX_PATH];
+ wchar_t *pname_buf;
+ fd = PyLong_AsLong(path_or_fd);
PyErr_Clear();
if (fd >= 0) {
- HANDLE handle = _Py_get_osfhandle_noraise(fd);
+ handle = _Py_get_osfhandle_noraise(fd);
if (handle == INVALID_HANDLE_VALUE)
return '\0';
return _get_console_type(handle);
}
- PyObject *decoded;
- wchar_t *decoded_wstr;
-
if (!PyUnicode_FSDecoder(path_or_fd, &decoded)) {
PyErr_Clear();
return '\0';
@@ -85,7 +90,7 @@ char _PyIO_get_console_type(PyObject *path_or_fd) {
return '\0';
}
- char m = '\0';
+ m = '\0';
if (!_wcsicmp(decoded_wstr, L"CONIN$")) {
m = 'r';
} else if (!_wcsicmp(decoded_wstr, L"CONOUT$")) {
@@ -98,9 +103,7 @@ char _PyIO_get_console_type(PyObject *path_or_fd) {
return m;
}
- DWORD length;
- wchar_t name_buf[MAX_PATH], *pname_buf = name_buf;
-
+ pname_buf = name_buf;
length = GetFullPathNameW(decoded_wstr, MAX_PATH, pname_buf, NULL);
if (length > MAX_PATH) {
pname_buf = PyMem_New(wchar_t, length);
@@ -519,7 +522,8 @@ _io__WindowsConsoleIO_writable_impl(winconsoleio *self)
static DWORD
_buflen(winconsoleio *self)
{
- for (DWORD i = 0; i < SMALLBUF; ++i) {
+ DWORD i;
+ for (i = 0; i < SMALLBUF; ++i) {
if (!self->buf[i])
return i;
}
@@ -529,11 +533,12 @@ _buflen(winconsoleio *self)
static DWORD
_copyfrombuf(winconsoleio *self, char *buf, DWORD len)
{
+ int i;
DWORD n = 0;
while (self->buf[0] && len--) {
buf[n++] = self->buf[0];
- for (int i = 1; i < SMALLBUF; ++i)
+ for (i = 1; i < SMALLBUF; ++i)
self->buf[i - 1] = self->buf[i];
self->buf[SMALLBUF - 1] = 0;
}
@@ -544,6 +549,8 @@ _copyfrombuf(winconsoleio *self, char *buf, DWORD len)
static wchar_t *
read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
int err = 0, sig = 0;
+ DWORD off;
+ HANDLE hInterruptEvent;
wchar_t *buf = (wchar_t*)PyMem_Malloc(maxlen * sizeof(wchar_t));
if (!buf)
@@ -553,12 +560,15 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
//DebugBreak();
Py_BEGIN_ALLOW_THREADS
- DWORD off = 0;
+ off = 0;
while (off < maxlen) {
- DWORD n = (DWORD)-1;
- DWORD len = min(maxlen - off, BUFSIZ);
+ DWORD n;
+ DWORD len;
+ BOOL res;
+ n = (DWORD)-1;
+ len = min(maxlen - off, BUFSIZ);
SetLastError(0);
- BOOL res = ReadConsoleW(handle, &buf[off], len, &n, NULL);
+ res = ReadConsoleW(handle, &buf[off], len, &n, NULL);
if (!res) {
err = GetLastError();
@@ -572,7 +582,7 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
if (err != ERROR_OPERATION_ABORTED)
break;
err = 0;
- HANDLE hInterruptEvent = _PyOS_SigintEvent();
+ hInterruptEvent = _PyOS_SigintEvent();
if (WaitForSingleObjectEx(hInterruptEvent, 100, FALSE)
== WAIT_OBJECT_0) {
ResetEvent(hInterruptEvent);
@@ -594,10 +604,9 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
break;
/* If the buffer ends with a high surrogate, expand the
buffer and read an extra character. */
- WORD char_type;
if (off + BUFSIZ >= maxlen &&
- GetStringTypeW(CT_CTYPE3, &buf[*readlen - 1], 1, &char_type) &&
- char_type == C3_HIGHSURROGATE) {
+ buf[*readlen - 1] >= 0xD800 &&
+ buf[*readlen - 1] <= 0xDBFF) {
wchar_t *newbuf;
maxlen += 1;
Py_BLOCK_THREADS
@@ -646,6 +655,14 @@ read_console_w(HANDLE handle, DWORD maxlen, DWORD *readlen) {
static Py_ssize_t
readinto(winconsoleio *self, char *buf, Py_ssize_t len)
{
+ HANDLE handle;
+ DWORD wlen;
+ DWORD read_len;
+ DWORD n;
+ wchar_t *wbuf;
+ int err;
+ DWORD u8n;
+
if (self->fd == -1) {
err_closed();
return -1;
@@ -661,7 +678,7 @@ readinto(winconsoleio *self, char *buf, Py_ssize_t len)
return -1;
}
- HANDLE handle = _Py_get_osfhandle(self->fd);
+ handle = _Py_get_osfhandle(self->fd);
if (handle == INVALID_HANDLE_VALUE)
return -1;
@@ -671,12 +688,12 @@ readinto(winconsoleio *self, char *buf, Py_ssize_t len)
If the caller requests fewer than 4 bytes, we buffer one
character.
*/
- DWORD wlen = (DWORD)(len / 4);
+ wlen = (DWORD)(len / 4);
if (wlen == 0) {
wlen = 1;
}
- DWORD read_len = _copyfrombuf(self, buf, (DWORD)len);
+ read_len = _copyfrombuf(self, buf, (DWORD)len);
if (read_len) {
buf = &buf[read_len];
len -= read_len;
@@ -685,8 +702,7 @@ readinto(winconsoleio *self, char *buf, Py_ssize_t len)
if (len == read_len || wlen == 0)
return read_len;
- DWORD n;
- wchar_t *wbuf = read_console_w(handle, wlen, &n);
+ wbuf = read_console_w(handle, wlen, &n);
if (wbuf == NULL)
return -1;
if (n == 0) {
@@ -694,8 +710,8 @@ readinto(winconsoleio *self, char *buf, Py_ssize_t len)
return read_len;
}
- int err = 0;
- DWORD u8n = 0;
+ err = 0;
+ u8n = 0;
Py_BEGIN_ALLOW_THREADS
if (len < 4) {
@@ -809,6 +825,7 @@ _io__WindowsConsoleIO_readall_impl(winconsoleio *self)
while (1) {
wchar_t *subbuf;
+ wchar_t *tmp;
if (len >= (Py_ssize_t)bufsize) {
DWORD newsize = new_buffersize(self, len);
@@ -823,7 +840,7 @@ _io__WindowsConsoleIO_readall_impl(winconsoleio *self)
}
bufsize = newsize;
- wchar_t *tmp = PyMem_Realloc(buf,
+ tmp = PyMem_Realloc(buf,
(bufsize + 1) * sizeof(wchar_t));
if (tmp == NULL) {
PyMem_Free(buf);
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/_opcode.c b/Modules/_opcode.c
index 4812716..ca8de7f 100644
--- a/Modules/_opcode.c
+++ b/Modules/_opcode.c
@@ -101,10 +101,14 @@ opcode_functions[] = {
static struct PyModuleDef opcodemodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_opcode",
- .m_doc = "Opcode support module.",
- .m_size = 0,
- .m_methods = opcode_functions
+ "_opcode",
+ "Opcode support module.",
+ 0,
+ opcode_functions,
+ NULL,
+ NULL,
+ NULL,
+ NULL
};
PyMODINIT_FUNC
diff --git a/Modules/_operator.c b/Modules/_operator.c
index 6a25205..2c0985d 100644
--- a/Modules/_operator.c
+++ b/Modules/_operator.c
@@ -992,6 +992,7 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *item;
Py_ssize_t nitems;
Py_ssize_t index;
+ _operator_state *state;
if (!_PyArg_NoKeywords("itemgetter", kwds))
return NULL;
@@ -1003,7 +1004,7 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
} else {
item = args;
}
- _operator_state *state = PyType_GetModuleState(type);
+ state = PyType_GetModuleState(type);
/* create itemgetterobject structure */
ig = PyObject_GC_New(itemgetterobject, (PyTypeObject *) state->itemgetter_type);
if (ig == NULL) {
@@ -1074,10 +1075,12 @@ static PyObject *
itemgetter_vectorcall(PyObject *ig, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
+ Py_ssize_t nargs;
+
if (!_PyArg_NoKwnames("itemgetter", kwnames)) {
return NULL;
}
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("itemgetter", nargs, 1, 1)) {
return NULL;
}
@@ -1183,12 +1186,12 @@ static PyType_Slot itemgetter_type_slots[] = {
};
static PyType_Spec itemgetter_type_spec = {
- .name = "operator.itemgetter",
- .basicsize = sizeof(itemgetterobject),
- .itemsize = 0,
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_VECTORCALL),
- .slots = itemgetter_type_slots,
+ "operator.itemgetter",
+ sizeof(itemgetterobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_VECTORCALL),
+ itemgetter_type_slots,
};
/* attrgetter object **********************************************************/
@@ -1213,6 +1216,7 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
attrgetterobject *ag;
PyObject *attr;
Py_ssize_t nattrs, idx, char_idx;
+ _operator_state *state;
if (!_PyArg_NoKeywords("attrgetter", kwds))
return NULL;
@@ -1305,7 +1309,7 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
- _operator_state *state = PyType_GetModuleState(type);
+ state = PyType_GetModuleState(type);
/* create attrgetterobject structure */
ag = PyObject_GC_New(attrgetterobject, (PyTypeObject *)state->attrgetter_type);
if (ag == NULL) {
@@ -1392,10 +1396,12 @@ attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw)
static PyObject *
attrgetter_vectorcall(PyObject *ag, PyObject *const *args, size_t nargsf, PyObject *kwnames)
{
+ Py_ssize_t nargs;
+
if (!_PyArg_NoKwnames("attrgetter", kwnames)) {
return NULL;
}
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("attrgetter", nargs, 1, 1)) {
return NULL;
}
@@ -1549,12 +1555,12 @@ static PyType_Slot attrgetter_type_slots[] = {
};
static PyType_Spec attrgetter_type_spec = {
- .name = "operator.attrgetter",
- .basicsize = sizeof(attrgetterobject),
- .itemsize = 0,
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_VECTORCALL),
- .slots = attrgetter_type_slots,
+ "operator.attrgetter",
+ sizeof(attrgetterobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_VECTORCALL),
+ attrgetter_type_slots,
};
@@ -1573,6 +1579,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
methodcallerobject *mc;
PyObject *name;
+ _operator_state *state;
if (PyTuple_GET_SIZE(args) < 1) {
PyErr_SetString(PyExc_TypeError, "methodcaller needs at least "
@@ -1587,7 +1594,7 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
- _operator_state *state = PyType_GetModuleState(type);
+ state = PyType_GetModuleState(type);
/* create methodcallerobject structure */
mc = PyObject_GC_New(methodcallerobject, (PyTypeObject *)state->methodcaller_type);
if (mc == NULL) {
@@ -1804,12 +1811,12 @@ static PyType_Slot methodcaller_type_slots[] = {
};
static PyType_Spec methodcaller_type_spec = {
- .name = "operator.methodcaller",
- .basicsize = sizeof(methodcallerobject),
- .itemsize = 0,
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = methodcaller_type_slots,
+ "operator.methodcaller",
+ sizeof(methodcallerobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_IMMUTABLETYPE),
+ methodcaller_type_slots,
};
static int
@@ -1877,14 +1884,14 @@ operator_free(void *module)
static struct PyModuleDef operatormodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_operator",
- .m_doc = operator_doc,
- .m_size = sizeof(_operator_state),
- .m_methods = operator_methods,
- .m_slots = operator_slots,
- .m_traverse = operator_traverse,
- .m_clear = operator_clear,
- .m_free = operator_free,
+ "_operator",
+ operator_doc,
+ sizeof(_operator_state),
+ operator_methods,
+ operator_slots,
+ operator_traverse,
+ operator_clear,
+ operator_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/_threadmodule.c b/Modules/_threadmodule.c
index 625e4e6..0459350 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -57,6 +57,8 @@ lock_traverse(lockobject *self, visitproc visit, void *arg)
static void
lock_dealloc(lockobject *self)
{
+ PyTypeObject *tp;
+
PyObject_GC_UnTrack(self);
if (self->in_weakreflist != NULL) {
PyObject_ClearWeakRefs((PyObject *) self);
@@ -67,7 +69,7 @@ lock_dealloc(lockobject *self)
PyThread_release_lock(self->lock_lock);
PyThread_free_lock(self->lock_lock);
}
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
tp->tp_free((PyObject*)self);
Py_DECREF(tp);
}
@@ -82,11 +84,11 @@ static PyLockStatus
acquire_timed(PyThread_type_lock lock, _PyTime_t timeout)
{
_PyTime_t endtime = 0;
+ PyLockStatus r;
if (timeout > 0) {
endtime = _PyDeadline_Init(timeout);
}
- PyLockStatus r;
do {
_PyTime_t microseconds;
microseconds = _PyTime_AsMicroseconds(timeout, _PyTime_ROUND_CEILING);
@@ -173,10 +175,11 @@ static PyObject *
lock_PyThread_acquire_lock(lockobject *self, PyObject *args, PyObject *kwds)
{
_PyTime_t timeout;
+ PyLockStatus r;
if (lock_acquire_parse_args(args, kwds, &timeout) < 0)
return NULL;
- PyLockStatus r = acquire_timed(self->lock_lock, timeout);
+ r = acquire_timed(self->lock_lock, timeout);
if (r == PY_LOCK_INTR) {
return NULL;
}
@@ -306,11 +309,12 @@ static PyType_Slot lock_type_slots[] = {
};
static PyType_Spec lock_type_spec = {
- .name = "_thread.lock",
- .basicsize = sizeof(lockobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = lock_type_slots,
+ "_thread.lock",
+ sizeof(lockobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
+ lock_type_slots,
};
/* Recursive lock objects */
@@ -334,6 +338,8 @@ rlock_traverse(rlockobject *self, visitproc visit, void *arg)
static void
rlock_dealloc(rlockobject *self)
{
+ PyTypeObject *tp;
+
PyObject_GC_UnTrack(self);
if (self->in_weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
@@ -346,7 +352,7 @@ rlock_dealloc(rlockobject *self)
PyThread_free_lock(self->rlock_lock);
}
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
tp->tp_free(self);
Py_DECREF(tp);
}
@@ -603,11 +609,12 @@ static PyType_Slot rlock_type_slots[] = {
};
static PyType_Spec rlock_type_spec = {
- .name = "_thread.RLock",
- .basicsize = sizeof(rlockobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = rlock_type_slots,
+ "_thread.RLock",
+ sizeof(rlockobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
+ rlock_type_slots,
};
static lockobject *
@@ -683,9 +690,11 @@ typedef struct {
static void
localdummy_dealloc(localdummyobject *self)
{
+ PyTypeObject *tp;
+
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
tp->tp_free((PyObject*)self);
Py_DECREF(tp);
}
@@ -703,11 +712,12 @@ static PyType_Slot local_dummy_type_slots[] = {
};
static PyType_Spec local_dummy_type_spec = {
- .name = "_thread._localdummy",
- .basicsize = sizeof(localdummyobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = local_dummy_type_slots,
+ "_thread._localdummy",
+ sizeof(localdummyobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE),
+ local_dummy_type_slots,
};
@@ -735,6 +745,7 @@ _local_create_dummy(localobject *self, thread_module_state *state)
PyObject *ldict = NULL, *wr = NULL;
localdummyobject *dummy = NULL;
PyTypeObject *type = state->local_dummy_type;
+ int r;
PyObject *tdict = PyThreadState_GetDict();
if (tdict == NULL) {
@@ -759,7 +770,7 @@ _local_create_dummy(localobject *self, thread_module_state *state)
/* As a side-effect, this will cache the weakref's hash before the
dummy gets deleted */
- int r = PyDict_SetItem(self->dummies, wr, ldict);
+ r = PyDict_SetItem(self->dummies, wr, ldict);
if (r < 0) {
goto err;
}
@@ -787,6 +798,11 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
"_localdummy_destroyed", (PyCFunction) _localdummy_destroyed, METH_O
};
+ PyObject *module;
+ thread_module_state *state;
+ localobject *self;
+ PyObject *wr;
+
if (type->tp_init == PyBaseObject_Type.tp_init) {
int rc = 0;
if (args != NULL)
@@ -802,10 +818,10 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
}
}
- PyObject *module = PyType_GetModuleByDef(type, &thread_module);
- thread_module_state *state = get_thread_state(module);
+ module = PyType_GetModuleByDef(type, &thread_module);
+ state = get_thread_state(module);
- localobject *self = (localobject *)type->tp_alloc(type, 0);
+ self = (localobject *)type->tp_alloc(type, 0);
if (self == NULL) {
return NULL;
}
@@ -824,7 +840,7 @@ local_new(PyTypeObject *type, PyObject *args, PyObject *kw)
/* We use a weak reference to self in the callback closure
in order to avoid spurious reference cycles */
- PyObject *wr = PyWeakref_NewRef((PyObject *) self, NULL);
+ wr = PyWeakref_NewRef((PyObject *) self, NULL);
if (wr == NULL) {
goto err;
}
@@ -869,8 +885,9 @@ local_clear(localobject *self)
if (self->key) {
PyInterpreterState *interp = _PyInterpreterState_GET();
_PyRuntimeState *runtime = &_PyRuntime;
+ PyThreadState *tstate;
HEAD_LOCK(runtime);
- PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
+ tstate = PyInterpreterState_ThreadHead(interp);
HEAD_UNLOCK(runtime);
while (tstate) {
if (tstate->dict) {
@@ -893,6 +910,8 @@ local_clear(localobject *self)
static void
local_dealloc(localobject *self)
{
+ PyTypeObject *tp;
+
/* Weakrefs must be invalidated right now, otherwise they can be used
from code called below, which is very dangerous since Py_REFCNT(self) == 0 */
if (self->weakreflist != NULL) {
@@ -904,7 +923,7 @@ local_dealloc(localobject *self)
local_clear(self);
Py_XDECREF(self->key);
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
tp->tp_free((PyObject*)self);
Py_DECREF(tp);
}
@@ -913,15 +932,18 @@ local_dealloc(localobject *self)
static PyObject *
_ldict(localobject *self, thread_module_state *state)
{
- PyObject *tdict = PyThreadState_GetDict();
+ PyObject *tdict;
+ PyObject *ldict;
+ PyObject *dummy;
+
+ tdict = PyThreadState_GetDict();
if (tdict == NULL) {
PyErr_SetString(PyExc_SystemError,
"Couldn't get thread-state dictionary");
return NULL;
}
- PyObject *ldict;
- PyObject *dummy = PyDict_GetItemWithError(tdict, self->key);
+ dummy = PyDict_GetItemWithError(tdict, self->key);
if (dummy == NULL) {
if (PyErr_Occurred()) {
return NULL;
@@ -951,15 +973,20 @@ _ldict(localobject *self, thread_module_state *state)
static int
local_setattro(localobject *self, PyObject *name, PyObject *v)
{
- PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
- thread_module_state *state = get_thread_state(module);
+ PyObject *module;
+ thread_module_state *state;
+ PyObject *ldict;
+ int r;
- PyObject *ldict = _ldict(self, state);
+ module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
+ state = get_thread_state(module);
+
+ ldict = _ldict(self, state);
if (ldict == NULL) {
return -1;
}
- int r = PyObject_RichCompareBool(name, &_Py_ID(__dict__), Py_EQ);
+ r = PyObject_RichCompareBool(name, &_Py_ID(__dict__), Py_EQ);
if (r == -1) {
return -1;
}
@@ -993,24 +1020,31 @@ static PyType_Slot local_type_slots[] = {
};
static PyType_Spec local_type_spec = {
- .name = "_thread._local",
- .basicsize = sizeof(localobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = local_type_slots,
+ "_thread._local",
+ sizeof(localobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_IMMUTABLETYPE),
+ local_type_slots,
};
static PyObject *
local_getattro(localobject *self, PyObject *name)
{
- PyObject *module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
- thread_module_state *state = get_thread_state(module);
+ PyObject *module;
+ thread_module_state *state;
+ PyObject *ldict;
+ int r;
+ PyObject *value;
+
+ module = PyType_GetModuleByDef(Py_TYPE(self), &thread_module);
+ state = get_thread_state(module);
- PyObject *ldict = _ldict(self, state);
+ ldict = _ldict(self, state);
if (ldict == NULL)
return NULL;
- int r = PyObject_RichCompareBool(name, &_Py_ID(__dict__), Py_EQ);
+ r = PyObject_RichCompareBool(name, &_Py_ID(__dict__), Py_EQ);
if (r == 1) {
return Py_NewRef(ldict);
}
@@ -1025,7 +1059,7 @@ local_getattro(localobject *self, PyObject *name)
}
/* Optimization: just look in dict ourselves */
- PyObject *value = PyDict_GetItemWithError(ldict, name);
+ value = PyDict_GetItemWithError(ldict, name);
if (value != NULL) {
return Py_NewRef(value);
}
@@ -1042,15 +1076,18 @@ local_getattro(localobject *self, PyObject *name)
static PyObject *
_localdummy_destroyed(PyObject *localweakref, PyObject *dummyweakref)
{
+ PyObject *obj;
+ localobject *self;
+
assert(PyWeakref_CheckRef(localweakref));
- PyObject *obj = PyWeakref_GET_OBJECT(localweakref);
+ obj = PyWeakref_GET_OBJECT(localweakref);
if (obj == Py_None) {
Py_RETURN_NONE;
}
/* If the thread-local object is still alive and not being cleared,
remove the corresponding local dict */
- localobject *self = (localobject *)Py_NewRef(obj);
+ self = (localobject *)Py_NewRef(obj);
if (self->dummies != NULL) {
PyObject *ldict;
ldict = PyDict_GetItemWithError(self->dummies, dummyweakref);
@@ -1089,8 +1126,12 @@ thread_bootstate_free(struct bootstate *boot, int decref)
static void
thread_run(void *boot_raw)
{
- struct bootstate *boot = (struct bootstate *) boot_raw;
- PyThreadState *tstate = boot->tstate;
+ struct bootstate *boot;
+ PyThreadState *tstate;
+ PyObject *res;
+
+ boot = (struct bootstate *) boot_raw;
+ tstate = boot->tstate;
// gh-108987: If _thread.start_new_thread() is called before or while
// Python is being finalized, thread_run() can called *after*.
@@ -1121,7 +1162,7 @@ thread_run(void *boot_raw)
PyEval_AcquireThread(tstate);
tstate->interp->threads.count++;
- PyObject *res = PyObject_Call(boot->func, boot->args, boot->kwargs);
+ res = PyObject_Call(boot->func, boot->args, boot->kwargs);
if (res == NULL) {
if (PyErr_ExceptionMatches(PyExc_SystemExit))
/* SystemExit is ignored silently */
@@ -1151,6 +1192,9 @@ static PyObject *
thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
{
PyObject *func, *args, *kwargs = NULL;
+ PyInterpreterState *interp;
+ struct bootstate *boot;
+ unsigned long ident;
if (!PyArg_UnpackTuple(fargs, "start_new_thread", 2, 3,
&func, &args, &kwargs))
@@ -1171,7 +1215,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
return NULL;
}
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ interp = _PyInterpreterState_GET();
if (interp->config._isolated_interpreter) {
PyErr_SetString(PyExc_RuntimeError,
"thread is not supported for isolated subinterpreters");
@@ -1181,7 +1225,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
// gh-109795: Use PyMem_RawMalloc() instead of PyMem_Malloc(),
// because it should be possible to call thread_bootstate_free()
// without holding the GIL.
- struct bootstate *boot = PyMem_RawMalloc(sizeof(struct bootstate));
+ boot = PyMem_RawMalloc(sizeof(struct bootstate));
if (boot == NULL) {
return PyErr_NoMemory();
}
@@ -1194,7 +1238,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
boot->args = Py_NewRef(args);
boot->kwargs = Py_XNewRef(kwargs);
- unsigned long ident = PyThread_start_new_thread(thread_run, (void*) boot);
+ ident = PyThread_start_new_thread(thread_run, (void*) boot);
if (ident == PYTHREAD_INVALID_THREAD_ID) {
PyErr_SetString(ThreadError, "can't start new thread");
PyThreadState_Clear(boot->tstate);
@@ -1445,12 +1489,15 @@ static int
thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value,
PyObject *exc_traceback, PyObject *thread)
{
+ PyObject *name;
+ PyObject *res;
+
/* print(f"Exception in thread {thread.name}:", file=file) */
if (PyFile_WriteString("Exception in thread ", file) < 0) {
return -1;
}
- PyObject *name = NULL;
+ name = NULL;
if (thread != Py_None) {
if (_PyObject_LookupAttr(thread, &_Py_ID(name), &name) < 0) {
return -1;
@@ -1490,7 +1537,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value,
_PyErr_Display(file, exc_type, exc_value, exc_traceback);
/* Call file.flush() */
- PyObject *res = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
+ res = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (!res) {
return -1;
}
@@ -1514,17 +1561,26 @@ static PyStructSequence_Field ExceptHookArgs_fields[] = {
};
static PyStructSequence_Desc ExceptHookArgs_desc = {
- .name = "_thread._ExceptHookArgs",
- .doc = ExceptHookArgs__doc__,
- .fields = ExceptHookArgs_fields,
- .n_in_sequence = 4
+ "_thread._ExceptHookArgs",
+ ExceptHookArgs__doc__,
+ ExceptHookArgs_fields,
+ 4
};
static PyObject *
thread_excepthook(PyObject *module, PyObject *args)
{
- thread_module_state *state = get_thread_state(module);
+ thread_module_state *state;
+ PyObject *exc_type;
+ PyObject *exc_value;
+ PyObject *exc_tb;
+ PyObject *thread;
+ PyThreadState *tstate;
+ PyObject *file;
+ int res;
+
+ state = get_thread_state(module);
if (!Py_IS_TYPE(args, state->excepthook_type)) {
PyErr_SetString(PyExc_TypeError,
@@ -1534,19 +1590,19 @@ thread_excepthook(PyObject *module, PyObject *args)
}
/* Borrowed reference */
- PyObject *exc_type = PyStructSequence_GET_ITEM(args, 0);
+ exc_type = PyStructSequence_GET_ITEM(args, 0);
if (exc_type == PyExc_SystemExit) {
/* silently ignore SystemExit */
Py_RETURN_NONE;
}
/* Borrowed references */
- PyObject *exc_value = PyStructSequence_GET_ITEM(args, 1);
- PyObject *exc_tb = PyStructSequence_GET_ITEM(args, 2);
- PyObject *thread = PyStructSequence_GET_ITEM(args, 3);
+ exc_value = PyStructSequence_GET_ITEM(args, 1);
+ exc_tb = PyStructSequence_GET_ITEM(args, 2);
+ thread = PyStructSequence_GET_ITEM(args, 3);
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *file = _PySys_GetAttr(tstate, &_Py_ID(stderr));
+ tstate = _PyThreadState_GET();
+ file = _PySys_GetAttr(tstate, &_Py_ID(stderr));
if (file == NULL || file == Py_None) {
if (thread == Py_None) {
/* do nothing if sys.stderr is None and thread is None */
@@ -1568,8 +1624,8 @@ thread_excepthook(PyObject *module, PyObject *args)
Py_INCREF(file);
}
- int res = thread_excepthook_file(file, exc_type, exc_value, exc_tb,
- thread);
+ res = thread_excepthook_file(file, exc_type, exc_value, exc_tb,
+ thread);
Py_DECREF(file);
if (res < 0) {
return NULL;
@@ -1621,8 +1677,14 @@ static PyMethodDef thread_methods[] = {
static int
thread_module_exec(PyObject *module)
{
- thread_module_state *state = get_thread_state(module);
- PyObject *d = PyModule_GetDict(module);
+ thread_module_state *state;
+ PyObject *d;
+ PyTypeObject *rlock_type;
+ double timeout_max;
+ double time_max;
+
+ state = get_thread_state(module);
+ d = PyModule_GetDict(module);
// Initialize the C thread library
PyThread_init_thread();
@@ -1637,7 +1699,7 @@ thread_module_exec(PyObject *module)
}
// RLock
- PyTypeObject *rlock_type = (PyTypeObject *)PyType_FromSpec(&rlock_type_spec);
+ rlock_type = (PyTypeObject *)PyType_FromSpec(&rlock_type_spec);
if (rlock_type == NULL) {
return -1;
}
@@ -1677,8 +1739,8 @@ thread_module_exec(PyObject *module)
}
// TIMEOUT_MAX
- double timeout_max = (double)PY_TIMEOUT_MAX * 1e-6;
- double time_max = _PyTime_AsSecondsDouble(_PyTime_MAX);
+ timeout_max = (double)PY_TIMEOUT_MAX * 1e-6;
+ time_max = _PyTime_AsSecondsDouble(_PyTime_MAX);
timeout_max = Py_MIN(timeout_max, time_max);
// Round towards minus infinity
timeout_max = floor(timeout_max);
@@ -1733,14 +1795,14 @@ static PyModuleDef_Slot thread_module_slots[] = {
static struct PyModuleDef thread_module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_thread",
- .m_doc = thread_doc,
- .m_size = sizeof(thread_module_state),
- .m_methods = thread_methods,
- .m_traverse = thread_module_traverse,
- .m_clear = thread_module_clear,
- .m_free = thread_module_free,
- .m_slots = thread_module_slots,
+ "_thread",
+ thread_doc,
+ sizeof(thread_module_state),
+ thread_methods,
+ thread_module_slots,
+ thread_module_traverse,
+ thread_module_clear,
+ thread_module_free,
};
PyMODINIT_FUNC
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 44a1f7b..dd181fb 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -280,6 +280,7 @@ hashtable_compare_traceback(const void *key1, const void *key2)
{
const traceback_t *traceback1 = (const traceback_t *)key1;
const traceback_t *traceback2 = (const traceback_t *)key2;
+ int i;
if (traceback1->nframe != traceback2->nframe) {
return 0;
@@ -288,7 +289,7 @@ hashtable_compare_traceback(const void *key1, const void *key2)
return 0;
}
- for (int i=0; i < traceback1->nframe; i++) {
+ for (i=0; i < traceback1->nframe; i++) {
const frame_t *frame1 = &traceback1->frames[i];
const frame_t *frame2 = &traceback2->frames[i];
@@ -307,14 +308,18 @@ hashtable_compare_traceback(const void *key1, const void *key2)
static void
tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame)
{
+ int lineno;
+ PyObject *filename;
+ _Py_hashtable_entry_t *entry;
+
frame->filename = &_Py_STR(anon_unknown);
- int lineno = _PyInterpreterFrame_GetLine(pyframe);
+ lineno = _PyInterpreterFrame_GetLine(pyframe);
if (lineno < 0) {
lineno = 0;
}
frame->lineno = (unsigned int)lineno;
- PyObject *filename = pyframe->f_code->co_filename;
+ filename = pyframe->f_code->co_filename;
if (filename == NULL) {
#ifdef TRACE_DEBUG
@@ -339,7 +344,6 @@ tracemalloc_get_frame(_PyInterpreterFrame *pyframe, frame_t *frame)
}
/* intern the filename */
- _Py_hashtable_entry_t *entry;
entry = _Py_hashtable_get_entry(tracemalloc_filenames, filename);
if (entry != NULL) {
filename = (PyObject *)entry->key;
@@ -391,7 +395,10 @@ traceback_hash(traceback_t *traceback)
static void
traceback_get_frames(traceback_t *traceback)
{
- PyThreadState *tstate = PyGILState_GetThisThreadState();
+ PyThreadState *tstate;
+ _PyInterpreterFrame *pyframe;
+
+ tstate = PyGILState_GetThisThreadState();
if (tstate == NULL) {
#ifdef TRACE_DEBUG
tracemalloc_error("failed to get the current thread state");
@@ -399,7 +406,7 @@ traceback_get_frames(traceback_t *traceback)
return;
}
- _PyInterpreterFrame *pyframe = tstate->cframe->current_frame;
+ pyframe = tstate->cframe->current_frame;
for (;;) {
while (pyframe && _PyFrame_IsIncomplete(pyframe)) {
pyframe = pyframe->previous;
@@ -505,14 +512,17 @@ tracemalloc_get_traces_table(unsigned int domain)
static void
tracemalloc_remove_trace(unsigned int domain, uintptr_t ptr)
{
+ _Py_hashtable_t *traces;
+ trace_t *trace;
+
assert(_Py_tracemalloc_config.tracing);
- _Py_hashtable_t *traces = tracemalloc_get_traces_table(domain);
+ traces = tracemalloc_get_traces_table(domain);
if (!traces) {
return;
}
- trace_t *trace = _Py_hashtable_steal(traces, TO_PTR(ptr));
+ trace = _Py_hashtable_steal(traces, TO_PTR(ptr));
if (!trace) {
return;
}
@@ -529,14 +539,19 @@ static int
tracemalloc_add_trace(unsigned int domain, uintptr_t ptr,
size_t size)
{
+ traceback_t *traceback;
+ _Py_hashtable_t *traces;
+ trace_t *trace;
+ int res;
+
assert(_Py_tracemalloc_config.tracing);
- traceback_t *traceback = traceback_new();
+ traceback = traceback_new();
if (traceback == NULL) {
return -1;
}
- _Py_hashtable_t *traces = tracemalloc_get_traces_table(domain);
+ traces = tracemalloc_get_traces_table(domain);
if (traces == NULL) {
traces = tracemalloc_create_traces_table();
if (traces == NULL) {
@@ -549,7 +564,7 @@ tracemalloc_add_trace(unsigned int domain, uintptr_t ptr,
}
}
- trace_t *trace = _Py_hashtable_get(traces, TO_PTR(ptr));
+ trace = _Py_hashtable_get(traces, TO_PTR(ptr));
if (trace != NULL) {
/* the memory block is already tracked */
assert(tracemalloc_traced_memory >= trace->size);
@@ -566,7 +581,7 @@ tracemalloc_add_trace(unsigned int domain, uintptr_t ptr,
trace->size = size;
trace->traceback = traceback;
- int res = _Py_hashtable_set(traces, TO_PTR(ptr), trace);
+ res = _Py_hashtable_set(traces, TO_PTR(ptr), trace);
if (res != 0) {
raw_free(trace);
return res;
@@ -1103,6 +1118,7 @@ static PyObject*
traceback_to_pyobject(traceback_t *traceback, _Py_hashtable_t *intern_table)
{
PyObject *frames;
+ int i;
if (intern_table != NULL) {
frames = _Py_hashtable_get(intern_table, (const void *)traceback);
@@ -1116,7 +1132,7 @@ traceback_to_pyobject(traceback_t *traceback, _Py_hashtable_t *intern_table)
if (frames == NULL)
return NULL;
- for (int i=0; i < traceback->nframe; i++) {
+ for (i=0; i < traceback->nframe; i++) {
PyObject *frame = frame_to_pyobject(&traceback->frames[i]);
if (frame == NULL) {
Py_DECREF(frames);
@@ -1215,12 +1231,15 @@ tracemalloc_copy_trace(_Py_hashtable_t *traces,
static _Py_hashtable_t*
tracemalloc_copy_traces(_Py_hashtable_t *traces)
{
- _Py_hashtable_t *traces2 = tracemalloc_create_traces_table();
+ _Py_hashtable_t *traces2;
+ int err;
+
+ traces2 = tracemalloc_create_traces_table();
if (traces2 == NULL) {
return NULL;
}
- int err = _Py_hashtable_foreach(traces,
+ err = _Py_hashtable_foreach(traces,
tracemalloc_copy_trace,
traces2);
if (err) {
@@ -1256,12 +1275,15 @@ tracemalloc_copy_domain(_Py_hashtable_t *domains,
static _Py_hashtable_t*
tracemalloc_copy_domains(_Py_hashtable_t *domains)
{
- _Py_hashtable_t *domains2 = tracemalloc_create_domains_table();
+ _Py_hashtable_t *domains2;
+ int err;
+
+ domains2 = tracemalloc_create_domains_table();
if (domains2 == NULL) {
return NULL;
}
- int err = _Py_hashtable_foreach(domains,
+ err = _Py_hashtable_foreach(domains,
tracemalloc_copy_domain,
domains2);
if (err) {
@@ -1277,17 +1299,22 @@ tracemalloc_get_traces_fill(_Py_hashtable_t *traces,
const void *key, const void *value,
void *user_data)
{
- get_traces_t *get_traces = user_data;
+ get_traces_t *get_traces;
+ const trace_t *trace;
+ PyObject *tuple;
+ int res;
+
+ get_traces = user_data;
- const trace_t *trace = (const trace_t *)value;
+ trace = (const trace_t *)value;
- PyObject *tuple = trace_to_pyobject(get_traces->domain, trace,
- get_traces->tracebacks);
+ tuple = trace_to_pyobject(get_traces->domain, trace,
+ get_traces->tracebacks);
if (tuple == NULL) {
return 1;
}
- int res = PyList_Append(get_traces->list, tuple);
+ res = PyList_Append(get_traces->list, tuple);
Py_DECREF(tuple);
if (res < 0) {
return 1;
@@ -1339,6 +1366,7 @@ _tracemalloc__get_traces_impl(PyObject *module)
/*[clinic end generated code: output=e9929876ced4b5cc input=6c7d2230b24255aa]*/
{
get_traces_t get_traces;
+ int err;
get_traces.domain = DEFAULT_DOMAIN;
get_traces.traces = NULL;
get_traces.domains = NULL;
@@ -1380,7 +1408,7 @@ _tracemalloc__get_traces_impl(PyObject *module)
// Convert traces to a list of tuples
set_reentrant(1);
- int err = _Py_hashtable_foreach(get_traces.traces,
+ err = _Py_hashtable_foreach(get_traces.traces,
tracemalloc_get_traces_fill,
&get_traces);
if (!err) {
@@ -1419,13 +1447,14 @@ _tracemalloc__get_traces_impl(PyObject *module)
static traceback_t*
tracemalloc_get_traceback(unsigned int domain, uintptr_t ptr)
{
+ trace_t *trace;
+ _Py_hashtable_t *traces;
if (!_Py_tracemalloc_config.tracing)
return NULL;
- trace_t *trace;
TABLES_LOCK();
- _Py_hashtable_t *traces = tracemalloc_get_traces_table(domain);
+ traces = tracemalloc_get_traces_table(domain);
if (traces) {
trace = _Py_hashtable_get(traces, TO_PTR(ptr));
}
@@ -1777,6 +1806,11 @@ PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
int
_PyTraceMalloc_NewReference(PyObject *op)
{
+ uintptr_t ptr;
+ PyTypeObject *type;
+ int res;
+ trace_t *trace;
+
assert(PyGILState_Check());
if (!_Py_tracemalloc_config.tracing) {
@@ -1784,8 +1818,7 @@ _PyTraceMalloc_NewReference(PyObject *op)
return -1;
}
- uintptr_t ptr;
- PyTypeObject *type = Py_TYPE(op);
+ type = Py_TYPE(op);
if (PyType_IS_GC(type)) {
ptr = (uintptr_t)((char *)op - sizeof(PyGC_Head));
}
@@ -1793,10 +1826,10 @@ _PyTraceMalloc_NewReference(PyObject *op)
ptr = (uintptr_t)op;
}
- int res = -1;
+ res = -1;
TABLES_LOCK();
- trace_t *trace = _Py_hashtable_get(tracemalloc_traces, TO_PTR(ptr));
+ trace = _Py_hashtable_get(tracemalloc_traces, TO_PTR(ptr));
if (trace != NULL) {
/* update the traceback of the memory block */
traceback_t *traceback = traceback_new();
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index 0376cc0..dbdfbb3 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -40,6 +40,57 @@
#include "windows.h"
+/* Legacy SDK names only; these definitions do not add Win9x API support. */
+#if defined(_MSC_VER) && _MSC_VER < 1300
+# ifndef INVALID_FILE_ATTRIBUTES
+# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+# endif
+# ifndef FSCTL_SET_REPARSE_POINT
+# define FSCTL_SET_REPARSE_POINT 0x000900A4
+# endif
+# ifndef LOCALE_NAME_INVARIANT
+# define LOCALE_NAME_INVARIANT L""
+# endif
+# ifndef LOCALE_NAME_MAX_LENGTH
+# define LOCALE_NAME_MAX_LENGTH 85
+# endif
+# ifndef LOCALE_NAME_SYSTEM_DEFAULT
+# define LOCALE_NAME_SYSTEM_DEFAULT L"!sys-default-locale"
+# endif
+# ifndef LOCALE_NAME_USER_DEFAULT
+# define LOCALE_NAME_USER_DEFAULT NULL
+# endif
+# ifndef LCMAP_SORTHANDLE
+# define LCMAP_SORTHANDLE 0x20000000
+# endif
+# ifndef LCMAP_HASH
+# define LCMAP_HASH 0x00040000
+# endif
+# ifndef LCMAP_TITLECASE
+# define LCMAP_TITLECASE 0x00000300
+# endif
+# ifndef FILE_FLAG_FIRST_PIPE_INSTANCE
+# define FILE_FLAG_FIRST_PIPE_INSTANCE 0x00080000
+# endif
+# ifndef FILE_MAP_EXECUTE
+# define FILE_MAP_EXECUTE 0x0020
+# endif
+# ifndef SEC_LARGE_PAGES
+# define SEC_LARGE_PAGES 0x80000000
+# endif
+# ifndef SEC_WRITECOMBINE
+# define SEC_WRITECOMBINE 0x40000000
+# endif
+# ifndef ABOVE_NORMAL_PRIORITY_CLASS
+# define ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
+# endif
+# ifndef BELOW_NORMAL_PRIORITY_CLASS
+# define BELOW_NORMAL_PRIORITY_CLASS 0x00004000
+# endif
+# ifndef CREATE_BREAKAWAY_FROM_JOB
+# define CREATE_BREAKAWAY_FROM_JOB 0x01000000
+# endif
+#endif
#include <crtdbg.h>
#include "winreparse.h"
@@ -130,6 +181,7 @@ overlapped_traverse(OverlappedObject *self, visitproc visit, void *arg)
static void
overlapped_dealloc(OverlappedObject *self)
{
+ PyTypeObject *tp;
DWORD bytes;
int err = GetLastError();
@@ -169,7 +221,7 @@ overlapped_dealloc(OverlappedObject *self)
if (self->write_buffer.obj)
PyBuffer_Release(&self->write_buffer);
Py_CLEAR(self->read_buffer);
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
tp->tp_free(self);
Py_DECREF(tp);
}
@@ -346,11 +398,12 @@ static PyType_Slot winapi_overlapped_type_slots[] = {
};
static PyType_Spec winapi_overlapped_type_spec = {
- .name = "_winapi.Overlapped",
- .basicsize = sizeof(OverlappedObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = winapi_overlapped_type_slots,
+ "_winapi.Overlapped",
+ sizeof(OverlappedObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE,
+ winapi_overlapped_type_slots,
};
static OverlappedObject *
@@ -818,17 +871,23 @@ static PyMethodDef sortenvironmentkey_def = {
static int
sort_environment_keys(PyObject *keys)
{
- PyObject *keyfunc = PyCFunction_New(&sortenvironmentkey_def, NULL);
+ PyObject *keyfunc;
+ PyObject *kwnames;
+ PyObject *args[2];
+ PyObject *ret;
+
+ keyfunc = PyCFunction_New(&sortenvironmentkey_def, NULL);
if (keyfunc == NULL) {
return -1;
}
- PyObject *kwnames = Py_BuildValue("(s)", "key");
+ kwnames = Py_BuildValue("(s)", "key");
if (kwnames == NULL) {
Py_DECREF(keyfunc);
return -1;
}
- PyObject *args[] = { keys, keyfunc };
- PyObject *ret = PyObject_VectorcallMethod(&_Py_ID(sort), args, 1, kwnames);
+ args[0] = keys;
+ args[1] = keyfunc;
+ ret = PyObject_VectorcallMethod(&_Py_ID(sort), args, 1, kwnames);
Py_DECREF(keyfunc);
Py_DECREF(kwnames);
if (ret == NULL) {
@@ -842,11 +901,14 @@ sort_environment_keys(PyObject *keys)
static int
compare_string_ordinal(PyObject *str1, PyObject *str2, int *result)
{
- wchar_t *s1 = PyUnicode_AsWideCharString(str1, NULL);
+ wchar_t *s1;
+ wchar_t *s2;
+
+ s1 = PyUnicode_AsWideCharString(str1, NULL);
if (s1 == NULL) {
return -1;
}
- wchar_t *s2 = PyUnicode_AsWideCharString(str2, NULL);
+ s2 = PyUnicode_AsWideCharString(str2, NULL);
if (s2 == NULL) {
PyMem_Free(s1);
return -1;
@@ -860,7 +922,10 @@ compare_string_ordinal(PyObject *str1, PyObject *str2, int *result)
static PyObject *
dedup_environment_keys(PyObject *keys)
{
- PyObject *result = PyList_New(0);
+ PyObject *result;
+ Py_ssize_t i;
+
+ result = PyList_New(0);
if (result == NULL) {
return NULL;
}
@@ -869,8 +934,12 @@ dedup_environment_keys(PyObject *keys)
// to the next key (ignoring case), if different, insert the current value
// into the result list. If they are equal, do nothing because we always
// want to keep the last inserted one.
- for (Py_ssize_t i = 0; i < PyList_GET_SIZE(keys); i++) {
- PyObject *key = PyList_GET_ITEM(keys, i);
+ for (i = 0; i < PyList_GET_SIZE(keys); i++) {
+ PyObject *key;
+ PyObject *next_key;
+ int compare_result;
+
+ key = PyList_GET_ITEM(keys, i);
// The last key will always be kept.
if (i + 1 == PyList_GET_SIZE(keys)) {
@@ -881,8 +950,7 @@ dedup_environment_keys(PyObject *keys)
continue;
}
- PyObject *next_key = PyList_GET_ITEM(keys, i + 1);
- int compare_result;
+ next_key = PyList_GET_ITEM(keys, i + 1);
if (compare_string_ordinal(key, next_key, &compare_result) < 0) {
Py_DECREF(result);
return NULL;
@@ -902,7 +970,15 @@ dedup_environment_keys(PyObject *keys)
static PyObject *
normalize_environment(PyObject *environment)
{
- PyObject *keys = PyMapping_Keys(environment);
+ PyObject *keys;
+ PyObject *normalized_keys;
+ PyObject *result;
+ PyObject *key;
+ PyObject *value;
+ int i;
+ int ret;
+
+ keys = PyMapping_Keys(environment);
if (keys == NULL) {
return NULL;
}
@@ -912,28 +988,28 @@ normalize_environment(PyObject *environment)
return NULL;
}
- PyObject *normalized_keys = dedup_environment_keys(keys);
+ normalized_keys = dedup_environment_keys(keys);
Py_DECREF(keys);
if (normalized_keys == NULL) {
return NULL;
}
- PyObject *result = PyDict_New();
+ result = PyDict_New();
if (result == NULL) {
Py_DECREF(normalized_keys);
return NULL;
}
- for (int i = 0; i < PyList_GET_SIZE(normalized_keys); i++) {
- PyObject *key = PyList_GET_ITEM(normalized_keys, i);
- PyObject *value = PyObject_GetItem(environment, key);
+ for (i = 0; i < PyList_GET_SIZE(normalized_keys); i++) {
+ key = PyList_GET_ITEM(normalized_keys, i);
+ value = PyObject_GetItem(environment, key);
if (value == NULL) {
Py_DECREF(normalized_keys);
Py_DECREF(result);
return NULL;
}
- int ret = PyObject_SetItem(result, key, value);
+ ret = PyObject_SetItem(result, key, value);
Py_DECREF(value);
if (ret < 0) {
Py_DECREF(normalized_keys);
@@ -1118,6 +1194,38 @@ gethandlelist(PyObject *mapping, const char *name, Py_ssize_t *size)
return ret;
}
+#if defined(_MSC_VER) && _MSC_VER < 1300
+/* Vista-only process/thread attribute APIs are unavailable in VC6. */
+typedef struct {
+ int unused;
+} AttributeList;
+
+static void
+freeattributelist(AttributeList *attribute_list)
+{
+ (void)attribute_list;
+}
+
+static int
+getattributelist(PyObject *obj, const char *name, AttributeList *attribute_list)
+{
+ PyObject *value;
+ (void)attribute_list;
+
+ value = PyObject_GetAttrString(obj, name);
+ if (!value) {
+ PyErr_Clear(); /* Preserve the existing optional-attribute behavior. */
+ return 0;
+ }
+ if (value == Py_None) {
+ Py_DECREF(value);
+ return 0;
+ }
+ Py_DECREF(value);
+ PyErr_SetFromWindowsErr(ERROR_CALL_NOT_IMPLEMENTED);
+ return -1;
+}
+#else
typedef struct {
LPPROC_THREAD_ATTRIBUTE_LIST attribute_list;
LPHANDLE handle_list;
@@ -1228,6 +1336,7 @@ getattributelist(PyObject *obj, const char *name, AttributeList *attribute_list)
return ret;
}
+#endif
/*[clinic input]
_winapi.CreateProcess
@@ -1265,18 +1374,25 @@ _winapi_CreateProcess_impl(PyObject *module,
PyObject *ret = NULL;
BOOL result;
PROCESS_INFORMATION pi;
+ STARTUPINFOW *si_base;
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ STARTUPINFOW si;
+#else
STARTUPINFOEXW si;
+#endif
wchar_t *wenvironment = NULL;
wchar_t *command_line_copy = NULL;
AttributeList attribute_list = {0};
+ PyInterpreterState *interp;
+ const PyConfig *config;
if (PySys_Audit("_winapi.CreateProcess", "uuu", application_name,
command_line, current_directory) < 0) {
return NULL;
}
- PyInterpreterState *interp = PyInterpreterState_Get();
- const PyConfig *config = _PyInterpreterState_GetConfig(interp);
+ interp = PyInterpreterState_Get();
+ config = _PyInterpreterState_GetConfig(interp);
if (config->_isolated_interpreter) {
PyErr_SetString(PyExc_RuntimeError,
"subprocess not supported for isolated subinterpreters");
@@ -1284,14 +1400,19 @@ _winapi_CreateProcess_impl(PyObject *module,
}
ZeroMemory(&si, sizeof(si));
- si.StartupInfo.cb = sizeof(si);
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ si_base = &si;
+#else
+ si_base = &si.StartupInfo;
+#endif
+ si_base->cb = sizeof(si);
/* note: we only support a small subset of all SI attributes */
- si.StartupInfo.dwFlags = getulong(startup_info, "dwFlags");
- si.StartupInfo.wShowWindow = (WORD)getulong(startup_info, "wShowWindow");
- si.StartupInfo.hStdInput = gethandle(startup_info, "hStdInput");
- si.StartupInfo.hStdOutput = gethandle(startup_info, "hStdOutput");
- si.StartupInfo.hStdError = gethandle(startup_info, "hStdError");
+ si_base->dwFlags = getulong(startup_info, "dwFlags");
+ si_base->wShowWindow = (WORD)getulong(startup_info, "wShowWindow");
+ si_base->hStdInput = gethandle(startup_info, "hStdInput");
+ si_base->hStdOutput = gethandle(startup_info, "hStdOutput");
+ si_base->hStdError = gethandle(startup_info, "hStdError");
if (PyErr_Occurred())
goto cleanup;
@@ -1305,7 +1426,9 @@ _winapi_CreateProcess_impl(PyObject *module,
if (getattributelist(startup_info, "lpAttributeList", &attribute_list) < 0)
goto cleanup;
+#if !defined(_MSC_VER) || _MSC_VER >= 1300
si.lpAttributeList = attribute_list.attribute_list;
+#endif
if (PyUnicode_Check(command_line)) {
command_line_copy = PyUnicode_AsWideCharString(command_line, NULL);
if (command_line_copy == NULL) {
@@ -1326,8 +1449,12 @@ _winapi_CreateProcess_impl(PyObject *module,
NULL,
NULL,
inherit_handles,
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ creation_flags | CREATE_UNICODE_ENVIRONMENT,
+#else
creation_flags | EXTENDED_STARTUPINFO_PRESENT |
CREATE_UNICODE_ENVIRONMENT,
+#endif
wenvironment,
current_directory,
(LPSTARTUPINFOW)&si,
@@ -1736,17 +1863,24 @@ _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
PyObject *src)
/*[clinic end generated code: output=8ea4c9d85a4a1f23 input=2fa6ebc92591731b]*/
{
+ wchar_t *locale_;
+ Py_ssize_t src_size;
+ wchar_t *src_;
+ int dest_size;
+ wchar_t *dest;
+ int nmapped;
+ PyObject *ret;
+
if (flags & (LCMAP_SORTHANDLE | LCMAP_HASH | LCMAP_BYTEREV |
LCMAP_SORTKEY)) {
return PyErr_Format(PyExc_ValueError, "unsupported flags");
}
- wchar_t *locale_ = PyUnicode_AsWideCharString(locale, NULL);
+ locale_ = PyUnicode_AsWideCharString(locale, NULL);
if (!locale_) {
return NULL;
}
- Py_ssize_t src_size;
- wchar_t *src_ = PyUnicode_AsWideCharString(src, &src_size);
+ src_ = PyUnicode_AsWideCharString(src, &src_size);
if (!src_) {
PyMem_Free(locale_);
return NULL;
@@ -1758,7 +1892,7 @@ _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
return NULL;
}
- int dest_size = LCMapStringEx(locale_, flags, src_, (int)src_size, NULL, 0,
+ dest_size = LCMapStringEx(locale_, flags, src_, (int)src_size, NULL, 0,
NULL, NULL, 0);
if (dest_size <= 0) {
DWORD error = GetLastError();
@@ -1767,14 +1901,14 @@ _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
return PyErr_SetFromWindowsErr(error);
}
- wchar_t* dest = PyMem_NEW(wchar_t, dest_size);
+ dest = PyMem_NEW(wchar_t, dest_size);
if (dest == NULL) {
PyMem_Free(locale_);
PyMem_Free(src_);
return PyErr_NoMemory();
}
- int nmapped = LCMapStringEx(locale_, flags, src_, (int)src_size, dest, dest_size,
+ nmapped = LCMapStringEx(locale_, flags, src_, (int)src_size, dest, dest_size,
NULL, NULL, 0);
if (nmapped <= 0) {
DWORD error = GetLastError();
@@ -1786,7 +1920,7 @@ _winapi_LCMapStringEx_impl(PyObject *module, PyObject *locale, DWORD flags,
PyMem_Free(locale_);
PyMem_Free(src_);
- PyObject *ret = PyUnicode_FromWideChar(dest, nmapped);
+ ret = PyUnicode_FromWideChar(dest, nmapped);
PyMem_DEL(dest);
return ret;
@@ -2199,10 +2333,12 @@ _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
int entry = 0;
HKEY hkcr = NULL;
LRESULT err;
+ DWORD i;
+ int j;
Py_BEGIN_ALLOW_THREADS
err = RegOpenKeyExW(HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, &hkcr);
- for (DWORD i = 0; err == ERROR_SUCCESS || err == ERROR_MORE_DATA; ++i) {
+ for (i = 0; err == ERROR_SUCCESS || err == ERROR_MORE_DATA; ++i) {
LPWSTR ext = entries[entry].ext;
LPWSTR type = entries[entry].type;
DWORD cchExt = CCH_EXT;
@@ -2241,7 +2377,7 @@ _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
/* Flush our cached entries if we are full */
if (entry == sizeof(entries) / sizeof(entries[0])) {
Py_BLOCK_THREADS
- for (int j = 0; j < entry; ++j) {
+ for (j = 0; j < entry; ++j) {
PyObject *r = PyObject_CallFunction(
on_type_read, "uu", entries[j].type, entries[j].ext
);
@@ -2266,7 +2402,7 @@ _winapi__mimetypes_read_windows_registry_impl(PyObject *module,
return NULL;
}
- for (int j = 0; j < entry; ++j) {
+ for (j = 0; j < entry; ++j) {
PyObject *r = PyObject_CallFunction(
on_type_read, "uu", entries[j].type, entries[j].ext
);
@@ -2334,7 +2470,10 @@ static PyMethodDef winapi_functions[] = {
static int winapi_exec(PyObject *m)
{
- WinApiState *st = winapi_get_state(m);
+ WinApiState *st;
+ PyObject *d;
+
+ st = winapi_get_state(m);
st->overlapped_type = (PyTypeObject *)PyType_FromModuleAndSpec(m, &winapi_overlapped_type_spec, NULL);
if (st->overlapped_type == NULL) {
@@ -2345,7 +2484,7 @@ static int winapi_exec(PyObject *m)
return -1;
}
- PyObject *d = PyModule_GetDict(m);
+ d = PyModule_GetDict(m);
/* constants */
WINAPI_CONSTANT(F_DWORD, CREATE_NEW_CONSOLE);
@@ -2492,13 +2631,14 @@ winapi_free(void *module)
static struct PyModuleDef winapi_module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_winapi",
- .m_size = sizeof(WinApiState),
- .m_methods = winapi_functions,
- .m_slots = winapi_slots,
- .m_traverse = winapi_traverse,
- .m_clear = winapi_clear,
- .m_free = winapi_free,
+ "_winapi",
+ NULL,
+ sizeof(WinApiState),
+ winapi_functions,
+ winapi_slots,
+ winapi_traverse,
+ winapi_clear,
+ winapi_free,
};
PyMODINIT_FUNC
diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c
index e5b96be..b60e38c 100644
--- a/Modules/_xxsubinterpretersmodule.c
+++ b/Modules/_xxsubinterpretersmodule.c
@@ -15,10 +15,11 @@ static char *
_copy_raw_string(PyObject *strobj)
{
const char *str = PyUnicode_AsUTF8(strobj);
+ char *copied;
if (str == NULL) {
return NULL;
}
- char *copied = PyMem_Malloc(strlen(str)+1);
+ copied = PyMem_Malloc(strlen(str)+1);
if (copied == NULL) {
PyErr_NoMemory();
return NULL;
@@ -72,16 +73,20 @@ _sharednsitem_clear(struct _sharednsitem *item)
static int
_sharednsitem_apply(struct _sharednsitem *item, PyObject *ns)
{
- PyObject *name = PyUnicode_FromString(item->name);
+ PyObject *name;
+ PyObject *value;
+ int res;
+
+ name = PyUnicode_FromString(item->name);
if (name == NULL) {
return -1;
}
- PyObject *value = _PyCrossInterpreterData_NewObject(&item->data);
+ value = _PyCrossInterpreterData_NewObject(&item->data);
if (value == NULL) {
Py_DECREF(name);
return -1;
}
- int res = PyDict_SetItem(ns, name, value);
+ res = PyDict_SetItem(ns, name, value);
Py_DECREF(name);
Py_DECREF(value);
return res;
@@ -113,7 +118,8 @@ _sharedns_new(Py_ssize_t len)
static void
_sharedns_free(_sharedns *shared)
{
- for (Py_ssize_t i=0; i < shared->len; i++) {
+ Py_ssize_t i;
+ for (i=0; i < shared->len; i++) {
_sharednsitem_clear(&shared->items[i]);
}
PyMem_Free(shared->items);
@@ -123,20 +129,25 @@ _sharedns_free(_sharedns *shared)
static _sharedns *
_get_shared_ns(PyObject *shareable)
{
+ Py_ssize_t len;
+ _sharedns *shared;
+ Py_ssize_t pos;
+ Py_ssize_t i;
+
if (shareable == NULL || shareable == Py_None) {
return NULL;
}
- Py_ssize_t len = PyDict_Size(shareable);
+ len = PyDict_Size(shareable);
if (len == 0) {
return NULL;
}
- _sharedns *shared = _sharedns_new(len);
+ shared = _sharedns_new(len);
if (shared == NULL) {
return NULL;
}
- Py_ssize_t pos = 0;
- for (Py_ssize_t i=0; i < len; i++) {
+ pos = 0;
+ for (i=0; i < len; i++) {
PyObject *key, *value;
if (PyDict_Next(shareable, &pos, &key, &value) == 0) {
break;
@@ -155,7 +166,8 @@ _get_shared_ns(PyObject *shareable)
static int
_sharedns_apply(_sharedns *shared, PyObject *ns)
{
- for (Py_ssize_t i=0; i < shared->len; i++) {
+ Py_ssize_t i;
+ for (i=0; i < shared->len; i++) {
if (_sharednsitem_apply(&shared->items[i], ns) != 0) {
return -1;
}
@@ -207,15 +219,18 @@ _sharedexception_free(_sharedexception *exc)
static _sharedexception *
_sharedexception_bind(PyObject *exctype, PyObject *exc, PyObject *tb)
{
+ char *failure;
+ _sharedexception *err;
+ PyObject *name;
assert(exctype != NULL);
- char *failure = NULL;
+ failure = NULL;
- _sharedexception *err = _sharedexception_new();
+ err = _sharedexception_new();
if (err == NULL) {
goto finally;
}
- PyObject *name = PyUnicode_FromFormat("%S", exctype);
+ name = PyUnicode_FromFormat("%S", exctype);
if (name == NULL) {
failure = "unable to format exception type name";
goto finally;
@@ -818,9 +833,10 @@ _channel_next(_PyChannelState *chan, int64_t interp)
static int
_channel_close_interpreter(_PyChannelState *chan, int64_t interp, int end)
{
+ int res;
PyThread_acquire_lock(chan->mutex, WAIT_LOCK);
- int res = -1;
+ res = -1;
if (!chan->open) {
PyErr_SetString(ChannelClosedError, "channel already closed");
goto done;
@@ -969,13 +985,15 @@ _channels_next_id(_channels *channels) // needs lock
static _PyChannelState *
_channels_lookup(_channels *channels, int64_t id, PyThread_type_lock *pmutex)
{
- _PyChannelState *chan = NULL;
+ _PyChannelState *chan;
+ _channelref *ref;
+ chan = NULL;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
if (pmutex != NULL) {
*pmutex = NULL;
}
- _channelref *ref = _channelref_find(channels->head, id, NULL);
+ ref = _channelref_find(channels->head, id, NULL);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", id);
goto done;
@@ -1001,15 +1019,18 @@ _channels_lookup(_channels *channels, int64_t id, PyThread_type_lock *pmutex)
static int64_t
_channels_add(_channels *channels, _PyChannelState *chan)
{
- int64_t cid = -1;
+ int64_t cid;
+ int64_t id;
+ _channelref *ref;
+ cid = -1;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
// Create a new ref.
- int64_t id = _channels_next_id(channels);
+ id = _channels_next_id(channels);
if (id < 0) {
goto done;
}
- _channelref *ref = _channelref_new(id, chan);
+ ref = _channelref_new(id, chan);
if (ref == NULL) {
goto done;
}
@@ -1034,12 +1055,13 @@ _channels_close(_channels *channels, int64_t cid, _PyChannelState **pchan,
int end, int force)
{
int res = -1;
+ _channelref *ref;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
if (pchan != NULL) {
*pchan = NULL;
}
- _channelref *ref = _channelref_find(channels->head, cid, NULL);
+ ref = _channelref_find(channels->head, cid, NULL);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", cid);
goto done;
@@ -1112,14 +1134,16 @@ static int
_channels_remove(_channels *channels, int64_t id, _PyChannelState **pchan)
{
int res = -1;
+ _channelref *prev;
+ _channelref *ref;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
if (pchan != NULL) {
*pchan = NULL;
}
- _channelref *prev = NULL;
- _channelref *ref = _channelref_find(channels->head, id, &prev);
+ prev = NULL;
+ ref = _channelref_find(channels->head, id, &prev);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", id);
goto done;
@@ -1137,9 +1161,10 @@ static int
_channels_add_id_object(_channels *channels, int64_t id)
{
int res = -1;
+ _channelref *ref;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
- _channelref *ref = _channelref_find(channels->head, id, NULL);
+ ref = _channelref_find(channels->head, id, NULL);
if (ref == NULL) {
PyErr_Format(ChannelNotFoundError, "channel %" PRId64 " not found", id);
goto done;
@@ -1155,10 +1180,12 @@ _channels_add_id_object(_channels *channels, int64_t id)
static void
_channels_drop_id_object(_channels *channels, int64_t id)
{
+ _channelref *prev;
+ _channelref *ref;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
- _channelref *prev = NULL;
- _channelref *ref = _channelref_find(channels->head, id, &prev);
+ prev = NULL;
+ ref = _channelref_find(channels->head, id, &prev);
if (ref == NULL) {
// Already destroyed.
goto done;
@@ -1182,13 +1209,16 @@ static int64_t *
_channels_list_all(_channels *channels, int64_t *count)
{
int64_t *cids = NULL;
+ int64_t *ids;
+ _channelref *ref;
+ int64_t i;
PyThread_acquire_lock(channels->mutex, WAIT_LOCK);
- int64_t *ids = PyMem_NEW(int64_t, (Py_ssize_t)(channels->numopen));
+ ids = PyMem_NEW(int64_t, (Py_ssize_t)(channels->numopen));
if (ids == NULL) {
goto done;
}
- _channelref *ref = channels->head;
- for (int64_t i=0; ref != NULL; ref = ref->next, i++) {
+ ref = channels->head;
+ for (i=0; ref != NULL; ref = ref->next, i++) {
ids[i] = ref->id;
}
*count = channels->numopen;
@@ -1207,12 +1237,14 @@ struct _channel_closing {
static int
_channel_set_closing(struct _channelref *ref, PyThread_type_lock mutex) {
- struct _channel *chan = ref->chan;
+ struct _channel *chan;
+ int res;
+ chan = ref->chan;
if (chan == NULL) {
// already closed
return 0;
}
- int res = -1;
+ res = -1;
PyThread_acquire_lock(chan->mutex, WAIT_LOCK);
if (chan->closing != NULL) {
PyErr_SetString(ChannelClosedError, "channel closed");
@@ -1242,11 +1274,13 @@ _channel_clear_closing(struct _channel *chan) {
static void
_channel_finish_closing(struct _channel *chan) {
- struct _channel_closing *closing = chan->closing;
+ struct _channel_closing *closing;
+ _channelref *ref;
+ closing = chan->closing;
if (closing == NULL) {
return;
}
- _channelref *ref = closing->ref;
+ ref = closing->ref;
_channel_clear_closing(chan);
// Do the things that would have been done in _channels_close().
ref->chan = NULL;
@@ -1258,11 +1292,13 @@ _channel_finish_closing(struct _channel *chan) {
static int64_t
_channel_create(_channels *channels)
{
- _PyChannelState *chan = _channel_new();
+ _PyChannelState *chan;
+ int64_t id;
+ chan = _channel_new();
if (chan == NULL) {
return -1;
}
- int64_t id = _channels_add(channels, chan);
+ id = _channels_add(channels, chan);
if (id < 0) {
_channel_free(chan);
return -1;
@@ -1286,14 +1322,19 @@ _channel_destroy(_channels *channels, int64_t id)
static int
_channel_send(_channels *channels, int64_t id, PyObject *obj)
{
- PyInterpreterState *interp = _get_current();
+ PyInterpreterState *interp;
+ PyThread_type_lock mutex;
+ _PyChannelState *chan;
+ _PyCrossInterpreterData *data;
+ int res;
+ interp = _get_current();
if (interp == NULL) {
return -1;
}
// Look up the channel.
- PyThread_type_lock mutex = NULL;
- _PyChannelState *chan = _channels_lookup(channels, id, &mutex);
+ mutex = NULL;
+ chan = _channels_lookup(channels, id, &mutex);
if (chan == NULL) {
return -1;
}
@@ -1306,7 +1347,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
}
// Convert the object to cross-interpreter data.
- _PyCrossInterpreterData *data = PyMem_NEW(_PyCrossInterpreterData, 1);
+ data = PyMem_NEW(_PyCrossInterpreterData, 1);
if (data == NULL) {
PyThread_release_lock(mutex);
return -1;
@@ -1318,7 +1359,7 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
}
// Add the data to the channel.
- int res = _channel_add(chan, PyInterpreterState_GetID(interp), data);
+ res = _channel_add(chan, PyInterpreterState_GetID(interp), data);
PyThread_release_lock(mutex);
if (res != 0) {
_PyCrossInterpreterData_Release(data);
@@ -1332,28 +1373,33 @@ _channel_send(_channels *channels, int64_t id, PyObject *obj)
static PyObject *
_channel_recv(_channels *channels, int64_t id)
{
- PyInterpreterState *interp = _get_current();
+ PyInterpreterState *interp;
+ PyThread_type_lock mutex;
+ _PyChannelState *chan;
+ _PyCrossInterpreterData *data;
+ PyObject *obj;
+ interp = _get_current();
if (interp == NULL) {
return NULL;
}
// Look up the channel.
- PyThread_type_lock mutex = NULL;
- _PyChannelState *chan = _channels_lookup(channels, id, &mutex);
+ mutex = NULL;
+ chan = _channels_lookup(channels, id, &mutex);
if (chan == NULL) {
return NULL;
}
// Past this point we are responsible for releasing the mutex.
// Pop off the next item from the channel.
- _PyCrossInterpreterData *data = _channel_next(chan, PyInterpreterState_GetID(interp));
+ data = _channel_next(chan, PyInterpreterState_GetID(interp));
PyThread_release_lock(mutex);
if (data == NULL) {
return NULL;
}
// Convert the data back to an object.
- PyObject *obj = _PyCrossInterpreterData_NewObject(data);
+ obj = _PyCrossInterpreterData_NewObject(data);
_PyCrossInterpreterData_Release(data);
PyMem_Free(data);
if (obj == NULL) {
@@ -1366,21 +1412,25 @@ _channel_recv(_channels *channels, int64_t id)
static int
_channel_drop(_channels *channels, int64_t id, int send, int recv)
{
- PyInterpreterState *interp = _get_current();
+ PyInterpreterState *interp;
+ PyThread_type_lock mutex;
+ _PyChannelState *chan;
+ int res;
+ interp = _get_current();
if (interp == NULL) {
return -1;
}
// Look up the channel.
- PyThread_type_lock mutex = NULL;
- _PyChannelState *chan = _channels_lookup(channels, id, &mutex);
+ mutex = NULL;
+ chan = _channels_lookup(channels, id, &mutex);
if (chan == NULL) {
return -1;
}
// Past this point we are responsible for releasing the mutex.
// Close one or both of the two ends.
- int res = _channel_close_interpreter(chan, PyInterpreterState_GetID(interp), send-recv);
+ res = _channel_close_interpreter(chan, PyInterpreterState_GetID(interp), send-recv);
PyThread_release_lock(mutex);
return res;
}
@@ -1395,7 +1445,9 @@ static int
_channel_is_associated(_channels *channels, int64_t cid, int64_t interp,
int send)
{
- _PyChannelState *chan = _channels_lookup(channels, cid, NULL);
+ _PyChannelState *chan;
+ _channelend *end;
+ chan = _channels_lookup(channels, cid, NULL);
if (chan == NULL) {
return -1;
} else if (send && chan->closing != NULL) {
@@ -1403,8 +1455,8 @@ _channel_is_associated(_channels *channels, int64_t cid, int64_t interp,
return -1;
}
- _channelend *end = _channelend_find(send ? chan->ends->send : chan->ends->recv,
- interp, NULL);
+ end = _channelend_find(send ? chan->ends->send : chan->ends->recv,
+ interp, NULL);
return (end != NULL && end->open);
}
@@ -1486,6 +1538,7 @@ channelid_new(PyTypeObject *cls, PyObject *args, PyObject *kwds)
int recv = -1;
int force = 0;
int resolve = 0;
+ int end;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O&|$pppp:ChannelID.__new__", kwlist,
channel_id_converter, &cid, &send, &recv, &force, &resolve))
@@ -1498,7 +1551,7 @@ channelid_new(PyTypeObject *cls, PyObject *args, PyObject *kwds)
return NULL;
}
- int end = 0;
+ end = 0;
if (send == 1) {
if (recv == 0 || recv == -1) {
end = CHANNEL_SEND;
@@ -1601,10 +1654,11 @@ channelid_hash(PyObject *self)
{
channelid *cid = (channelid *)self;
PyObject *id = PyLong_FromLongLong(cid->id);
+ Py_hash_t hash;
if (id == NULL) {
return -1;
}
- Py_hash_t hash = PyObject_Hash(id);
+ hash = PyObject_Hash(id);
Py_DECREF(id);
return hash;
}
@@ -1612,6 +1666,8 @@ channelid_hash(PyObject *self)
static PyObject *
channelid_richcompare(PyObject *self, PyObject *other, int op)
{
+ channelid *cid;
+ int equal;
if (op != Py_EQ && op != Py_NE) {
Py_RETURN_NOTIMPLEMENTED;
}
@@ -1620,27 +1676,29 @@ channelid_richcompare(PyObject *self, PyObject *other, int op)
Py_RETURN_NOTIMPLEMENTED;
}
- channelid *cid = (channelid *)self;
- int equal;
+ cid = (channelid *)self;
if (PyObject_TypeCheck(other, &ChannelIDtype)) {
channelid *othercid = (channelid *)other;
equal = (cid->end == othercid->end) && (cid->id == othercid->id);
}
else if (PyLong_Check(other)) {
- /* Fast path */
int overflow;
- long long othercid = PyLong_AsLongLongAndOverflow(other, &overflow);
+ PY_LONG_LONG othercid;
+ /* Fast path */
+ othercid = PyLong_AsLongLongAndOverflow(other, &overflow);
if (othercid == -1 && PyErr_Occurred()) {
return NULL;
}
equal = !overflow && (othercid >= 0) && (cid->id == othercid);
}
else if (PyNumber_Check(other)) {
- PyObject *pyid = PyLong_FromLongLong(cid->id);
+ PyObject *pyid;
+ PyObject *res;
+ pyid = PyLong_FromLongLong(cid->id);
if (pyid == NULL) {
return NULL;
}
- PyObject *res = PyObject_RichCompare(pyid, other, op);
+ res = PyObject_RichCompare(pyid, other, op);
Py_DECREF(pyid);
return res;
}
@@ -1658,6 +1716,9 @@ static PyObject *
_channel_from_cid(PyObject *cid, int end)
{
PyObject *highlevel = PyImport_ImportModule("interpreters");
+ const char *clsname;
+ PyObject *cls;
+ PyObject *chan;
if (highlevel == NULL) {
PyErr_Clear();
highlevel = PyImport_ImportModule("test.support.interpreters");
@@ -1665,14 +1726,14 @@ _channel_from_cid(PyObject *cid, int end)
return NULL;
}
}
- const char *clsname = (end == CHANNEL_RECV) ? "RecvChannel" :
- "SendChannel";
- PyObject *cls = PyObject_GetAttrString(highlevel, clsname);
+ clsname = (end == CHANNEL_RECV) ? "RecvChannel" :
+ "SendChannel";
+ cls = PyObject_GetAttrString(highlevel, clsname);
Py_DECREF(highlevel);
if (cls == NULL) {
return NULL;
}
- PyObject *chan = PyObject_CallFunctionObjArgs(cls, cid, NULL);
+ chan = PyObject_CallFunctionObjArgs(cls, cid, NULL);
Py_DECREF(cls);
if (chan == NULL) {
return NULL;
@@ -1690,9 +1751,11 @@ static PyObject *
_channelid_from_xid(_PyCrossInterpreterData *data)
{
struct _channelid_xid *xid = (struct _channelid_xid *)data->data;
+ PyObject *cid;
+ PyObject *chan;
// Note that we do not preserve the "resolve" flag.
- PyObject *cid = (PyObject *)newchannelid(&ChannelIDtype, xid->id, xid->end,
- _global_channels(), 0, 0);
+ cid = (PyObject *)newchannelid(&ChannelIDtype, xid->id, xid->end,
+ _global_channels(), 0, 0);
if (xid->end == 0) {
return cid;
}
@@ -1701,7 +1764,7 @@ _channelid_from_xid(_PyCrossInterpreterData *data)
}
/* Try returning a high-level channel end but fall back to the ID. */
- PyObject *chan = _channel_from_cid(cid, xid->end);
+ chan = _channel_from_cid(cid, xid->end);
if (chan == NULL) {
PyErr_Clear();
return cid;
@@ -1831,6 +1894,7 @@ static int
_is_running(PyInterpreterState *interp)
{
PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
+ _PyInterpreterFrame *frame;
if (PyThreadState_Next(tstate) != NULL) {
PyErr_SetString(PyExc_RuntimeError,
"interpreter has more than one thread");
@@ -1838,7 +1902,7 @@ _is_running(PyInterpreterState *interp)
}
assert(!PyErr_Occurred());
- _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+ frame = tstate->cframe->current_frame;
if (frame == NULL) {
return 0;
}
@@ -1866,12 +1930,15 @@ _run_script(PyInterpreterState *interp, const char *codestr,
PyObject *exctype = NULL;
PyObject *excval = NULL;
PyObject *tb = NULL;
+ PyObject *ns;
+ PyObject *result;
+ _sharedexception *sharedexc;
PyObject *main_mod = _PyInterpreterState_GetMainModule(interp);
if (main_mod == NULL) {
goto error;
}
- PyObject *ns = PyModule_GetDict(main_mod); // borrowed
+ ns = PyModule_GetDict(main_mod); // borrowed
Py_DECREF(main_mod);
if (ns == NULL) {
goto error;
@@ -1887,7 +1954,7 @@ _run_script(PyInterpreterState *interp, const char *codestr,
}
// Run the string (see PyRun_SimpleStringFlags).
- PyObject *result = PyRun_StringFlags(codestr, Py_file_input, ns, ns, NULL);
+ result = PyRun_StringFlags(codestr, Py_file_input, ns, ns, NULL);
Py_DECREF(ns);
if (result == NULL) {
goto error;
@@ -1902,7 +1969,7 @@ _run_script(PyInterpreterState *interp, const char *codestr,
error:
PyErr_Fetch(&exctype, &excval, &tb);
- _sharedexception *sharedexc = _sharedexception_bind(exctype, excval, tb);
+ sharedexc = _sharedexception_bind(exctype, excval, tb);
Py_XDECREF(exctype);
Py_XDECREF(excval);
Py_XDECREF(tb);
@@ -1922,27 +1989,32 @@ static int
_run_script_in_interpreter(PyInterpreterState *interp, const char *codestr,
PyObject *shareables)
{
+ _sharedns *shared;
+ PyThreadState *save_tstate;
+ PyThreadState *tstate;
+ _sharedexception *exc;
+ int result;
if (_ensure_not_running(interp) < 0) {
return -1;
}
- _sharedns *shared = _get_shared_ns(shareables);
+ shared = _get_shared_ns(shareables);
if (shared == NULL && PyErr_Occurred()) {
return -1;
}
// Switch to interpreter.
- PyThreadState *save_tstate = NULL;
+ save_tstate = NULL;
if (interp != PyInterpreterState_Get()) {
// XXX Using the "head" thread isn't strictly correct.
- PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
+ tstate = PyInterpreterState_ThreadHead(interp);
// XXX Possible GILState issues?
save_tstate = PyThreadState_Swap(tstate);
}
// Run the script.
- _sharedexception *exc = NULL;
- int result = _run_script(interp, codestr, shared, &exc);
+ exc = NULL;
+ result = _run_script(interp, codestr, shared, &exc);
// Switch back.
if (save_tstate != NULL) {
@@ -1996,15 +2068,19 @@ interp_create(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"isolated", NULL};
int isolated = 1;
+ PyThreadState *save_tstate;
+ PyThreadState *tstate;
+ PyInterpreterState *interp;
+ PyObject *idobj;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|$i:create", kwlist,
&isolated)) {
return NULL;
}
// Create and initialize the new interpreter.
- PyThreadState *save_tstate = _PyThreadState_GET();
+ save_tstate = _PyThreadState_GET();
// XXX Possible GILState issues?
- PyThreadState *tstate = _Py_NewInterpreter(isolated);
+ tstate = _Py_NewInterpreter(isolated);
PyThreadState_Swap(save_tstate);
if (tstate == NULL) {
/* Since no new thread state was created, there is no exception to
@@ -2013,8 +2089,8 @@ interp_create(PyObject *self, PyObject *args, PyObject *kwds)
PyErr_SetString(PyExc_RuntimeError, "interpreter creation failed");
return NULL;
}
- PyInterpreterState *interp = PyThreadState_GetInterpreter(tstate);
- PyObject *idobj = _PyInterpreterState_GetIDObject(interp);
+ interp = PyThreadState_GetInterpreter(tstate);
+ idobj = _PyInterpreterState_GetIDObject(interp);
if (idobj == NULL) {
// XXX Possible GILState issues?
save_tstate = PyThreadState_Swap(tstate);
@@ -2037,6 +2113,10 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"id", NULL};
PyObject *id;
+ PyInterpreterState *interp;
+ PyInterpreterState *current;
+ PyThreadState *tstate;
+ PyThreadState *save_tstate;
// XXX Use "L" for id?
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O:destroy", kwlist, &id)) {
@@ -2044,13 +2124,13 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
}
// Look up the interpreter.
- PyInterpreterState *interp = _PyInterpreterID_LookUp(id);
+ interp = _PyInterpreterID_LookUp(id);
if (interp == NULL) {
return NULL;
}
// Ensure we don't try to destroy the current interpreter.
- PyInterpreterState *current = _get_current();
+ current = _get_current();
if (current == NULL) {
return NULL;
}
@@ -2068,9 +2148,9 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
}
// Destroy the interpreter.
- PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
+ tstate = PyInterpreterState_ThreadHead(interp);
// XXX Possible GILState issues?
- PyThreadState *save_tstate = PyThreadState_Swap(tstate);
+ save_tstate = PyThreadState_Swap(tstate);
Py_EndInterpreter(tstate);
PyThreadState_Swap(save_tstate);
@@ -2091,6 +2171,7 @@ interp_list_all(PyObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *ids, *id;
PyInterpreterState *interp;
+ int res;
ids = PyList_New(0);
if (ids == NULL) {
@@ -2105,7 +2186,7 @@ interp_list_all(PyObject *self, PyObject *Py_UNUSED(ignored))
return NULL;
}
// insert at front of list
- int res = PyList_Insert(ids, 0, id);
+ res = PyList_Insert(ids, 0, id);
Py_DECREF(id);
if (res < 0) {
Py_DECREF(ids);
@@ -2160,6 +2241,9 @@ interp_run_string(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"id", "script", "shared", NULL};
PyObject *id, *code;
PyObject *shared = NULL;
+ PyInterpreterState *interp;
+ Py_ssize_t size;
+ const char *codestr;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OU|O:run_string", kwlist,
&id, &code, &shared)) {
@@ -2167,14 +2251,13 @@ interp_run_string(PyObject *self, PyObject *args, PyObject *kwds)
}
// Look up the interpreter.
- PyInterpreterState *interp = _PyInterpreterID_LookUp(id);
+ interp = _PyInterpreterID_LookUp(id);
if (interp == NULL) {
return NULL;
}
// Extract code.
- Py_ssize_t size;
- const char *codestr = PyUnicode_AsUTF8AndSize(code, &size);
+ codestr = PyUnicode_AsUTF8AndSize(code, &size);
if (codestr == NULL) {
return NULL;
}
@@ -2228,16 +2311,18 @@ interp_is_running(PyObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"id", NULL};
PyObject *id;
+ PyInterpreterState *interp;
+ int is_running;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O:is_running", kwlist, &id)) {
return NULL;
}
- PyInterpreterState *interp = _PyInterpreterID_LookUp(id);
+ interp = _PyInterpreterID_LookUp(id);
if (interp == NULL) {
return NULL;
}
- int is_running = _is_running(interp);
+ is_running = _is_running(interp);
if (is_running < 0) {
return NULL;
}
@@ -2256,11 +2341,12 @@ static PyObject *
channel_create(PyObject *self, PyObject *Py_UNUSED(ignored))
{
int64_t cid = _channel_create(&_globals.channels);
+ PyObject *id;
if (cid < 0) {
return NULL;
}
- PyObject *id = (PyObject *)newchannelid(&ChannelIDtype, cid, 0,
- &_globals.channels, 0, 0);
+ id = (PyObject *)newchannelid(&ChannelIDtype, cid, 0,
+ &_globals.channels, 0, 0);
if (id == NULL) {
if (_channel_destroy(&_globals.channels, cid) != 0) {
// XXX issue a warning?
@@ -2303,18 +2389,21 @@ channel_list_all(PyObject *self, PyObject *Py_UNUSED(ignored))
{
int64_t count = 0;
int64_t *cids = _channels_list_all(&_globals.channels, &count);
+ PyObject *ids;
+ int64_t *cur;
+ int64_t i;
if (cids == NULL) {
if (count == 0) {
return PyList_New(0);
}
return NULL;
}
- PyObject *ids = PyList_New((Py_ssize_t)count);
+ ids = PyList_New((Py_ssize_t)count);
if (ids == NULL) {
goto finally;
}
- int64_t *cur = cids;
- for (int64_t i=0; i < count; cur++, i++) {
+ cur = cids;
+ for (i=0; i < count; cur++, i++) {
PyObject *id = (PyObject *)newchannelid(&ChannelIDtype, *cur, 0,
&_globals.channels, 0, 0);
if (id == NULL) {
@@ -2344,6 +2433,7 @@ channel_list_interpreters(PyObject *self, PyObject *args, PyObject *kwds)
int64_t id;
PyObject *ids, *id_obj;
PyInterpreterState *interp;
+ int res;
if (!PyArg_ParseTupleAndKeywords(
args, kwds, "O&$p:channel_list_interpreters",
@@ -2360,7 +2450,7 @@ channel_list_interpreters(PyObject *self, PyObject *args, PyObject *kwds)
while (interp != NULL) {
id = PyInterpreterState_GetID(interp);
assert(id >= 0);
- int res = _channel_is_associated(&_globals.channels, cid, id, send);
+ res = _channel_is_associated(&_globals.channels, cid, id, send);
if (res < 0) {
goto except;
}
@@ -2425,13 +2515,14 @@ channel_recv(PyObject *self, PyObject *args, PyObject *kwds)
static char *kwlist[] = {"cid", "default", NULL};
int64_t cid;
PyObject *dflt = NULL;
+ PyObject *obj;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O:channel_recv", kwlist,
channel_id_converter, &cid, &dflt)) {
return NULL;
}
Py_XINCREF(dflt);
- PyObject *obj = _channel_recv(&_globals.channels, cid);
+ obj = _channel_recv(&_globals.channels, cid);
if (obj != NULL) {
Py_XDECREF(dflt);
return obj;
@@ -2606,6 +2697,8 @@ static struct PyModuleDef interpretersmodule = {
PyMODINIT_FUNC
PyInit__xxsubinterpreters(void)
{
+ PyObject *module;
+ PyObject *ns;
if (_init_globals() != 0) {
return NULL;
}
@@ -2616,13 +2709,13 @@ PyInit__xxsubinterpreters(void)
}
/* Create the module */
- PyObject *module = PyModule_Create(&interpretersmodule);
+ module = PyModule_Create(&interpretersmodule);
if (module == NULL) {
return NULL;
}
/* Add exception types */
- PyObject *ns = PyModule_GetDict(module); // borrowed
+ ns = PyModule_GetDict(module); // borrowed
if (interp_exceptions_init(ns) != 0) {
return NULL;
}
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/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h
index ba8fad2..ee348b7 100644
--- a/Modules/cjkcodecs/cjkcodecs.h
+++ b/Modules/cjkcodecs/cjkcodecs.h
@@ -245,12 +245,14 @@ static const struct dbcs_map *mapping_list;
static PyObject *
getmultibytecodec(void)
{
- PyObject *mod = PyImport_ImportModuleNoBlock("_multibytecodec");
+ PyObject *mod;
+ PyObject *cofunc;
+ mod = PyImport_ImportModuleNoBlock("_multibytecodec");
if (mod == NULL) {
return NULL;
}
- PyObject *cofunc = PyObject_GetAttrString(mod, "__create_codec");
+ cofunc = PyObject_GetAttrString(mod, "__create_codec");
Py_DECREF(mod);
return cofunc;
}
@@ -301,12 +303,13 @@ static int
register_maps(PyObject *module)
{
const struct dbcs_map *h;
+ PyObject *capsule;
for (h = mapping_list; h->charset[0] != '\0'; h++) {
char mhname[256] = "__map_";
strcpy(mhname + sizeof("__map_") - 1, h->charset);
- PyObject *capsule = PyCapsule_New((void *)h,
+ capsule = PyCapsule_New((void *)h,
PyMultibyteCodec_CAPSULE_NAME, NULL);
if (capsule == NULL) {
return -1;
@@ -415,10 +418,14 @@ static PyModuleDef_Slot _cjk_slots[] = {
#define I_AM_A_MODULE_FOR(loc) \
static struct PyModuleDef _cjk_module = { \
PyModuleDef_HEAD_INIT, \
- .m_name = "_codecs_"#loc, \
- .m_size = 0, \
- .m_methods = _cjk_methods, \
- .m_slots = _cjk_slots, \
+ "_codecs_"#loc, \
+ NULL, \
+ 0, \
+ _cjk_methods, \
+ _cjk_slots, \
+ NULL, \
+ NULL, \
+ NULL, \
}; \
\
PyMODINIT_FUNC \
diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c
index 4769ab2..1393db7 100644
--- a/Modules/cjkcodecs/multibytecodec.c
+++ b/Modules/cjkcodecs/multibytecodec.c
@@ -730,8 +730,9 @@ multibytecodec_traverse(PyObject *self, visitproc visit, void *arg)
static void
multibytecodec_dealloc(MultibyteCodecObject *self)
{
+ PyTypeObject *tp;
PyObject_GC_UnTrack(self);
- PyTypeObject *tp = Py_TYPE(self);
+ tp = Py_TYPE(self);
tp->tp_free(self);
Py_DECREF(tp);
}
@@ -745,11 +746,12 @@ static PyType_Slot multibytecodec_slots[] = {
};
static PyType_Spec multibytecodec_spec = {
- .name = MODULE_NAME ".MultibyteCodec",
- .basicsize = sizeof(MultibyteCodecObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = multibytecodec_slots,
+ MODULE_NAME ".MultibyteCodec",
+ sizeof(MultibyteCodecObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE,
+ multibytecodec_slots,
};
@@ -1033,6 +1035,7 @@ mbiencoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
MultibyteIncrementalEncoderObject *self;
PyObject *codec = NULL;
char *errors = NULL;
+ _multibytecodec_state *state;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s:IncrementalEncoder",
incnewkwarglist, &errors))
@@ -1046,7 +1049,7 @@ mbiencoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (codec == NULL)
goto errorexit;
- _multibytecodec_state *state = _multibyte_codec_find_state_by_type(type);
+ state = _multibyte_codec_find_state_by_type(type);
if (!MultibyteCodec_Check(state, codec)) {
PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
goto errorexit;
@@ -1108,11 +1111,12 @@ static PyType_Slot encoder_slots[] = {
};
static PyType_Spec encoder_spec = {
- .name = MODULE_NAME ".MultibyteIncrementalEncoder",
- .basicsize = sizeof(MultibyteIncrementalEncoderObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = encoder_slots,
+ MODULE_NAME ".MultibyteIncrementalEncoder",
+ sizeof(MultibyteIncrementalEncoderObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_IMMUTABLETYPE,
+ encoder_slots,
};
@@ -1308,6 +1312,7 @@ mbidecoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
MultibyteIncrementalDecoderObject *self;
PyObject *codec = NULL;
char *errors = NULL;
+ _multibytecodec_state *state;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|s:IncrementalDecoder",
incnewkwarglist, &errors))
@@ -1321,7 +1326,7 @@ mbidecoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (codec == NULL)
goto errorexit;
- _multibytecodec_state *state = _multibyte_codec_find_state_by_type(type);
+ state = _multibyte_codec_find_state_by_type(type);
if (!MultibyteCodec_Check(state, codec)) {
PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
goto errorexit;
@@ -1382,11 +1387,12 @@ static PyType_Slot decoder_slots[] = {
};
static PyType_Spec decoder_spec = {
- .name = MODULE_NAME ".MultibyteIncrementalDecoder",
- .basicsize = sizeof(MultibyteIncrementalDecoderObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = decoder_slots,
+ MODULE_NAME ".MultibyteIncrementalDecoder",
+ sizeof(MultibyteIncrementalDecoderObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_IMMUTABLETYPE,
+ decoder_slots,
};
static PyObject *
@@ -1625,6 +1631,7 @@ mbstreamreader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
MultibyteStreamReaderObject *self;
PyObject *stream, *codec = NULL;
char *errors = NULL;
+ _multibytecodec_state *state;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s:StreamReader",
streamkwarglist, &stream, &errors))
@@ -1638,7 +1645,7 @@ mbstreamreader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (codec == NULL)
goto errorexit;
- _multibytecodec_state *state = _multibyte_codec_find_state_by_type(type);
+ state = _multibyte_codec_find_state_by_type(type);
if (!MultibyteCodec_Check(state, codec)) {
PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
goto errorexit;
@@ -1704,11 +1711,12 @@ static PyType_Slot reader_slots[] = {
};
static PyType_Spec reader_spec = {
- .name = MODULE_NAME ".MultibyteStreamReader",
- .basicsize = sizeof(MultibyteStreamReaderObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = reader_slots,
+ MODULE_NAME ".MultibyteStreamReader",
+ sizeof(MultibyteStreamReaderObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_IMMUTABLETYPE,
+ reader_slots,
};
static int
@@ -1744,7 +1752,8 @@ _multibytecodec_MultibyteStreamWriter_write_impl(MultibyteStreamWriterObject *se
PyObject *strobj)
/*[clinic end generated code: output=68ade3aea26410ac input=199f26f68bd8425a]*/
{
- _multibytecodec_state *state = PyType_GetModuleState(cls);
+ _multibytecodec_state *state;
+ state = PyType_GetModuleState(cls);
assert(state != NULL);
if (mbstreamwriter_iwrite(self, strobj, state->str_write)) {
return NULL;
@@ -1768,6 +1777,7 @@ _multibytecodec_MultibyteStreamWriter_writelines_impl(MultibyteStreamWriterObjec
{
PyObject *strobj;
int i, r;
+ _multibytecodec_state *state;
if (!PySequence_Check(lines)) {
PyErr_SetString(PyExc_TypeError,
@@ -1775,7 +1785,7 @@ _multibytecodec_MultibyteStreamWriter_writelines_impl(MultibyteStreamWriterObjec
return NULL;
}
- _multibytecodec_state *state = PyType_GetModuleState(cls);
+ state = PyType_GetModuleState(cls);
assert(state != NULL);
for (i = 0; i < PySequence_Length(lines); i++) {
/* length can be changed even within this loop */
@@ -1809,6 +1819,7 @@ _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *se
/*[clinic end generated code: output=32ef224c2a38aa3d input=28af6a9cd38d1979]*/
{
PyObject *pwrt;
+ _multibytecodec_state *state;
if (!self->pending)
Py_RETURN_NONE;
@@ -1826,7 +1837,7 @@ _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *se
assert(PyBytes_Check(pwrt));
- _multibytecodec_state *state = PyType_GetModuleState(cls);
+ state = PyType_GetModuleState(cls);
assert(state != NULL);
if (PyBytes_Size(pwrt) > 0) {
@@ -1849,6 +1860,7 @@ mbstreamwriter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
MultibyteStreamWriterObject *self;
PyObject *stream, *codec = NULL;
char *errors = NULL;
+ _multibytecodec_state *state;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s:StreamWriter",
streamkwarglist, &stream, &errors))
@@ -1862,7 +1874,7 @@ mbstreamwriter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (codec == NULL)
goto errorexit;
- _multibytecodec_state *state = _multibyte_codec_find_state_by_type(type);
+ state = _multibyte_codec_find_state_by_type(type);
if (!MultibyteCodec_Check(state, codec)) {
PyErr_SetString(PyExc_TypeError, "codec is unexpected type");
goto errorexit;
@@ -1942,11 +1954,12 @@ static PyType_Slot writer_slots[] = {
};
static PyType_Spec writer_spec = {
- .name = MODULE_NAME ".MultibyteStreamWriter",
- .basicsize = sizeof(MultibyteStreamWriterObject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_IMMUTABLETYPE),
- .slots = writer_slots,
+ MODULE_NAME ".MultibyteStreamWriter",
+ sizeof(MultibyteStreamWriterObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_IMMUTABLETYPE,
+ writer_slots,
};
@@ -1963,6 +1976,7 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
{
MultibyteCodecObject *self;
MultibyteCodec *codec;
+ _multibytecodec_state *state;
if (!PyCapsule_IsValid(arg, PyMultibyteCodec_CAPSULE_NAME)) {
PyErr_SetString(PyExc_ValueError, "argument type invalid");
@@ -1973,7 +1987,7 @@ _multibytecodec___create_codec(PyObject *module, PyObject *arg)
if (codec->codecinit != NULL && codec->codecinit(codec->config) != 0)
return NULL;
- _multibytecodec_state *state = _multibytecodec_get_state(module);
+ state = _multibytecodec_get_state(module);
self = PyObject_GC_New(MultibyteCodecObject, state->multibytecodec_type);
if (self == NULL)
return NULL;
@@ -2064,14 +2078,15 @@ static PyModuleDef_Slot _multibytecodec_slots[] = {
};
static struct PyModuleDef _multibytecodecmodule = {
- .m_base = PyModuleDef_HEAD_INIT,
- .m_name = "_multibytecodec",
- .m_size = sizeof(_multibytecodec_state),
- .m_methods = _multibytecodec_methods,
- .m_slots = _multibytecodec_slots,
- .m_traverse = _multibytecodec_traverse,
- .m_clear = _multibytecodec_clear,
- .m_free = _multibytecodec_free,
+ PyModuleDef_HEAD_INIT,
+ "_multibytecodec",
+ NULL,
+ sizeof(_multibytecodec_state),
+ _multibytecodec_methods,
+ _multibytecodec_slots,
+ _multibytecodec_traverse,
+ _multibytecodec_clear,
+ _multibytecodec_free,
};
PyMODINIT_FUNC
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/clinic/symtablemodule.c.h b/Modules/clinic/symtablemodule.c.h
index 2cd08f8..16d05e1 100644
--- a/Modules/clinic/symtablemodule.c.h
+++ b/Modules/clinic/symtablemodule.c.h
@@ -22,6 +22,7 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
PyObject *source;
PyObject *filename;
const char *startstr;
+ Py_ssize_t startstr_length;
if (!_PyArg_CheckPositional("symtable", nargs, 3, 3)) {
goto exit;
@@ -34,7 +35,6 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
_PyArg_BadArgument("symtable", "argument 3", "str", args[2]);
goto exit;
}
- Py_ssize_t startstr_length;
startstr = PyUnicode_AsUTF8AndSize(args[2], &startstr_length);
if (startstr == 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/gcmodule.c b/Modules/gcmodule.c
index 347ded8..082ee66 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -139,13 +139,14 @@ get_gc_state(void)
void
_PyGC_InitState(GCState *gcstate)
{
+ int i;
#define INIT_HEAD(GEN) \
do { \
GEN.head._gc_next = (uintptr_t)&GEN.head; \
GEN.head._gc_prev = (uintptr_t)&GEN.head; \
} while (0)
- for (int i = 0; i < NUM_GENERATIONS; i++) {
+ for (i = 0; i < NUM_GENERATIONS; i++) {
assert(gcstate->generations[i].count == 0);
INIT_HEAD(gcstate->generations[i]);
};
@@ -278,6 +279,7 @@ gc_list_remove(PyGC_Head *node)
static void
gc_list_move(PyGC_Head *node, PyGC_Head *list)
{
+ PyGC_Head *to_prev;
/* Unlink from current list. */
PyGC_Head *from_prev = GC_PREV(node);
PyGC_Head *from_next = GC_NEXT(node);
@@ -286,7 +288,7 @@ gc_list_move(PyGC_Head *node, PyGC_Head *list)
/* Relink at end of new list. */
// list must not have flags. So we can skip macros.
- PyGC_Head *to_prev = (PyGC_Head*)list->_gc_prev;
+ to_prev = (PyGC_Head*)list->_gc_prev;
_PyGCHead_SET_PREV(node, to_prev);
_PyGCHead_SET_NEXT(to_prev, node);
list->_gc_prev = (uintptr_t)node;
@@ -485,12 +487,16 @@ subtract_refs(PyGC_Head *containers)
static int
visit_reachable(PyObject *op, PyGC_Head *reachable)
{
+ PyGC_Head *gc;
+ PyGC_Head *prev;
+ PyGC_Head *next;
+ Py_ssize_t gc_refs;
if (!_PyObject_IS_GC(op)) {
return 0;
}
- PyGC_Head *gc = AS_GC(op);
- const Py_ssize_t gc_refs = gc_get_refs(gc);
+ gc = AS_GC(op);
+ gc_refs = gc_get_refs(gc);
// Ignore objects in other generation.
// This also skips objects "to the left" of the current position in
@@ -512,8 +518,8 @@ visit_reachable(PyObject *op, PyGC_Head *reachable)
*/
// Manually unlink gc from unreachable list because the list functions
// don't work right in the presence of NEXT_MASK_UNREACHABLE flags.
- PyGC_Head *prev = GC_PREV(gc);
- PyGC_Head *next = (PyGC_Head*)(gc->_gc_next & ~NEXT_MASK_UNREACHABLE);
+ prev = GC_PREV(gc);
+ next = (PyGC_Head*)(gc->_gc_next & ~NEXT_MASK_UNREACHABLE);
_PyObject_ASSERT(FROM_GC(prev),
prev->_gc_next & NEXT_MASK_UNREACHABLE);
_PyObject_ASSERT(FROM_GC(next),
@@ -557,6 +563,9 @@ visit_reachable(PyObject *op, PyGC_Head *reachable)
static void
move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
{
+ PyObject *op;
+ traverseproc traverse;
+ PyGC_Head *last;
// previous elem in the young list, used for restore gc_prev.
PyGC_Head *prev = young;
PyGC_Head *gc = GC_NEXT(young);
@@ -580,8 +589,8 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
* so we have to wait until it returns to determine
* the next object to visit.
*/
- PyObject *op = FROM_GC(gc);
- traverseproc traverse = Py_TYPE(op)->tp_traverse;
+ op = FROM_GC(gc);
+ traverse = Py_TYPE(op)->tp_traverse;
_PyObject_ASSERT_WITH_MSG(op, gc_get_refs(gc) > 0,
"refcount is too small");
// NOTE: visit_reachable may change gc->_gc_next when
@@ -609,7 +618,7 @@ move_unreachable(PyGC_Head *young, PyGC_Head *unreachable)
// We can't use gc_list_append() here because we use
// NEXT_MASK_UNREACHABLE here.
- PyGC_Head *last = GC_PREV(unreachable);
+ last = GC_PREV(unreachable);
// NOTE: Since all objects in unreachable set has
// NEXT_MASK_UNREACHABLE flag, we set it unconditionally.
// But this may pollute the unreachable list head's 'next' pointer
@@ -695,10 +704,10 @@ move_legacy_finalizers(PyGC_Head *unreachable, PyGC_Head *finalizers)
static inline void
clear_unreachable_mask(PyGC_Head *unreachable)
{
+ PyGC_Head *gc, *next;
/* Check that the list head does not have the unreachable bit set */
assert(((uintptr_t)unreachable & NEXT_MASK_UNREACHABLE) == 0);
- PyGC_Head *gc, *next;
assert((unreachable->_gc_next & NEXT_MASK_UNREACHABLE) == 0);
for (gc = GC_NEXT(unreachable); gc != unreachable; gc = next) {
_PyObject_ASSERT((PyObject*)FROM_GC(gc), gc->_gc_next & NEXT_MASK_UNREACHABLE);
@@ -929,12 +938,14 @@ handle_legacy_finalizers(PyThreadState *tstate,
GCState *gcstate,
PyGC_Head *finalizers, PyGC_Head *old)
{
+ PyGC_Head *gc;
+ PyObject *op;
assert(!_PyErr_Occurred(tstate));
assert(gcstate->garbage != NULL);
- PyGC_Head *gc = GC_NEXT(finalizers);
+ gc = GC_NEXT(finalizers);
for (; gc != finalizers; gc = GC_NEXT(gc)) {
- PyObject *op = FROM_GC(gc);
+ op = FROM_GC(gc);
if ((gcstate->debug & DEBUG_SAVEALL) || has_legacy_finalizer(op)) {
if (PyList_Append(gcstate->garbage, op) < 0) {
@@ -1046,10 +1057,11 @@ clear_freelists(PyInterpreterState *interp)
static void
show_stats_each_generations(GCState *gcstate)
{
+ int i;
char buf[100];
size_t pos = 0;
- for (int i = 0; i < NUM_GENERATIONS && pos < sizeof(buf); i++) {
+ for (i = 0; i < NUM_GENERATIONS && pos < sizeof(buf); i++) {
pos += PyOS_snprintf(buf+pos, sizeof(buf)-pos,
" %zd",
gc_list_size(GEN_HEAD(gcstate, i)));
@@ -1157,6 +1169,7 @@ static inline void
handle_resurrected_objects(PyGC_Head *unreachable, PyGC_Head* still_unreachable,
PyGC_Head *old_generation)
{
+ PyGC_Head *resurrected;
// Remove the PREV_MASK_COLLECTING from unreachable
// to prepare it for a new call to 'deduce_unreachable'
gc_list_clear_collecting(unreachable);
@@ -1164,7 +1177,7 @@ handle_resurrected_objects(PyGC_Head *unreachable, PyGC_Head* still_unreachable,
// After the call to deduce_unreachable, the 'still_unreachable' set will
// have the PREV_MARK_COLLECTING set, but the objects are going to be
// removed so we can skip the expense of clearing the flag.
- PyGC_Head* resurrected = unreachable;
+ resurrected = unreachable;
deduce_unreachable(resurrected, still_unreachable);
clear_unreachable_mask(still_unreachable);
@@ -1179,6 +1192,7 @@ gc_collect_main(PyThreadState *tstate, int generation,
Py_ssize_t *n_collected, Py_ssize_t *n_uncollectable,
int nofail)
{
+ struct gc_generation_stats *stats;
int i;
Py_ssize_t m = 0; /* # objects collected */
Py_ssize_t n = 0; /* # unreachable objects that couldn't be collected */
@@ -1186,6 +1200,7 @@ gc_collect_main(PyThreadState *tstate, int generation,
PyGC_Head *old; /* next older generation */
PyGC_Head unreachable; /* non-problematic unreachable trash */
PyGC_Head finalizers; /* objects with, & reachable from, __del__ */
+ PyGC_Head final_unreachable;
PyGC_Head *gc;
_PyTime_t t1 = 0; /* initialize to prevent a compiler warning */
GCState *gcstate = &tstate->interp->gc;
@@ -1276,7 +1291,6 @@ gc_collect_main(PyThreadState *tstate, int generation,
/* Handle any objects that may have resurrected after the call
* to 'finalize_garbage' and continue the collection with the
* objects that are still unreachable */
- PyGC_Head final_unreachable;
handle_resurrected_objects(&unreachable, &final_unreachable, old);
/* Call tp_clear on objects in the final_unreachable set. This will cause
@@ -1330,7 +1344,7 @@ gc_collect_main(PyThreadState *tstate, int generation,
*n_uncollectable = n;
}
- struct gc_generation_stats *stats = &gcstate->generation_stats[generation];
+ stats = &gcstate->generation_stats[generation];
stats->collections++;
stats->collected += m;
stats->uncollectable += n;
@@ -1351,17 +1365,21 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
int generation, Py_ssize_t collected,
Py_ssize_t uncollectable)
{
+ GCState *gcstate;
+ PyObject *info = NULL;
+ PyObject *r;
+ PyObject *cb;
+ Py_ssize_t i;
assert(!_PyErr_Occurred(tstate));
/* we may get called very early */
- GCState *gcstate = &tstate->interp->gc;
+ gcstate = &tstate->interp->gc;
if (gcstate->callbacks == NULL) {
return;
}
/* The local variable cannot be rebound, check it for sanity */
assert(PyList_CheckExact(gcstate->callbacks));
- PyObject *info = NULL;
if (PyList_GET_SIZE(gcstate->callbacks) != 0) {
info = Py_BuildValue("{sisnsn}",
"generation", generation,
@@ -1372,8 +1390,8 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
return;
}
}
- for (Py_ssize_t i=0; i<PyList_GET_SIZE(gcstate->callbacks); i++) {
- PyObject *r, *cb = PyList_GET_ITEM(gcstate->callbacks, i);
+ for (i=0; i<PyList_GET_SIZE(gcstate->callbacks); i++) {
+ cb = PyList_GET_ITEM(gcstate->callbacks, i);
Py_INCREF(cb); /* make sure cb doesn't go away */
r = PyObject_CallFunction(cb, "sO", phase, info);
if (r == NULL) {
@@ -1394,8 +1412,8 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
static Py_ssize_t
gc_collect_with_callback(PyThreadState *tstate, int generation)
{
- assert(!_PyErr_Occurred(tstate));
Py_ssize_t result, collected, uncollectable;
+ assert(!_PyErr_Occurred(tstate));
invoke_gc_callback(tstate, "start", generation, 0, 0);
result = gc_collect_main(tstate, generation, &collected, &uncollectable, 0);
invoke_gc_callback(tstate, "stop", generation, collected, uncollectable);
@@ -1406,12 +1424,13 @@ gc_collect_with_callback(PyThreadState *tstate, int generation)
static Py_ssize_t
gc_collect_generations(PyThreadState *tstate)
{
+ int i;
GCState *gcstate = &tstate->interp->gc;
/* Find the oldest generation (highest numbered) where the count
* exceeds the threshold. Objects in the that generation and
* generations younger than it will be collected. */
Py_ssize_t n = 0;
- for (int i = NUM_GENERATIONS-1; i >= 0; i--) {
+ for (i = NUM_GENERATIONS-1; i >= 0; i--) {
if (gcstate->generations[i].count > gcstate->generations[i].threshold) {
/* Avoid quadratic performance degradation in number
of tracked objects (see also issue #4074):
@@ -1520,15 +1539,18 @@ static Py_ssize_t
gc_collect_impl(PyObject *module, int generation)
/*[clinic end generated code: output=b697e633043233c7 input=40720128b682d879]*/
{
- PyThreadState *tstate = _PyThreadState_GET();
+ PyThreadState *tstate;
+ GCState *gcstate;
+ Py_ssize_t n;
+
+ tstate = _PyThreadState_GET();
if (generation < 0 || generation >= NUM_GENERATIONS) {
_PyErr_SetString(tstate, PyExc_ValueError, "invalid generation");
return -1;
}
- GCState *gcstate = &tstate->interp->gc;
- Py_ssize_t n;
+ gcstate = &tstate->interp->gc;
if (gcstate->collecting) {
/* already collecting, don't do anything */
n = 0;
@@ -1591,13 +1613,14 @@ PyDoc_STRVAR(gc_set_thresh__doc__,
static PyObject *
gc_set_threshold(PyObject *self, PyObject *args)
{
+ int i;
GCState *gcstate = get_gc_state();
if (!PyArg_ParseTuple(args, "i|ii:set_threshold",
&gcstate->generations[0].threshold,
&gcstate->generations[1].threshold,
&gcstate->generations[2].threshold))
return NULL;
- for (int i = 3; i < NUM_GENERATIONS; i++) {
+ for (i = 3; i < NUM_GENERATIONS; i++) {
/* generations higher than 2 get the same threshold */
gcstate->generations[i].threshold = gcstate->generations[2].threshold;
}
@@ -1674,17 +1697,20 @@ Return the list of objects that directly refer to any of objs.");
static PyObject *
gc_get_referrers(PyObject *self, PyObject *args)
{
+ PyObject *result;
+ GCState *gcstate;
+ int i;
if (PySys_Audit("gc.get_referrers", "(O)", args) < 0) {
return NULL;
}
- PyObject *result = PyList_New(0);
+ result = PyList_New(0);
if (!result) {
return NULL;
}
- GCState *gcstate = get_gc_state();
- for (int i = 0; i < NUM_GENERATIONS; i++) {
+ gcstate = get_gc_state();
+ for (i = 0; i < NUM_GENERATIONS; i++) {
if (!(gc_referrers_for(args, GEN_HEAD(gcstate, i), result))) {
Py_DECREF(result);
return NULL;
@@ -1708,17 +1734,19 @@ static PyObject *
gc_get_referents(PyObject *self, PyObject *args)
{
Py_ssize_t i;
+ PyObject *result;
+ traverseproc traverse;
+ PyObject *obj;
if (PySys_Audit("gc.get_referents", "(O)", args) < 0) {
return NULL;
}
- PyObject *result = PyList_New(0);
+ result = PyList_New(0);
if (result == NULL)
return NULL;
for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
- traverseproc traverse;
- PyObject *obj = PyTuple_GET_ITEM(args, i);
+ obj = PyTuple_GET_ITEM(args, i);
if (!_PyObject_IS_GC(obj))
continue;
@@ -1810,6 +1838,7 @@ gc_get_stats_impl(PyObject *module)
{
int i;
struct gc_generation_stats stats[NUM_GENERATIONS], *st;
+ PyObject *result;
/* To get consistent values despite allocations while constructing
the result list, we use a snapshot of the running stats. */
@@ -1818,7 +1847,7 @@ gc_get_stats_impl(PyObject *module)
stats[i] = gcstate->generation_stats[i];
}
- PyObject *result = PyList_New(0);
+ result = PyList_New(0);
if (result == NULL)
return NULL;
@@ -1905,7 +1934,8 @@ gc_freeze_impl(PyObject *module)
/*[clinic end generated code: output=502159d9cdc4c139 input=b602b16ac5febbe5]*/
{
GCState *gcstate = get_gc_state();
- for (int i = 0; i < NUM_GENERATIONS; ++i) {
+ int i;
+ for (i = 0; i < NUM_GENERATIONS; ++i) {
gc_list_merge(GEN_HEAD(gcstate, i), &gcstate->permanent_generation.head);
gcstate->generations[i].count = 0;
}
@@ -2024,11 +2054,11 @@ static PyModuleDef_Slot gcmodule_slots[] = {
static struct PyModuleDef gcmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "gc",
- .m_doc = gc__doc__,
- .m_size = 0, // per interpreter state, see: get_gc_state()
- .m_methods = GcMethods,
- .m_slots = gcmodule_slots
+ "gc",
+ gc__doc__,
+ 0,
+ GcMethods,
+ gcmodule_slots
};
PyMODINIT_FUNC
@@ -2069,18 +2099,20 @@ PyGC_Collect(void)
{
PyThreadState *tstate = _PyThreadState_GET();
GCState *gcstate = &tstate->interp->gc;
+ Py_ssize_t n;
+ PyObject *exc;
+ PyObject *value;
+ PyObject *tb;
if (!gcstate->enabled) {
return 0;
}
- Py_ssize_t n;
if (gcstate->collecting) {
/* already collecting, don't do anything */
n = 0;
}
else {
- PyObject *exc, *value, *tb;
gcstate->collecting = 1;
_PyErr_Fetch(tstate, &exc, &value, &tb);
n = gc_collect_with_callback(tstate, NUM_GENERATIONS - 1);
@@ -2094,6 +2126,7 @@ PyGC_Collect(void)
Py_ssize_t
_PyGC_CollectNoFail(PyThreadState *tstate)
{
+ Py_ssize_t n;
/* Ideally, this function is only called on interpreter shutdown,
and therefore not recursively. Unfortunately, when there are daemon
threads, a daemon thread can start a cyclic garbage collection
@@ -2104,8 +2137,6 @@ _PyGC_CollectNoFail(PyThreadState *tstate)
if (gcstate->collecting) {
return 0;
}
-
- Py_ssize_t n;
gcstate->collecting = 1;
n = gc_collect_main(tstate, NUM_GENERATIONS - 1, NULL, NULL, 1);
gcstate->collecting = 0;
@@ -2170,6 +2201,8 @@ gc_fini_untrack(PyGC_Head *list)
void
_PyGC_Fini(PyInterpreterState *interp)
{
+ int i;
+ PyGC_Head *gen;
GCState *gcstate = &interp->gc;
Py_CLEAR(gcstate->garbage);
Py_CLEAR(gcstate->callbacks);
@@ -2180,8 +2213,8 @@ _PyGC_Fini(PyInterpreterState *interp)
// calling PyObject_GC_UnTrack() on the object crashs if the previous
// or the next object of the PyGC_Head structure became a dangling
// pointer.
- for (int i = 0; i < NUM_GENERATIONS; i++) {
- PyGC_Head *gen = GEN_HEAD(gcstate, i);
+ for (i = 0; i < NUM_GENERATIONS; i++) {
+ gen = GEN_HEAD(gcstate, i);
gc_fini_untrack(gen);
}
}
@@ -2252,11 +2285,15 @@ PyObject_IS_GC(PyObject *obj)
void
_PyObject_GC_Link(PyObject *op)
{
- PyGC_Head *g = AS_GC(op);
+ PyGC_Head *g;
+ PyThreadState *tstate;
+ GCState *gcstate;
+
+ g = AS_GC(op);
assert(((uintptr_t)g & (sizeof(uintptr_t)-1)) == 0); // g must be correctly aligned
- PyThreadState *tstate = _PyThreadState_GET();
- GCState *gcstate = &tstate->interp->gc;
+ tstate = _PyThreadState_GET();
+ gcstate = &tstate->interp->gc;
g->_gc_next = 0;
g->_gc_prev = 0;
gcstate->generations[0].count++; /* number of allocated GC objects */
@@ -2275,18 +2312,23 @@ _PyObject_GC_Link(PyObject *op)
static PyObject *
gc_alloc(size_t basicsize, size_t presize)
{
- PyThreadState *tstate = _PyThreadState_GET();
+ PyThreadState *tstate;
+ size_t size;
+ char *mem;
+ PyObject *op;
+
+ tstate = _PyThreadState_GET();
if (basicsize > PY_SSIZE_T_MAX - presize) {
return _PyErr_NoMemory(tstate);
}
- size_t size = presize + basicsize;
- char *mem = PyObject_Malloc(size);
+ size = presize + basicsize;
+ mem = PyObject_Malloc(size);
if (mem == NULL) {
return _PyErr_NoMemory(tstate);
}
((PyObject **)mem)[0] = NULL;
((PyObject **)mem)[1] = NULL;
- PyObject *op = (PyObject *)(mem + presize);
+ op = (PyObject *)(mem + presize);
_PyObject_GC_Link(op);
return op;
}
@@ -2307,13 +2349,14 @@ PyVarObject *
_PyObject_GC_NewVar(PyTypeObject *tp, Py_ssize_t nitems)
{
size_t size;
+ size_t presize;
PyVarObject *op;
if (nitems < 0) {
PyErr_BadInternalCall();
return NULL;
}
- size_t presize = _PyType_PreHeaderSize(tp);
+ presize = _PyType_PreHeaderSize(tp);
size = _PyObject_VAR_SIZE(tp, nitems);
op = (PyVarObject *)gc_alloc(size, presize);
if (op == NULL) {
@@ -2327,12 +2370,13 @@ PyVarObject *
_PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
{
const size_t basicsize = _PyObject_VAR_SIZE(Py_TYPE(op), nitems);
+ PyGC_Head *g;
_PyObject_ASSERT((PyObject *)op, !_PyObject_GC_IS_TRACKED(op));
if (basicsize > PY_SSIZE_T_MAX - sizeof(PyGC_Head)) {
return (PyVarObject *)PyErr_NoMemory();
}
- PyGC_Head *g = AS_GC(op);
+ g = AS_GC(op);
g = (PyGC_Head *)PyObject_Realloc(g, sizeof(PyGC_Head) + basicsize);
if (g == NULL)
return (PyVarObject *)PyErr_NoMemory();
@@ -2344,6 +2388,7 @@ _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
void
PyObject_GC_Del(void *op)
{
+ GCState *gcstate;
size_t presize = _PyType_PreHeaderSize(((PyObject *)op)->ob_type);
PyGC_Head *g = AS_GC(op);
if (_PyObject_GC_IS_TRACKED(op)) {
@@ -2360,7 +2405,7 @@ PyObject_GC_Del(void *op)
PyErr_Restore(exc, exc_value, exc_tb);
#endif
}
- GCState *gcstate = get_gc_state();
+ gcstate = get_gc_state();
if (gcstate->generations[0].count > 0) {
gcstate->generations[0].count--;
}
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/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 7a02a0d..b65b001 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -871,6 +871,7 @@ tee_fromiterable(PyObject *iterable)
{
teeobject *to;
PyObject *it;
+ PyObject *dataobj;
it = PyObject_GetIter(iterable);
if (it == NULL)
@@ -880,7 +881,7 @@ tee_fromiterable(PyObject *iterable)
goto done;
}
- PyObject *dataobj = teedataobject_newinternal(it);
+ dataobj = teedataobject_newinternal(it);
if (!dataobj) {
to = NULL;
goto done;
@@ -4849,6 +4850,7 @@ combinations_with_replacement(p, r)\n\
static int
itertoolsmodule_exec(PyObject *m)
{
+ size_t i;
PyTypeObject *typelist[] = {
&accumulate_type,
&combinations_type,
@@ -4875,7 +4877,7 @@ itertoolsmodule_exec(PyObject *m)
Py_SET_TYPE(&teedataobject_type, &PyType_Type);
- for (size_t i = 0; i < Py_ARRAY_LENGTH(typelist); i++) {
+ for (i = 0; i < Py_ARRAY_LENGTH(typelist); i++) {
if (PyModule_AddType(m, typelist[i]) < 0) {
return -1;
}
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/Modules/mathmodule.c b/Modules/mathmodule.c
index 5f5b71c..999fa85 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -70,6 +70,100 @@ raised for division by zero and mod by zero.
#include "clinic/mathmodule.c.h"
+#if defined(_MSC_VER) && _MSC_VER < 1300
+# define PY_MATH_ULONG_LONG unsigned __int64
+# define PY_MATH_LONG_LONG __int64
+# define PY_MATH_ULLONG_MAX ((unsigned __int64)0xffffffffffffffffI64)
+# define PY_MATH_LLONG_MAX ((__int64)0x7fffffffffffffffI64)
+
+static double
+m_asinh(double x)
+{
+ if (x < 0.0)
+ return -m_asinh(-x);
+ if (x > 1.3407807929942596e154)
+ return log(x) + log(2.0);
+ return log(x + sqrt(x * x + 1.0));
+}
+
+static double
+m_acosh(double x)
+{
+ if (x < 1.0) {
+ errno = EDOM;
+ return Py_NAN;
+ }
+ if (x > 1.3407807929942596e154) {
+ return log(x) + log(2.0);
+ }
+ return log(x + sqrt((x - 1.0) * (x + 1.0)));
+}
+
+static double
+m_atanh(double x)
+{
+ double a, u, t, r;
+
+ if (Py_IS_NAN(x))
+ return x;
+
+ a = fabs(x);
+ if (a >= 1.0) {
+ errno = EDOM;
+ return Py_NAN;
+ }
+ if (a < 3.7252902984619140625e-9) /* 2**-28 */
+ return x;
+
+ u = 2.0 * a / (1.0 - a);
+ t = 1.0 + u;
+ r = 0.5 * log(t) * (u / (t - 1.0));
+ return x < 0.0 ? -r : r;
+}
+
+static double
+m_cbrt(double x)
+{
+ double ax;
+
+ if (Py_IS_NAN(x))
+ return x;
+ if (x == 0.0)
+ return x;
+ if (Py_IS_INFINITY(x))
+ return x;
+ ax = fabs(x);
+ ax = exp(log(ax) / 3.0);
+ return x < 0.0 ? -ax : ax;
+}
+
+static double
+m_expm1(double x)
+{
+ if (fabs(x) < 1e-5)
+ return x + 0.5 * x * x;
+ return exp(x) - 1.0;
+}
+
+static double
+m_exp2(double x)
+{
+ if (Py_IS_NAN(x))
+ return x;
+ return exp(x * log(2.0));
+}
+
+#else
+# define PY_MATH_ULONG_LONG unsigned long long
+# define PY_MATH_LONG_LONG long long
+# define PY_MATH_ULLONG_MAX ULLONG_MAX
+# define PY_MATH_LLONG_MAX LLONG_MAX
+# define m_atanh atanh
+# define m_cbrt cbrt
+# define m_expm1 expm1
+# define m_exp2 exp2
+#endif
+
/*[clinic input]
module math
[clinic start generated code]*/
@@ -841,7 +935,7 @@ m_log10(double x)
static PyObject *
math_gcd(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
{
- PyObject *res, *x;
+ PyObject *res, *x, *one;
Py_ssize_t i;
if (nargs == 0) {
@@ -856,7 +950,7 @@ math_gcd(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
return res;
}
- PyObject *one = _PyLong_GetOne(); // borrowed ref
+ one = _PyLong_GetOne(); // borrowed ref
for (i = 1; i < nargs; i++) {
x = _PyNumber_Index(args[i]);
if (x == NULL) {
@@ -916,7 +1010,7 @@ long_lcm(PyObject *a, PyObject *b)
static PyObject *
math_lcm(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
{
- PyObject *res, *x;
+ PyObject *res, *x, *zero;
Py_ssize_t i;
if (nargs == 0) {
@@ -931,7 +1025,7 @@ math_lcm(PyObject *module, PyObject * const *args, Py_ssize_t nargs)
return res;
}
- PyObject *zero = _PyLong_GetZero(); // borrowed ref
+ zero = _PyLong_GetZero(); // borrowed ref
for (i = 1; i < nargs; i++) {
x = PyNumber_Index(args[i]);
if (x == NULL) {
@@ -1175,14 +1269,14 @@ FUNC1(acos, acos, 0,
"acos($module, x, /)\n--\n\n"
"Return the arc cosine (measured in radians) of x.\n\n"
"The result is between 0 and pi.")
-FUNC1(acosh, acosh, 0,
+FUNC1(acosh, m_acosh, 0,
"acosh($module, x, /)\n--\n\n"
"Return the inverse hyperbolic cosine of x.")
FUNC1(asin, asin, 0,
"asin($module, x, /)\n--\n\n"
"Return the arc sine (measured in radians) of x.\n\n"
"The result is between -pi/2 and pi/2.")
-FUNC1(asinh, asinh, 0,
+FUNC1(asinh, m_asinh, 0,
"asinh($module, x, /)\n--\n\n"
"Return the inverse hyperbolic sine of x.")
FUNC1(atan, atan, 0,
@@ -1193,10 +1287,10 @@ FUNC2(atan2, m_atan2,
"atan2($module, y, x, /)\n--\n\n"
"Return the arc tangent (measured in radians) of y/x.\n\n"
"Unlike atan(y/x), the signs of both x and y are considered.")
-FUNC1(atanh, atanh, 0,
+FUNC1(atanh, m_atanh, 0,
"atanh($module, x, /)\n--\n\n"
"Return the inverse hyperbolic tangent of x.")
-FUNC1(cbrt, cbrt, 0,
+FUNC1(cbrt, m_cbrt, 0,
"cbrt($module, x, /)\n--\n\n"
"Return the cube root of x.")
@@ -1216,6 +1310,7 @@ math_ceil(PyObject *module, PyObject *number)
/*[clinic end generated code: output=6c3b8a78bc201c67 input=2725352806399cab]*/
{
_Py_IDENTIFIER(__ceil__);
+ double x;
if (!PyFloat_CheckExact(number)) {
PyObject *method = _PyObject_LookupSpecialId(number, &PyId___ceil__);
@@ -1227,7 +1322,7 @@ math_ceil(PyObject *module, PyObject *number)
if (PyErr_Occurred())
return NULL;
}
- double x = PyFloat_AsDouble(number);
+ x = PyFloat_AsDouble(number);
if (x == -1.0 && PyErr_Occurred())
return NULL;
@@ -1254,10 +1349,10 @@ FUNC1A(erfc, m_erfc,
FUNC1(exp, exp, 1,
"exp($module, x, /)\n--\n\n"
"Return e raised to the power of x.")
-FUNC1(exp2, exp2, 1,
+FUNC1(exp2, m_exp2, 1,
"exp2($module, x, /)\n--\n\n"
"Return 2 raised to the power of x.")
-FUNC1(expm1, expm1, 1,
+FUNC1(expm1, m_expm1, 1,
"expm1($module, x, /)\n--\n\n"
"Return exp(x)-1.\n\n"
"This function avoids the loss of precision involved in the direct "
@@ -1779,6 +1874,7 @@ math_isqrt(PyObject *module, PyObject *n)
/*[clinic end generated code: output=35a6f7f980beab26 input=5b6e7ae4fa6c43d6]*/
{
int a_too_large, c_bit_length;
+ int s;
size_t c, d;
uint64_t m;
uint32_t u;
@@ -1847,7 +1943,7 @@ math_isqrt(PyObject *module, PyObject *n)
goto error;
}
- for (int s = c_bit_length - 6; s >= 0; --s) {
+ for (s = c_bit_length - 6; s >= 0; --s) {
PyObject *q;
size_t e = d;
@@ -3082,14 +3178,17 @@ _check_long_mult_overflow(long a, long b) {
long longprod = (long)((unsigned long)a * b);
double doubleprod = (double)a * (double)b;
double doubled_longprod = (double)longprod;
+ double diff;
+ double absdiff;
+ double absprod;
if (doubled_longprod == doubleprod) {
return 0;
}
- const double diff = doubled_longprod - doubleprod;
- const double absdiff = diff >= 0.0 ? diff : -diff;
- const double absprod = doubleprod >= 0.0 ? doubleprod : -doubleprod;
+ diff = doubled_longprod - doubleprod;
+ absdiff = diff >= 0.0 ? diff : -diff;
+ absprod = doubleprod >= 0.0 ? doubleprod : -doubleprod;
if (32.0 * absdiff <= absprod) {
return 0;
@@ -3380,8 +3479,16 @@ static const uint8_t factorial_trailing_zeros[] = {
/* Calculate C(n, k) for n in the 63-bit range. */
static PyObject *
-perm_comb_small(unsigned long long n, unsigned long long k, int iscomb)
+perm_comb_small(PY_MATH_ULONG_LONG n, PY_MATH_ULONG_LONG k, int iscomb)
{
+ PY_MATH_ULONG_LONG result, i, j;
+ uint64_t comb_odd_part, perm_odd_part;
+ int shift;
+ PyObject *a, *b;
+ static const PY_MATH_ULONG_LONG fast_comb_limits2[] = {
+ 0, PY_MATH_ULLONG_MAX, (PY_MATH_ULONG_LONG)4294967296I64, 3329022, 102570, 13467, 3612, 1449, // 0-7
+ 746, 453, 308, 227, 178, 147, // 8-13
+ };
if (k == 0) {
return PyLong_FromLong(1);
}
@@ -3410,26 +3517,22 @@ perm_comb_small(unsigned long long n, unsigned long long k, int iscomb)
calculated efficiently via arithmetic modulo 2**64, using three
lookups and two uint64_t multiplications.
*/
- uint64_t comb_odd_part = reduced_factorial_odd_part[n]
- * inverted_factorial_odd_part[k]
- * inverted_factorial_odd_part[n - k];
- int shift = factorial_trailing_zeros[n]
- - factorial_trailing_zeros[k]
- - factorial_trailing_zeros[n - k];
+ comb_odd_part = reduced_factorial_odd_part[n]
+ * inverted_factorial_odd_part[k]
+ * inverted_factorial_odd_part[n - k];
+ shift = factorial_trailing_zeros[n]
+ - factorial_trailing_zeros[k]
+ - factorial_trailing_zeros[n - k];
return PyLong_FromUnsignedLongLong(comb_odd_part << shift);
}
/* Maps k to the maximal n so that 2*k-1 <= n <= 127 and C(n, k)*k
* fits into a long long (which is at least 64 bit). Only contains
* items larger than in fast_comb_limits1. */
- static const unsigned long long fast_comb_limits2[] = {
- 0, ULLONG_MAX, 4294967296ULL, 3329022, 102570, 13467, 3612, 1449, // 0-7
- 746, 453, 308, 227, 178, 147, // 8-13
- };
if (k < Py_ARRAY_LENGTH(fast_comb_limits2) && n <= fast_comb_limits2[k]) {
/* C(n, k) = C(n, k-1) * (n-k+1) / k */
- unsigned long long result = n;
- for (unsigned long long i = 1; i < k;) {
+ result = n;
+ for (i = 1; i < k;) {
result *= --n;
result /= ++i;
}
@@ -3439,8 +3542,8 @@ perm_comb_small(unsigned long long n, unsigned long long k, int iscomb)
else {
/* Maps k to the maximal n so that k <= n and P(n, k)
* fits into a long long (which is at least 64 bit). */
- static const unsigned long long fast_perm_limits[] = {
- 0, ULLONG_MAX, 4294967296ULL, 2642246, 65537, 7133, 1627, 568, // 0-7
+ static const PY_MATH_ULONG_LONG fast_perm_limits[] = {
+ 0, PY_MATH_ULLONG_MAX, (PY_MATH_ULONG_LONG)4294967296I64, 2642246, 65537, 7133, 1627, 568, // 0-7
259, 142, 88, 61, 45, 36, 30, 26, // 8-15
24, 22, 21, 20, 20, // 16-20
};
@@ -3455,8 +3558,8 @@ perm_comb_small(unsigned long long n, unsigned long long k, int iscomb)
}
/* P(n, k) = P(n, k-1) * (n-k+1) */
- unsigned long long result = n;
- for (unsigned long long i = 1; i < k;) {
+ result = n;
+ for (i = 1; i < k;) {
result *= --n;
++i;
}
@@ -3469,8 +3572,7 @@ perm_comb_small(unsigned long long n, unsigned long long k, int iscomb)
* P(n, k) = P(n, j) * P(n-j, k-j)
* C(n, k) = C(n, j) * C(n-j, k-j) // C(k, j)
*/
- unsigned long long j = k / 2;
- PyObject *a, *b;
+ j = k / 2;
a = perm_comb_small(n, j, iscomb);
if (a == NULL) {
return NULL;
@@ -3501,8 +3603,10 @@ perm_comb_small(unsigned long long n, unsigned long long k, int iscomb)
* Karatsuba multiplication.
*/
static PyObject *
-perm_comb(PyObject *n, unsigned long long k, int iscomb)
+perm_comb(PyObject *n, PY_MATH_ULONG_LONG k, int iscomb)
{
+ PY_MATH_ULONG_LONG j;
+ PyObject *a, *b, *t;
if (k == 0) {
return PyLong_FromLong(1);
}
@@ -3513,13 +3617,12 @@ perm_comb(PyObject *n, unsigned long long k, int iscomb)
/* P(n, k) = P(n, j) * P(n-j, k-j) */
/* C(n, k) = C(n, j) * C(n-j, k-j) // C(k, j) */
- unsigned long long j = k / 2;
- PyObject *a, *b;
+ j = k / 2;
a = perm_comb(n, j, iscomb);
if (a == NULL) {
return NULL;
}
- PyObject *t = PyLong_FromUnsignedLongLong(j);
+ t = PyLong_FromUnsignedLongLong(j);
if (t == NULL) {
goto error;
}
@@ -3575,7 +3678,7 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
{
PyObject *result = NULL;
int overflow, cmp;
- long long ki, ni;
+ PY_MATH_LONG_LONG ki, ni;
if (k == Py_None) {
return math_factorial(module, n);
@@ -3616,7 +3719,7 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
if (overflow > 0) {
PyErr_Format(PyExc_OverflowError,
"k must not exceed %lld",
- LLONG_MAX);
+ PY_MATH_LLONG_MAX);
goto error;
}
assert(ki >= 0);
@@ -3625,11 +3728,11 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
assert(overflow >= 0 && !PyErr_Occurred());
if (!overflow && ki > 1) {
assert(ni >= 0);
- result = perm_comb_small((unsigned long long)ni,
- (unsigned long long)ki, 0);
+ result = perm_comb_small((PY_MATH_ULONG_LONG)ni,
+ (PY_MATH_ULONG_LONG)ki, 0);
}
else {
- result = perm_comb(n, (unsigned long long)ki, 0);
+ result = perm_comb(n, (PY_MATH_ULONG_LONG)ki, 0);
}
done:
@@ -3670,7 +3773,7 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
{
PyObject *result = NULL, *temp;
int overflow, cmp;
- long long ki, ni;
+ PY_MATH_LONG_LONG ki, ni;
n = PyNumber_Index(n);
if (n == NULL) {
@@ -3708,8 +3811,8 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
ki = Py_MIN(ki, ni - ki);
if (ki > 1) {
- result = perm_comb_small((unsigned long long)ni,
- (unsigned long long)ki, 1);
+ result = perm_comb_small((PY_MATH_ULONG_LONG)ni,
+ (PY_MATH_ULONG_LONG)ki, 1);
goto done;
}
/* For k == 1 just return the original n in perm_comb(). */
@@ -3741,13 +3844,13 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
if (overflow) {
PyErr_Format(PyExc_OverflowError,
"min(n - k, k) must not exceed %lld",
- LLONG_MAX);
+ PY_MATH_LLONG_MAX);
goto error;
}
assert(ki >= 0);
}
- result = perm_comb(n, (unsigned long long)ki, 1);
+ result = perm_comb(n, (PY_MATH_ULONG_LONG)ki, 1);
done:
Py_DECREF(n);
@@ -3805,6 +3908,8 @@ static double
math_ulp_impl(PyObject *module, double x)
/*[clinic end generated code: output=f5207867a9384dd4 input=31f9bfbbe373fcaa]*/
{
+ double inf;
+ double x2;
if (Py_IS_NAN(x)) {
return x;
}
@@ -3812,8 +3917,8 @@ math_ulp_impl(PyObject *module, double x)
if (Py_IS_INFINITY(x)) {
return x;
}
- double inf = m_inf();
- double x2 = nextafter(x, inf);
+ inf = m_inf();
+ x2 = nextafter(x, inf);
if (Py_IS_INFINITY(x2)) {
/* special case: x is the largest positive representable float */
x2 = nextafter(x, -inf);
@@ -3916,11 +4021,11 @@ PyDoc_STRVAR(module_doc,
static struct PyModuleDef mathmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "math",
- .m_doc = module_doc,
- .m_size = 0,
- .m_methods = math_methods,
- .m_slots = math_slots,
+ "math",
+ module_doc,
+ 0,
+ math_methods,
+ math_slots
};
PyMODINIT_FUNC
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 48b11e0..eaae0de 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -33,7 +33,7 @@ class MD5Type "MD5object *" "&PyType_Type"
#if SIZEOF_INT == 4
typedef unsigned int MD5_INT32; /* 32-bit integer */
-typedef long long MD5_INT64; /* 64-bit integer */
+typedef PY_LONG_LONG MD5_INT64; /* 64-bit integer */
#else
/* not defined. compilation will die. */
#endif
@@ -495,11 +495,12 @@ static PyType_Slot md5_type_slots[] = {
};
static PyType_Spec md5_type_spec = {
- .name = "_md5.md5",
- .basicsize = sizeof(MD5object),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
- .slots = md5_type_slots
+ "_md5.md5",
+ sizeof(MD5object),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
+ md5_type_slots
};
/* The single module-level function: new() */
@@ -520,11 +521,12 @@ _md5_md5_impl(PyObject *module, PyObject *string, int usedforsecurity)
{
MD5object *new;
Py_buffer buf;
+ MD5State *st;
if (string)
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
- MD5State *st = md5_get_state(module);
+ st = md5_get_state(module);
if ((new = newMD5object(st)) == NULL) {
if (string)
PyBuffer_Release(&buf);
@@ -607,13 +609,14 @@ static PyModuleDef_Slot _md5_slots[] = {
static struct PyModuleDef _md5module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_md5",
- .m_size = sizeof(MD5State),
- .m_methods = MD5_functions,
- .m_slots = _md5_slots,
- .m_traverse = _md5_traverse,
- .m_clear = _md5_clear,
- .m_free = _md5_free,
+ "_md5",
+ NULL,
+ sizeof(MD5State),
+ MD5_functions,
+ _md5_slots,
+ _md5_traverse,
+ _md5_clear,
+ _md5_free,
};
PyMODINIT_FUNC
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index b315bec..32d001b 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -100,7 +100,7 @@ typedef struct {
Py_ssize_t size;
Py_ssize_t pos; /* relative to offset */
#ifdef MS_WINDOWS
- long long offset;
+ PY_LONG_LONG offset;
#else
off_t offset;
#endif
@@ -178,6 +178,11 @@ mmap_object_dealloc(mmap_object *m_obj)
static PyObject *
mmap_close_method(mmap_object *self, PyObject *unused)
{
+#ifdef MS_WINDOWS
+ HANDLE map_handle;
+ HANDLE file_handle;
+ char *data;
+#endif
if (self->exports > 0) {
PyErr_SetString(PyExc_BufferError, "cannot close "\
"exported pointers exist");
@@ -191,9 +196,9 @@ mmap_close_method(mmap_object *self, PyObject *unused)
again.
TODO - should we check for errors in the close operations???
*/
- HANDLE map_handle = self->map_handle;
- HANDLE file_handle = self->file_handle;
- char *data = self->data;
+ map_handle = self->map_handle;
+ file_handle = self->file_handle;
+ data = self->data;
self->map_handle = NULL;
self->file_handle = INVALID_HANDLE_VALUE;
self->data = NULL;
@@ -327,6 +332,7 @@ mmap_gfind(mmap_object *self,
{
Py_ssize_t start = self->pos;
Py_ssize_t end = self->size;
+ Py_ssize_t res;
Py_buffer view;
CHECK_VALID(NULL);
@@ -349,7 +355,6 @@ mmap_gfind(mmap_object *self,
else if (end > self->size)
end = self->size;
- Py_ssize_t res;
CHECK_VALID_OR_RELEASE(NULL, view);
if (end < start) {
res = -1;
@@ -472,7 +477,7 @@ mmap_size_method(mmap_object *self,
#ifdef MS_WINDOWS
if (self->file_handle != INVALID_HANDLE_VALUE) {
DWORD low,high;
- long long size;
+ PY_LONG_LONG size;
low = GetFileSize(self->file_handle, &high);
if (low == INVALID_FILE_SIZE) {
/* It might be that the function appears to have failed,
@@ -483,7 +488,7 @@ mmap_size_method(mmap_object *self,
}
if (!high && low < LONG_MAX)
return PyLong_FromLong((long)low);
- size = (((long long)high)<<32) + low;
+ size = (((PY_LONG_LONG)high)<<32) + low;
return PyLong_FromLongLong(size);
} else {
return PyLong_FromSsize_t(self->size);
@@ -1199,11 +1204,12 @@ static PyType_Slot mmap_object_slots[] = {
};
static PyType_Spec mmap_object_spec = {
- .name = "mmap.mmap",
- .basicsize = sizeof(mmap_object),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
- Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
- .slots = mmap_object_slots,
+ "mmap.mmap",
+ sizeof(mmap_object),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
+ mmap_object_slots,
};
@@ -1394,7 +1400,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
{
mmap_object *m_obj;
Py_ssize_t map_size;
- long long offset = 0, size;
+ PY_LONG_LONG offset = 0, size;
DWORD off_hi; /* upper 32 bits of offset */
DWORD off_lo; /* lower 32 bits of offset */
DWORD size_hi; /* upper 32 bits of size */
@@ -1506,7 +1512,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
return PyErr_SetFromWindowsErr(dwErr);
}
- size = (((long long) high) << 32) + low;
+ size = (((PY_LONG_LONG) high) << 32) + low;
if (size == 0) {
PyErr_SetString(PyExc_ValueError,
"cannot mmap an empty file");
@@ -1780,12 +1786,14 @@ static PyModuleDef_Slot mmap_slots[] = {
static struct PyModuleDef mmapmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "mmap",
- .m_size = sizeof(mmap_state),
- .m_slots = mmap_slots,
- .m_traverse = mmap_traverse,
- .m_clear = mmap_clear,
- .m_free = mmap_free,
+ "mmap",
+ NULL,
+ sizeof(mmap_state),
+ NULL,
+ mmap_slots,
+ mmap_traverse,
+ mmap_clear,
+ mmap_free,
};
PyMODINIT_FUNC
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 6fb2fc8..3f9778c 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -15,6 +15,7 @@
// whereas pycore_condvar.h defines the WIN32_LEAN_AND_MEAN macro.
#ifdef MS_WINDOWS
# include <windows.h>
+# include "pycore_win9x_loadlibrary.h" // SDK fallbacks for VC6
# include <pathcch.h>
# include <lmcons.h> // UNLEN
# include "osdefs.h" // SEP
@@ -36,7 +37,37 @@
#ifdef MS_WINDOWS
# include <aclapi.h> // SetEntriesInAcl
-# include <sddl.h> // SDDL_REVISION_1
+# if defined(_MSC_VER) && _MSC_VER < 1300
+# ifndef SYMBOLIC_LINK_FLAG_DIRECTORY
+# define SYMBOLIC_LINK_FLAG_DIRECTORY 0x1
+# endif
+# endif
+# if defined(_MSC_VER) && _MSC_VER < 1300
+# ifndef INVALID_FILE_ATTRIBUTES
+# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+# endif
+# endif
+# if defined(_MSC_VER) && _MSC_VER < 1300
+# ifndef VOLUME_NAME_DOS
+# define VOLUME_NAME_DOS 0x0
+# endif
+# endif
+# if defined(_MSC_VER) && _MSC_VER < 1300
+# ifndef _MAX_ENV
+# define _MAX_ENV 32767
+# endif
+# endif
+# if defined(_MSC_VER) && _MSC_VER < 1300
+# ifndef IO_REPARSE_TAG_SYMLINK
+# define IO_REPARSE_TAG_SYMLINK 0xA000000C
+# endif
+# ifndef IO_REPARSE_TAG_MOUNT_POINT
+# define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
+# endif
+# endif
+# if !defined(_MSC_VER) || _MSC_VER >= 1300
+# include <sddl.h> // SDDL_REVISION_1
+# endif
#endif
#include "structmember.h" // PyMemberDef
@@ -1477,7 +1508,7 @@ dir_fd_and_follow_symlinks_invalid(const char *function_name, int dir_fd,
}
#ifdef MS_WINDOWS
- typedef long long Py_off_t;
+ typedef PY_LONG_LONG Py_off_t;
#else
typedef off_t Py_off_t;
#endif
@@ -1571,6 +1602,10 @@ _Py_Sigset_Converter(PyObject *obj, void *addr)
static int
win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
{
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ /* Win9x has no reparse points; the VC98 SDK lacks the query operation. */
+ return FALSE;
+#else
char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
_Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
DWORD n_bytes_returned;
@@ -1588,6 +1623,7 @@ win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
*reparse_tag = rdb->ReparseTag;
return TRUE;
+#endif
}
#endif /* MS_WINDOWS */
@@ -1798,6 +1834,7 @@ win32_wchdir(LPCWSTR path)
wchar_t path_buf[MAX_PATH], *new_path = path_buf;
int result;
wchar_t env[4] = L"=x:";
+ int is_unc_like_path;
if(!SetCurrentDirectoryW(path))
return FALSE;
@@ -1816,7 +1853,7 @@ win32_wchdir(LPCWSTR path)
return FALSE;
}
}
- int is_unc_like_path = (wcsncmp(new_path, L"\\\\", 2) == 0 ||
+ is_unc_like_path = (wcsncmp(new_path, L"\\\\", 2) == 0 ||
wcsncmp(new_path, L"//", 2) == 0);
if (!is_unc_like_path) {
env[1] = new_path[0];
@@ -1896,7 +1933,14 @@ win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
{
HANDLE hFile;
BY_HANDLE_FILE_INFORMATION fileInfo;
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ struct {
+ DWORD FileAttributes;
+ DWORD ReparseTag;
+ } tagInfo = { 0 };
+#else
FILE_ATTRIBUTE_TAG_INFO tagInfo = { 0 };
+#endif
DWORD fileType, error;
BOOL isUnhandledTag = FALSE;
int retval = 0;
@@ -1974,11 +2018,12 @@ win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
/* Handle types other than files on disk. */
fileType = GetFileType(hFile);
if (fileType != FILE_TYPE_DISK) {
+ DWORD fileAttributes;
if (fileType == FILE_TYPE_UNKNOWN && GetLastError() != 0) {
retval = -1;
goto cleanup;
}
- DWORD fileAttributes = GetFileAttributesW(path);
+ fileAttributes = GetFileAttributesW(path);
memset(result, 0, sizeof(*result));
if (fileAttributes != INVALID_FILE_ATTRIBUTES &&
fileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
@@ -1995,6 +2040,7 @@ win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
goto cleanup;
}
+#if !defined(_MSC_VER) || _MSC_VER >= 1300
/* Query the reparse tag, and traverse a non-link. */
if (!traverse) {
if (!GetFileInformationByHandleEx(hFile, FileAttributeTagInfo,
@@ -2030,6 +2076,7 @@ win32_xstat_impl(const wchar_t *path, struct _Py_stat_struct *result,
}
}
+#endif
if (!GetFileInformationByHandle(hFile, &fileInfo)) {
switch (GetLastError()) {
case ERROR_INVALID_PARAMETER:
@@ -2372,15 +2419,17 @@ _posix_free(void *module)
static int
fill_time(PyObject *module, PyObject *v, int index, time_t sec, unsigned long nsec)
{
- assert(!PyErr_Occurred());
-
int res = -1;
PyObject *s_in_ns = NULL;
PyObject *ns_total = NULL;
PyObject *float_s = NULL;
+ PyObject *s;
+ PyObject *ns_fractional;
+
+ assert(!PyErr_Occurred());
- PyObject *s = _PyLong_FromTime_t(sec);
- PyObject *ns_fractional = PyLong_FromUnsignedLong(nsec);
+ s = _PyLong_FromTime_t(sec);
+ ns_fractional = PyLong_FromUnsignedLong(nsec);
if (!(s && ns_fractional)) {
goto exit;
}
@@ -2423,10 +2472,14 @@ fill_time(PyObject *module, PyObject *v, int index, time_t sec, unsigned long ns
static PyObject*
_pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
{
+ PyObject *StatResultType;
+ PyObject *v;
+ unsigned long ansec, mnsec, cnsec;
+
assert(!PyErr_Occurred());
- PyObject *StatResultType = get_posix_state(module)->StatResultType;
- PyObject *v = PyStructSequence_New((PyTypeObject *)StatResultType);
+ StatResultType = get_posix_state(module)->StatResultType;
+ v = PyStructSequence_New((PyTypeObject *)StatResultType);
if (v == NULL) {
return NULL;
}
@@ -2441,8 +2494,8 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
} while (0)
SET_ITEM(0, PyLong_FromLong((long)st->st_mode));
- static_assert(sizeof(unsigned long long) >= sizeof(st->st_ino),
- "stat.st_ino is larger than unsigned long long");
+ static_assert(sizeof(unsigned PY_LONG_LONG) >= sizeof(st->st_ino),
+ "stat.st_ino is larger than unsigned PY_LONG_LONG");
SET_ITEM(1, PyLong_FromUnsignedLongLong(st->st_ino));
#ifdef MS_WINDOWS
SET_ITEM(2, PyLong_FromUnsignedLong(st->st_dev));
@@ -2457,12 +2510,11 @@ _pystat_fromstructstat(PyObject *module, STRUCT_STAT *st)
SET_ITEM(4, _PyLong_FromUid(st->st_uid));
SET_ITEM(5, _PyLong_FromGid(st->st_gid));
#endif
- static_assert(sizeof(long long) >= sizeof(st->st_size),
- "stat.st_size is larger than long long");
+ static_assert(sizeof(PY_LONG_LONG) >= sizeof(st->st_size),
+ "stat.st_size is larger than PY_LONG_LONG");
SET_ITEM(6, PyLong_FromLongLong(st->st_size));
// Set st_atime, st_mtime and st_ctime
- unsigned long ansec, mnsec, cnsec;
#if defined(HAVE_STAT_TV_NSEC)
ansec = st->st_atim.tv_nsec;
mnsec = st->st_mtim.tv_nsec;
@@ -3813,6 +3865,7 @@ posix_getcwd(int use_bytes)
wchar_t wbuf[MAXPATHLEN];
wchar_t *wbuf2 = wbuf;
DWORD len;
+ PyObject *resobj;
Py_BEGIN_ALLOW_THREADS
len = GetCurrentDirectoryW(Py_ARRAY_LENGTH(wbuf), wbuf);
@@ -3843,7 +3896,7 @@ posix_getcwd(int use_bytes)
return NULL;
}
- PyObject *resobj = PyUnicode_FromWideChar(wbuf2, len);
+ resobj = PyUnicode_FromWideChar(wbuf2, len);
if (wbuf2 != wbuf) {
PyMem_RawFree(wbuf2);
}
@@ -4362,6 +4415,7 @@ os__getfullpathname_impl(PyObject *module, path_t *path)
/*[clinic end generated code: output=bb8679d56845bc9b input=332ed537c29d0a3e]*/
{
wchar_t *abspath;
+ PyObject *str;
if (_PyOS_getfullpathname(path->wide, &abspath) < 0) {
return win32_error_object("GetFullPathNameW", path->object);
@@ -4370,7 +4424,7 @@ os__getfullpathname_impl(PyObject *module, path_t *path)
return PyErr_NoMemory();
}
- PyObject *str = PyUnicode_FromWideChar(abspath, wcslen(abspath));
+ str = PyUnicode_FromWideChar(abspath, wcslen(abspath));
PyMem_RawFree(abspath);
if (str == NULL) {
return NULL;
@@ -4396,6 +4450,7 @@ os__getfinalpathname_impl(PyObject *module, path_t *path)
/*[clinic end generated code: output=621a3c79bc29ebfa input=2b6b6c7cbad5fb84]*/
{
HANDLE hFile;
+ wchar_t *tmp;
wchar_t buf[MAXPATHLEN], *target_path = buf;
int buf_size = Py_ARRAY_LENGTH(buf);
int result_length;
@@ -4435,7 +4490,6 @@ os__getfinalpathname_impl(PyObject *module, path_t *path)
break;
}
- wchar_t *tmp;
tmp = PyMem_Realloc(target_path != buf ? target_path : NULL,
result_length * sizeof(*tmp));
if (!tmp) {
@@ -4523,6 +4577,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path)
{
wchar_t *buffer;
wchar_t *end;
+ wchar_t *p;
PyObject *result = NULL;
HRESULT ret;
@@ -4531,7 +4586,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path)
return NULL;
}
wcscpy(buffer, path->wide);
- for (wchar_t *p = wcschr(buffer, L'/'); p; p = wcschr(p, L'/')) {
+ for (p = wcschr(buffer, L'/'); p; p = wcschr(p, L'/')) {
*p = L'\\';
}
@@ -4570,19 +4625,23 @@ static PyObject *
os__path_normpath_impl(PyObject *module, PyObject *path)
/*[clinic end generated code: output=b94d696d828019da input=5e90c39e12549dc0]*/
{
+ Py_ssize_t len;
+ wchar_t *buffer;
+ Py_ssize_t norm_len;
+ wchar_t *norm_path;
+ PyObject *result;
+
if (!PyUnicode_Check(path)) {
PyErr_Format(PyExc_TypeError, "expected 'str', not '%.200s'",
Py_TYPE(path)->tp_name);
return NULL;
}
- Py_ssize_t len;
- wchar_t *buffer = PyUnicode_AsWideCharString(path, &len);
+ buffer = PyUnicode_AsWideCharString(path, &len);
if (!buffer) {
return NULL;
}
- Py_ssize_t norm_len;
- wchar_t *norm_path = _Py_normpath_and_size(buffer, len, &norm_len);
- PyObject *result = PyUnicode_FromWideChar(norm_path, norm_len);
+ norm_path = _Py_normpath_and_size(buffer, len, &norm_len);
+ result = PyUnicode_FromWideChar(norm_path, norm_len);
PyMem_Free(buffer);
return result;
}
@@ -4619,7 +4678,9 @@ os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd)
#ifdef MS_WINDOWS
int error = 0;
int pathError = 0;
+#if !defined(_MSC_VER) || _MSC_VER >= 1300
SECURITY_ATTRIBUTES secAttr = { sizeof(secAttr) };
+#endif
SECURITY_ATTRIBUTES *pSecAttr = NULL;
#endif
#ifdef HAVE_MKDIRAT
@@ -4633,6 +4694,7 @@ os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd)
#ifdef MS_WINDOWS
Py_BEGIN_ALLOW_THREADS
+#if !defined(_MSC_VER) || _MSC_VER >= 1300
if (mode == 0700 /* 0o700 */) {
ULONG sdSize;
pSecAttr = &secAttr;
@@ -4648,14 +4710,17 @@ os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd)
error = GetLastError();
}
}
+#endif
if (!error) {
result = CreateDirectoryW(path->wide, pSecAttr);
+#if !defined(_MSC_VER) || _MSC_VER >= 1300
if (secAttr.lpSecurityDescriptor &&
// uncommonly, LocalFree returns non-zero on error, but still uses
// GetLastError() to see what the error code is
LocalFree(secAttr.lpSecurityDescriptor)) {
error = GetLastError();
}
+#endif
}
Py_END_ALLOW_THREADS
@@ -5755,6 +5820,7 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
Py_ssize_t i, pos, envc;
PyObject *keys=NULL, *vals=NULL;
PyObject *key2, *val2, *keyval;
+ PyObject *key, *val;
EXECV_CHAR **envlist;
i = PyMapping_Size(env);
@@ -5779,11 +5845,11 @@ parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
}
for (pos = 0; pos < i; pos++) {
- PyObject *key = PyList_GetItem(keys, pos); // Borrowed ref.
+ key = PyList_GetItem(keys, pos); // Borrowed ref.
if (key == NULL) {
goto error;
}
- PyObject *val = PyList_GetItem(vals, pos); // Borrowed ref.
+ val = PyList_GetItem(vals, pos); // Borrowed ref.
if (val == NULL) {
goto error;
}
@@ -6571,6 +6637,7 @@ os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv)
int i;
Py_ssize_t argc;
intptr_t spawnval;
+ int saved_errno;
PyObject *(*getitem)(PyObject *, Py_ssize_t);
/* spawnv has three arguments: (mode, path, argv), where
@@ -6641,7 +6708,7 @@ os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv)
_Py_END_SUPPRESS_IPH
Py_END_ALLOW_THREADS
- int saved_errno = errno;
+ saved_errno = errno;
free_string_array(argvlist, argc);
if (spawnval == -1) {
@@ -8101,6 +8168,13 @@ static PyObject *
os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
/*[clinic end generated code: output=8e346a6701c88568 input=61a36b86ca275ab9]*/
{
+#ifdef MS_WINDOWS
+ PyObject *result;
+ DWORD sig;
+ DWORD err;
+ HANDLE handle;
+#endif
+
if (PySys_Audit("os.kill", "in", pid, signal) < 0) {
return NULL;
}
@@ -8118,10 +8192,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
Py_RETURN_NONE;
#else /* !MS_WINDOWS */
- PyObject *result;
- DWORD sig = (DWORD)signal;
- DWORD err;
- HANDLE handle;
+ sig = (DWORD)signal;
/* Console processes which share a common console can be sent CTRL+C or
CTRL+BREAK events, provided they handle said events. */
@@ -8667,6 +8738,7 @@ os_waitpid_impl(PyObject *module, intptr_t pid, int options)
int status;
intptr_t res;
int async_err = 0;
+ PY_LONG_LONG ustatus;
do {
Py_BEGIN_ALLOW_THREADS
@@ -8678,7 +8750,7 @@ os_waitpid_impl(PyObject *module, intptr_t pid, int options)
if (res < 0)
return (!async_err) ? posix_error() : NULL;
- unsigned long long ustatus = (unsigned int)status;
+ ustatus = (unsigned int)status;
/* shift the status left a byte so this is more like the POSIX waitpid */
return Py_BuildValue(_Py_PARSE_INTPTR "K", res, ustatus << 8);
@@ -8800,6 +8872,11 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
else
return PyBytes_FromStringAndSize(buffer, length);
#elif defined(MS_WINDOWS)
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ PyErr_SetString(PyExc_NotImplementedError,
+ "os.readlink is unavailable on this Windows build");
+ return NULL;
+#else
DWORD n_bytes_returned;
DWORD io_result = 0;
HANDLE reparse_point_handle;
@@ -8864,6 +8941,7 @@ os_readlink_impl(PyObject *module, path_t *path, int dir_fd)
}
}
return result;
+#endif /* _MSC_VER >= 1300 */
#endif
}
#endif /* defined(HAVE_READLINK) || defined(MS_WINDOWS) */
@@ -11134,6 +11212,11 @@ os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
static PyObject*
win32_putenv(PyObject *name, PyObject *value)
{
+ PyObject *unicode;
+ Py_ssize_t size;
+ wchar_t *env;
+ int err;
+
/* Search from index 1 because on Windows starting '=' is allowed for
defining hidden environment variables. */
if (PyUnicode_GET_LENGTH(name) == 0 ||
@@ -11142,7 +11225,6 @@ win32_putenv(PyObject *name, PyObject *value)
PyErr_SetString(PyExc_ValueError, "illegal environment variable name");
return NULL;
}
- PyObject *unicode;
if (value != NULL) {
unicode = PyUnicode_FromFormat("%U=%U", name, value);
}
@@ -11153,8 +11235,7 @@ win32_putenv(PyObject *name, PyObject *value)
return NULL;
}
- Py_ssize_t size;
- wchar_t *env = PyUnicode_AsWideCharString(unicode, &size);
+ env = PyUnicode_AsWideCharString(unicode, &size);
Py_DECREF(unicode);
if (env == NULL) {
@@ -11180,7 +11261,7 @@ win32_putenv(PyObject *name, PyObject *value)
Prefer _wputenv() to be compatible with C libraries using CRT
variables and CRT functions using these variables (ex: getenv()). */
- int err = _wputenv(env);
+ err = _wputenv(env);
if (err) {
posix_error();
@@ -13437,6 +13518,8 @@ os_get_terminal_size_impl(PyObject *module, int fd)
{
int columns, lines;
PyObject *termsize;
+ PyObject *TerminalSizeType;
+ int pos;
/* Under some conditions stdout may not be connected and
* fileno(stdout) may point to an invalid file descriptor. For example
@@ -13485,12 +13568,12 @@ os_get_terminal_size_impl(PyObject *module, int fd)
}
#endif /* TERMSIZE_USE_CONIO */
- PyObject *TerminalSizeType = get_posix_state(module)->TerminalSizeType;
+ TerminalSizeType = get_posix_state(module)->TerminalSizeType;
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
if (termsize == NULL)
return NULL;
- int pos = 0;
+ pos = 0;
#define SET_TERMSIZE(CALL) \
do { \
@@ -13527,7 +13610,14 @@ os_cpu_count_impl(PyObject *module)
{
int ncpu = 0;
#ifdef MS_WINDOWS
+# if defined(_MSC_VER) && _MSC_VER < 1300
+ /* Win9x has no processor groups or GetActiveProcessorCount. */
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo(&sysinfo);
+ ncpu = sysinfo.dwNumberOfProcessors;
+# else
ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
+# endif
#elif defined(__hpux)
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
@@ -13724,11 +13814,12 @@ static void
DirEntry_dealloc(DirEntry *entry)
{
PyTypeObject *tp = Py_TYPE(entry);
+ freefunc free_func;
Py_XDECREF(entry->name);
Py_XDECREF(entry->path);
Py_XDECREF(entry->stat);
Py_XDECREF(entry->lstat);
- freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
+ free_func = PyType_GetSlot(tp, Py_tp_free);
free_func(entry);
Py_DECREF(tp);
}
@@ -13768,8 +13859,18 @@ static PyObject *
DirEntry_fetch_stat(PyObject *module, DirEntry *self, int follow_symlinks)
{
int result;
+ int saved_errno;
STRUCT_STAT st;
PyObject *ub;
+#ifdef MS_WINDOWS
+#if USE_UNICODE_WCHAR_CACHE
+ const wchar_t *path;
+#else /* USE_UNICODE_WCHAR_CACHE */
+ wchar_t *path;
+#endif /* USE_UNICODE_WCHAR_CACHE */
+#else /* POSIX */
+ const char *path;
+#endif
#ifdef MS_WINDOWS
if (!PyUnicode_FSDecoder(self->path, &ub))
@@ -13777,16 +13878,16 @@ DirEntry_fetch_stat(PyObject *module, DirEntry *self, int follow_symlinks)
#if USE_UNICODE_WCHAR_CACHE
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
- const wchar_t *path = PyUnicode_AsUnicode(ub);
+ path = PyUnicode_AsUnicode(ub);
_Py_COMP_DIAG_POP
#else /* USE_UNICODE_WCHAR_CACHE */
- wchar_t *path = PyUnicode_AsWideCharString(ub, NULL);
+ path = PyUnicode_AsWideCharString(ub, NULL);
Py_DECREF(ub);
#endif /* USE_UNICODE_WCHAR_CACHE */
#else /* POSIX */
if (!PyUnicode_FSConverter(self->path, &ub))
return NULL;
- const char *path = PyBytes_AS_STRING(ub);
+ path = PyBytes_AS_STRING(ub);
if (self->dir_fd != DEFAULT_DIR_FD) {
#ifdef HAVE_FSTATAT
if (HAVE_FSTATAT_RUNTIME) {
@@ -13815,7 +13916,7 @@ _Py_COMP_DIAG_POP
}
Py_END_ALLOW_THREADS
}
- int saved_errno = errno;
+ saved_errno = errno;
#if defined(MS_WINDOWS) && !USE_UNICODE_WCHAR_CACHE
PyMem_Free(path);
#else /* USE_UNICODE_WCHAR_CACHE */
@@ -13892,6 +13993,7 @@ DirEntry_test_mode(PyTypeObject *defining_class, DirEntry *self,
PyObject *st_mode = NULL;
long mode;
int result;
+ _posixstate *state;
#if defined(MS_WINDOWS) || defined(HAVE_DIRENT_D_TYPE)
int is_symlink;
int need_stat;
@@ -13921,7 +14023,7 @@ DirEntry_test_mode(PyTypeObject *defining_class, DirEntry *self,
}
goto error;
}
- _posixstate* state = get_posix_state(PyType_GetModule(defining_class));
+ state = get_posix_state(PyType_GetModule(defining_class));
st_mode = PyObject_GetAttr(stat, state->st_mode);
if (!st_mode)
goto error;
@@ -14014,23 +14116,29 @@ os_DirEntry_inode_impl(DirEntry *self)
PyObject *unicode;
STRUCT_STAT stat;
int result;
+ int saved_errno;
+#if USE_UNICODE_WCHAR_CACHE
+ const wchar_t *path;
+#else /* USE_UNICODE_WCHAR_CACHE */
+ wchar_t *path;
+#endif /* USE_UNICODE_WCHAR_CACHE */
if (!PyUnicode_FSDecoder(self->path, &unicode))
return NULL;
#if USE_UNICODE_WCHAR_CACHE
_Py_COMP_DIAG_PUSH
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
- const wchar_t *path = PyUnicode_AsUnicode(unicode);
+ path = PyUnicode_AsUnicode(unicode);
result = LSTAT(path, &stat);
- int saved_errno = errno;
+ saved_errno = errno;
Py_DECREF(unicode);
_Py_COMP_DIAG_POP
#else /* USE_UNICODE_WCHAR_CACHE */
- wchar_t *path = PyUnicode_AsWideCharString(unicode, NULL);
+ path = PyUnicode_AsWideCharString(unicode, NULL);
Py_DECREF(unicode);
result = LSTAT(path, &stat);
- int saved_errno = errno;
+ saved_errno = errno;
PyMem_Free(path);
#endif /* USE_UNICODE_WCHAR_CACHE */
@@ -14042,11 +14150,11 @@ _Py_COMP_DIAG_POP
self->win32_file_index = stat.st_ino;
self->got_file_index = 1;
}
- static_assert(sizeof(unsigned long long) >= sizeof(self->win32_file_index),
+ static_assert(sizeof(unsigned PY_LONG_LONG) >= sizeof(self->win32_file_index),
"DirEntry.win32_file_index is larger than unsigned long long");
return PyLong_FromUnsignedLongLong(self->win32_file_index);
#else /* POSIX */
- static_assert(sizeof(unsigned long long) >= sizeof(self->d_ino),
+ static_assert(sizeof(unsigned PY_LONG_LONG) >= sizeof(self->d_ino),
"DirEntry.d_ino is larger than unsigned long long");
return PyLong_FromUnsignedLongLong(self->d_ino);
#endif
@@ -14510,10 +14618,11 @@ static void
ScandirIterator_dealloc(ScandirIterator *iterator)
{
PyTypeObject *tp = Py_TYPE(iterator);
+ freefunc free_func;
if (PyObject_CallFinalizerFromDealloc((PyObject *)iterator) < 0)
return;
- freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
+ free_func = PyType_GetSlot(tp, Py_tp_free);
free_func(iterator);
Py_DECREF(tp);
}
@@ -14564,6 +14673,7 @@ os_scandir_impl(PyObject *module, path_t *path)
/*[clinic end generated code: output=6eb2668b675ca89e input=6bdd312708fc3bb0]*/
{
ScandirIterator *iterator;
+ PyObject *ScandirIteratorType;
#ifdef MS_WINDOWS
wchar_t *path_strW;
#else
@@ -14578,7 +14688,7 @@ os_scandir_impl(PyObject *module, path_t *path)
return NULL;
}
- PyObject *ScandirIteratorType = get_posix_state(module)->ScandirIteratorType;
+ ScandirIteratorType = get_posix_state(module)->ScandirIteratorType;
iterator = PyObject_New(ScandirIterator, (PyTypeObject *)ScandirIteratorType);
if (!iterator)
return NULL;
@@ -14793,8 +14903,10 @@ os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags)
* on win32
*/
+#if !defined(_MSC_VER) || _MSC_VER >= 1300
typedef DLL_DIRECTORY_COOKIE (WINAPI *PAddDllDirectory)(PCWSTR newDirectory);
typedef BOOL (WINAPI *PRemoveDllDirectory)(DLL_DIRECTORY_COOKIE cookie);
+#endif
/*[clinic input]
os._add_dll_directory
@@ -14815,6 +14927,11 @@ static PyObject *
os__add_dll_directory_impl(PyObject *module, path_t *path)
/*[clinic end generated code: output=80b025daebb5d683 input=1de3e6c13a5808c8]*/
{
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ PyErr_SetString(PyExc_NotImplementedError,
+ "DLL directory management is unavailable on this Windows build");
+ return NULL;
+#else
HMODULE hKernel32;
PAddDllDirectory AddDllDirectory;
DLL_DIRECTORY_COOKIE cookie = 0;
@@ -14842,6 +14959,7 @@ os__add_dll_directory_impl(PyObject *module, path_t *path)
}
return PyCapsule_New(cookie, "DLL directory cookie", NULL);
+#endif
}
/*[clinic input]
@@ -14860,6 +14978,11 @@ static PyObject *
os__remove_dll_directory_impl(PyObject *module, PyObject *cookie)
/*[clinic end generated code: output=594350433ae535bc input=c1d16a7e7d9dc5dc]*/
{
+#if defined(_MSC_VER) && _MSC_VER < 1300
+ PyErr_SetString(PyExc_NotImplementedError,
+ "DLL directory management is unavailable on this Windows build");
+ return NULL;
+#else
HMODULE hKernel32;
PRemoveDllDirectory RemoveDllDirectory;
DLL_DIRECTORY_COOKIE cookieValue;
@@ -14896,6 +15019,7 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie)
}
Py_RETURN_NONE;
+#endif
}
#endif
@@ -14974,14 +15098,17 @@ os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj)
}
return PyLong_FromLong(exitcode);
#else
+ unsigned PY_LONG_LONG status;
+ unsigned PY_LONG_LONG exitcode;
+
/* Windows implementation: see os.waitpid() implementation
which uses _cwait(). */
- unsigned long long status = PyLong_AsUnsignedLongLong(status_obj);
- if (status == (unsigned long long)-1 && PyErr_Occurred()) {
+ status = PyLong_AsUnsignedLongLong(status_obj);
+ if (status == (unsigned PY_LONG_LONG)-1 && PyErr_Occurred()) {
return NULL;
}
- unsigned long long exitcode = (status >> 8);
+ exitcode = (status >> 8);
/* ExitProcess() accepts an UINT type:
reject exit code which doesn't fit in an UINT */
if (exitcode > UINT_MAX) {
@@ -15960,7 +16087,12 @@ static const struct have_function {
static int
posixmodule_exec(PyObject *m)
{
- _posixstate *state = get_posix_state(m);
+ _posixstate *state;
+ PyObject *ScandirIteratorType;
+ PyObject *list;
+ const struct have_function *trace;
+
+ state = get_posix_state(m);
#if defined(HAVE_PWRITEV)
if (HAVE_PWRITEV_RUNTIME) {} else {
@@ -16044,7 +16176,7 @@ posixmodule_exec(PyObject *m)
}
/* initialize scandir types */
- PyObject *ScandirIteratorType = PyType_FromModuleAndSpec(m, &ScandirIteratorType_spec, NULL);
+ ScandirIteratorType = PyType_FromModuleAndSpec(m, &ScandirIteratorType_spec, NULL);
if (ScandirIteratorType == NULL) {
return -1;
}
@@ -16091,11 +16223,11 @@ posixmodule_exec(PyObject *m)
* provide list of locally available functions
* so os.py can populate support_* lists
*/
- PyObject *list = PyList_New(0);
+ list = PyList_New(0);
if (!list) {
return -1;
}
- for (const struct have_function *trace = have_functions; trace->label; trace++) {
+ for (trace = have_functions; trace->label; trace++) {
PyObject *unicode;
if (trace->probe && !trace->probe()) continue;
unicode = PyUnicode_DecodeASCII(trace->label, strlen(trace->label), NULL);
@@ -16117,14 +16249,14 @@ static PyModuleDef_Slot posixmodile_slots[] = {
static struct PyModuleDef posixmodule = {
PyModuleDef_HEAD_INIT,
- .m_name = MODNAME,
- .m_doc = posix__doc__,
- .m_size = sizeof(_posixstate),
- .m_methods = posix_methods,
- .m_slots = posixmodile_slots,
- .m_traverse = _posix_traverse,
- .m_clear = _posix_clear,
- .m_free = _posix_free,
+ MODNAME,
+ posix__doc__,
+ sizeof(_posixstate),
+ posix_methods,
+ posixmodile_slots,
+ _posix_traverse,
+ _posix_clear,
+ _posix_free,
};
PyMODINIT_FUNC
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
index 9153557..a4c0735 100644
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -33,7 +33,7 @@ class SHA1Type "SHA1object *" "&PyType_Type"
#if SIZEOF_INT == 4
typedef unsigned int SHA1_INT32; /* 32-bit integer */
-typedef long long SHA1_INT64; /* 64-bit integer */
+typedef PY_LONG_LONG SHA1_INT64; /* 64-bit integer */
#else
/* not defined. compilation will die. */
#endif
@@ -473,11 +473,12 @@ static PyType_Slot sha1_type_slots[] = {
};
static PyType_Spec sha1_type_spec = {
- .name = "_sha1.sha1",
- .basicsize = sizeof(SHA1object),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
- .slots = sha1_type_slots
+ "_sha1.sha1",
+ sizeof(SHA1object),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
+ sha1_type_slots
};
/* The single module-level function: new() */
@@ -498,11 +499,12 @@ _sha1_sha1_impl(PyObject *module, PyObject *string, int usedforsecurity)
{
SHA1object *new;
Py_buffer buf;
+ SHA1State *st;
if (string)
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
- SHA1State *st = sha1_get_state(module);
+ st = sha1_get_state(module);
if ((new = newSHA1object(st)) == NULL) {
if (string)
PyBuffer_Release(&buf);
@@ -588,13 +590,14 @@ static PyModuleDef_Slot _sha1_slots[] = {
static struct PyModuleDef _sha1module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_sha1",
- .m_size = sizeof(SHA1State),
- .m_methods = SHA1_functions,
- .m_slots = _sha1_slots,
- .m_traverse = _sha1_traverse,
- .m_clear = _sha1_clear,
- .m_free = _sha1_free
+ "_sha1",
+ NULL,
+ sizeof(SHA1State),
+ SHA1_functions,
+ _sha1_slots,
+ _sha1_traverse,
+ _sha1_clear,
+ _sha1_free
};
PyMODINIT_FUNC
diff --git a/Modules/sha256module.c b/Modules/sha256module.c
index 17ee866..4dceaae 100644
--- a/Modules/sha256module.c
+++ b/Modules/sha256module.c
@@ -559,19 +559,21 @@ static PyType_Slot sha256_types_slots[] = {
};
static PyType_Spec sha224_type_spec = {
- .name = "_sha256.sha224",
- .basicsize = sizeof(SHAobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
- .slots = sha256_types_slots
+ "_sha256.sha224",
+ sizeof(SHAobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
+ sha256_types_slots
};
static PyType_Spec sha256_type_spec = {
- .name = "_sha256.sha256",
- .basicsize = sizeof(SHAobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
- .slots = sha256_types_slots
+ "_sha256.sha256",
+ sizeof(SHAobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
+ sha256_types_slots
};
/* The single module-level function: new() */
@@ -591,14 +593,15 @@ _sha256_sha256_impl(PyObject *module, PyObject *string, int usedforsecurity)
/*[clinic end generated code: output=a1de327e8e1185cf input=9be86301aeb14ea5]*/
{
Py_buffer buf;
+ _sha256_state *state;
+ SHAobject *new;
if (string) {
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
}
- _sha256_state *state = PyModule_GetState(module);
+ state = PyModule_GetState(module);
- SHAobject *new;
if ((new = newSHA256object(state)) == NULL) {
if (string) {
PyBuffer_Release(&buf);
@@ -638,12 +641,14 @@ _sha256_sha224_impl(PyObject *module, PyObject *string, int usedforsecurity)
/*[clinic end generated code: output=08be6b36569bc69c input=9fcfb46e460860ac]*/
{
Py_buffer buf;
+ _sha256_state *state;
+ SHAobject *new;
+
if (string) {
GET_BUFFER_VIEW_OR_ERROUT(string, &buf);
}
- _sha256_state *state = PyModule_GetState(module);
- SHAobject *new;
+ state = PyModule_GetState(module);
if ((new = newSHA224object(state)) == NULL) {
if (string) {
PyBuffer_Release(&buf);
@@ -739,13 +744,14 @@ static PyModuleDef_Slot _sha256_slots[] = {
static struct PyModuleDef _sha256module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_sha256",
- .m_size = sizeof(_sha256_state),
- .m_methods = SHA_functions,
- .m_slots = _sha256_slots,
- .m_traverse = _sha256_traverse,
- .m_clear = _sha256_clear,
- .m_free = _sha256_free
+ "_sha256",
+ NULL,
+ sizeof(_sha256_state),
+ SHA_functions,
+ _sha256_slots,
+ _sha256_traverse,
+ _sha256_clear,
+ _sha256_free
};
/* Initialize this module. */
diff --git a/Modules/sha512module.c b/Modules/sha512module.c
index bf4408b..db47ad2 100644
--- a/Modules/sha512module.c
+++ b/Modules/sha512module.c
@@ -105,12 +105,12 @@ static void SHAcopy(SHAobject *src, SHAobject *dest)
/* Various logical functions */
#define ROR64(x, y) \
- ( ((((x) & 0xFFFFFFFFFFFFFFFFULL)>>((unsigned long long)(y) & 63)) | \
- ((x)<<((unsigned long long)(64-((y) & 63))))) & 0xFFFFFFFFFFFFFFFFULL)
+ ( ((((x) & PY_ULL(0xFFFFFFFFFFFFFFFF))>>((unsigned PY_LONG_LONG)(y) & 63)) | \
+ ((x)<<((unsigned PY_LONG_LONG)(64-((y) & 63))))) & PY_ULL(0xFFFFFFFFFFFFFFFF))
#define Ch(x,y,z) (z ^ (x & (y ^ z)))
#define Maj(x,y,z) (((x | y) & z) | (x & y))
#define S(x, n) ROR64((x),(n))
-#define R(x, n) (((x) & 0xFFFFFFFFFFFFFFFFULL) >> ((unsigned long long)n))
+#define R(x, n) (((x) & PY_ULL(0xFFFFFFFFFFFFFFFF)) >> ((unsigned PY_LONG_LONG)n))
#define Sigma0(x) (S(x, 28) ^ S(x, 34) ^ S(x, 39))
#define Sigma1(x) (S(x, 14) ^ S(x, 18) ^ S(x, 41))
#define Gamma0(x) (S(x, 1) ^ S(x, 8) ^ R(x, 7))
@@ -142,86 +142,86 @@ sha512_transform(SHAobject *sha_info)
d += t0; \
h = t0 + t1;
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],0,0x428a2f98d728ae22ULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],1,0x7137449123ef65cdULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],2,0xb5c0fbcfec4d3b2fULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],3,0xe9b5dba58189dbbcULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],4,0x3956c25bf348b538ULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],5,0x59f111f1b605d019ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],6,0x923f82a4af194f9bULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],7,0xab1c5ed5da6d8118ULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],8,0xd807aa98a3030242ULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],9,0x12835b0145706fbeULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],10,0x243185be4ee4b28cULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],11,0x550c7dc3d5ffb4e2ULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],12,0x72be5d74f27b896fULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],13,0x80deb1fe3b1696b1ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],14,0x9bdc06a725c71235ULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],15,0xc19bf174cf692694ULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],16,0xe49b69c19ef14ad2ULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],17,0xefbe4786384f25e3ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],18,0x0fc19dc68b8cd5b5ULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],19,0x240ca1cc77ac9c65ULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],20,0x2de92c6f592b0275ULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],21,0x4a7484aa6ea6e483ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],22,0x5cb0a9dcbd41fbd4ULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],23,0x76f988da831153b5ULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],24,0x983e5152ee66dfabULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],25,0xa831c66d2db43210ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],26,0xb00327c898fb213fULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],27,0xbf597fc7beef0ee4ULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],28,0xc6e00bf33da88fc2ULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],29,0xd5a79147930aa725ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],30,0x06ca6351e003826fULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],31,0x142929670a0e6e70ULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],32,0x27b70a8546d22ffcULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],33,0x2e1b21385c26c926ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],34,0x4d2c6dfc5ac42aedULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],35,0x53380d139d95b3dfULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],36,0x650a73548baf63deULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],37,0x766a0abb3c77b2a8ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],38,0x81c2c92e47edaee6ULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],39,0x92722c851482353bULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],40,0xa2bfe8a14cf10364ULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],41,0xa81a664bbc423001ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],42,0xc24b8b70d0f89791ULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],43,0xc76c51a30654be30ULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],44,0xd192e819d6ef5218ULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],45,0xd69906245565a910ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],46,0xf40e35855771202aULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],47,0x106aa07032bbd1b8ULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],48,0x19a4c116b8d2d0c8ULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],49,0x1e376c085141ab53ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],50,0x2748774cdf8eeb99ULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],51,0x34b0bcb5e19b48a8ULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],52,0x391c0cb3c5c95a63ULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],53,0x4ed8aa4ae3418acbULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],54,0x5b9cca4f7763e373ULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],55,0x682e6ff3d6b2b8a3ULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],56,0x748f82ee5defb2fcULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],57,0x78a5636f43172f60ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],58,0x84c87814a1f0ab72ULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],59,0x8cc702081a6439ecULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],60,0x90befffa23631e28ULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],61,0xa4506cebde82bde9ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],62,0xbef9a3f7b2c67915ULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],63,0xc67178f2e372532bULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],64,0xca273eceea26619cULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],65,0xd186b8c721c0c207ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],66,0xeada7dd6cde0eb1eULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],67,0xf57d4f7fee6ed178ULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],68,0x06f067aa72176fbaULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],69,0x0a637dc5a2c898a6ULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],70,0x113f9804bef90daeULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],71,0x1b710b35131c471bULL);
- RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],72,0x28db77f523047d84ULL);
- RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],73,0x32caab7b40c72493ULL);
- RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],74,0x3c9ebe0a15c9bebcULL);
- RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],75,0x431d67c49c100d4cULL);
- RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],76,0x4cc5d4becb3e42b6ULL);
- RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],77,0x597f299cfc657e2aULL);
- RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],78,0x5fcb6fab3ad6faecULL);
- RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],79,0x6c44198c4a475817ULL);
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],0,PY_ULL(0x428a2f98d728ae22));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],1,PY_ULL(0x7137449123ef65cd));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],2,PY_ULL(0xb5c0fbcfec4d3b2f));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],3,PY_ULL(0xe9b5dba58189dbbc));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],4,PY_ULL(0x3956c25bf348b538));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],5,PY_ULL(0x59f111f1b605d019));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],6,PY_ULL(0x923f82a4af194f9b));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],7,PY_ULL(0xab1c5ed5da6d8118));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],8,PY_ULL(0xd807aa98a3030242));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],9,PY_ULL(0x12835b0145706fbe));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],10,PY_ULL(0x243185be4ee4b28c));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],11,PY_ULL(0x550c7dc3d5ffb4e2));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],12,PY_ULL(0x72be5d74f27b896f));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],13,PY_ULL(0x80deb1fe3b1696b1));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],14,PY_ULL(0x9bdc06a725c71235));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],15,PY_ULL(0xc19bf174cf692694));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],16,PY_ULL(0xe49b69c19ef14ad2));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],17,PY_ULL(0xefbe4786384f25e3));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],18,PY_ULL(0x0fc19dc68b8cd5b5));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],19,PY_ULL(0x240ca1cc77ac9c65));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],20,PY_ULL(0x2de92c6f592b0275));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],21,PY_ULL(0x4a7484aa6ea6e483));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],22,PY_ULL(0x5cb0a9dcbd41fbd4));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],23,PY_ULL(0x76f988da831153b5));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],24,PY_ULL(0x983e5152ee66dfab));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],25,PY_ULL(0xa831c66d2db43210));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],26,PY_ULL(0xb00327c898fb213f));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],27,PY_ULL(0xbf597fc7beef0ee4));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],28,PY_ULL(0xc6e00bf33da88fc2));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],29,PY_ULL(0xd5a79147930aa725));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],30,PY_ULL(0x06ca6351e003826f));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],31,PY_ULL(0x142929670a0e6e70));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],32,PY_ULL(0x27b70a8546d22ffc));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],33,PY_ULL(0x2e1b21385c26c926));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],34,PY_ULL(0x4d2c6dfc5ac42aed));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],35,PY_ULL(0x53380d139d95b3df));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],36,PY_ULL(0x650a73548baf63de));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],37,PY_ULL(0x766a0abb3c77b2a8));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],38,PY_ULL(0x81c2c92e47edaee6));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],39,PY_ULL(0x92722c851482353b));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],40,PY_ULL(0xa2bfe8a14cf10364));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],41,PY_ULL(0xa81a664bbc423001));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],42,PY_ULL(0xc24b8b70d0f89791));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],43,PY_ULL(0xc76c51a30654be30));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],44,PY_ULL(0xd192e819d6ef5218));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],45,PY_ULL(0xd69906245565a910));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],46,PY_ULL(0xf40e35855771202a));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],47,PY_ULL(0x106aa07032bbd1b8));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],48,PY_ULL(0x19a4c116b8d2d0c8));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],49,PY_ULL(0x1e376c085141ab53));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],50,PY_ULL(0x2748774cdf8eeb99));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],51,PY_ULL(0x34b0bcb5e19b48a8));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],52,PY_ULL(0x391c0cb3c5c95a63));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],53,PY_ULL(0x4ed8aa4ae3418acb));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],54,PY_ULL(0x5b9cca4f7763e373));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],55,PY_ULL(0x682e6ff3d6b2b8a3));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],56,PY_ULL(0x748f82ee5defb2fc));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],57,PY_ULL(0x78a5636f43172f60));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],58,PY_ULL(0x84c87814a1f0ab72));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],59,PY_ULL(0x8cc702081a6439ec));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],60,PY_ULL(0x90befffa23631e28));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],61,PY_ULL(0xa4506cebde82bde9));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],62,PY_ULL(0xbef9a3f7b2c67915));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],63,PY_ULL(0xc67178f2e372532b));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],64,PY_ULL(0xca273eceea26619c));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],65,PY_ULL(0xd186b8c721c0c207));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],66,PY_ULL(0xeada7dd6cde0eb1e));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],67,PY_ULL(0xf57d4f7fee6ed178));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],68,PY_ULL(0x06f067aa72176fba));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],69,PY_ULL(0x0a637dc5a2c898a6));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],70,PY_ULL(0x113f9804bef90dae));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],71,PY_ULL(0x1b710b35131c471b));
+ RND(S[0],S[1],S[2],S[3],S[4],S[5],S[6],S[7],72,PY_ULL(0x28db77f523047d84));
+ RND(S[7],S[0],S[1],S[2],S[3],S[4],S[5],S[6],73,PY_ULL(0x32caab7b40c72493));
+ RND(S[6],S[7],S[0],S[1],S[2],S[3],S[4],S[5],74,PY_ULL(0x3c9ebe0a15c9bebc));
+ RND(S[5],S[6],S[7],S[0],S[1],S[2],S[3],S[4],75,PY_ULL(0x431d67c49c100d4c));
+ RND(S[4],S[5],S[6],S[7],S[0],S[1],S[2],S[3],76,PY_ULL(0x4cc5d4becb3e42b6));
+ RND(S[3],S[4],S[5],S[6],S[7],S[0],S[1],S[2],77,PY_ULL(0x597f299cfc657e2a));
+ RND(S[2],S[3],S[4],S[5],S[6],S[7],S[0],S[1],78,PY_ULL(0x5fcb6fab3ad6faec));
+ RND(S[1],S[2],S[3],S[4],S[5],S[6],S[7],S[0],79,PY_ULL(0x6c44198c4a475817));
#undef RND
@@ -615,11 +615,12 @@ static PyType_Slot sha512_sha384_type_slots[] = {
};
static PyType_Spec sha512_sha384_type_spec = {
- .name = "_sha512.sha384",
- .basicsize = sizeof(SHAobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
- .slots = sha512_sha384_type_slots
+ "_sha512.sha384",
+ sizeof(SHAobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
+ sha512_sha384_type_slots
};
static PyType_Slot sha512_sha512_type_slots[] = {
@@ -634,11 +635,12 @@ static PyType_Slot sha512_sha512_type_slots[] = {
// Using PyType_GetModuleState() on this type is safe since
// it cannot be subclassed: it does not have the Py_TPFLAGS_BASETYPE flag.
static PyType_Spec sha512_sha512_type_spec = {
- .name = "_sha512.sha512",
- .basicsize = sizeof(SHAobject),
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
- Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
- .slots = sha512_sha512_type_slots
+ "_sha512.sha512",
+ sizeof(SHAobject),
+ 0,
+ (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
+ Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC),
+ sha512_sha512_type_slots
};
/* The single module-level function: new() */
@@ -803,13 +805,14 @@ static PyModuleDef_Slot _sha512_slots[] = {
static struct PyModuleDef _sha512module = {
PyModuleDef_HEAD_INIT,
- .m_name = "_sha512",
- .m_size = sizeof(SHA512State),
- .m_methods = SHA_functions,
- .m_slots = _sha512_slots,
- .m_traverse = _sha512_traverse,
- .m_clear = _sha512_clear,
- .m_free = _sha512_free
+ "_sha512",
+ NULL,
+ sizeof(SHA512State),
+ SHA_functions,
+ _sha512_slots,
+ _sha512_traverse,
+ _sha512_clear,
+ _sha512_free
};
PyMODINIT_FUNC
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 8305f64..f7d9eb3 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -27,6 +27,9 @@
# ifdef HAVE_PROCESS_H
# include <process.h>
# endif
+# ifndef EWOULDBLOCK
+# define EWOULDBLOCK EAGAIN
+# endif
#endif
#ifdef HAVE_SIGNAL_H
@@ -115,7 +118,7 @@ static volatile struct {
SOCKET_T fd;
int warn_on_full_buffer;
int use_send;
-} wakeup = {.fd = INVALID_FD, .warn_on_full_buffer = 1, .use_send = 0};
+} wakeup = {INVALID_FD, 1, 0};
#else
#define INVALID_FD (-1)
static volatile struct {
@@ -305,6 +308,9 @@ report_wakeup_send_error(void* data)
static void
trip_signal(int sig_num)
{
+ int fd;
+ PyInterpreterState *interp;
+
_Py_atomic_store_relaxed(&Handlers[sig_num].tripped, 1);
/* Set is_tripped after setting .tripped, as it gets
@@ -312,7 +318,7 @@ trip_signal(int sig_num)
_Py_atomic_store(&is_tripped, 1);
/* Signals are always handled by the main interpreter */
- PyInterpreterState *interp = _PyInterpreterState_Main();
+ interp = _PyInterpreterState_Main();
/* Notify ceval.c */
_PyEval_SignalReceived(interp);
@@ -336,7 +342,6 @@ trip_signal(int sig_num)
See bpo-30038 for more details.
*/
- int fd;
#ifdef MS_WINDOWS
fd = Py_SAFE_DOWNCAST(wakeup.fd, SOCKET_T, int);
#else
@@ -519,9 +524,12 @@ static PyObject *
signal_signal_impl(PyObject *module, int signalnum, PyObject *handler)
/*[clinic end generated code: output=b44cfda43780f3a1 input=deee84af5fa0432c]*/
{
- _signal_module_state *modstate = get_signal_state(module);
+ _signal_module_state *modstate;
PyObject *old_handler;
void (*func)(int);
+ PyThreadState *tstate;
+
+ modstate = get_signal_state(module);
#ifdef MS_WINDOWS
/* Validate that signalnum is one of the allowable signals */
switch (signalnum) {
@@ -542,7 +550,7 @@ signal_signal_impl(PyObject *module, int signalnum, PyObject *handler)
}
#endif
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (!_Py_ThreadCanHandleSignals(tstate->interp)) {
_PyErr_SetString(tstate, PyExc_ValueError,
"signal only works in main thread "
@@ -751,6 +759,7 @@ static PyObject*
signal_set_wakeup_fd(PyObject *self, PyObject *args, PyObject *kwds)
{
struct _Py_stat_struct status;
+ PyThreadState *tstate;
static char *kwlist[] = {
"", "warn_on_full_buffer", NULL,
};
@@ -778,7 +787,7 @@ signal_set_wakeup_fd(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
#endif
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (!_Py_ThreadCanHandleSignals(tstate->interp)) {
_PyErr_SetString(tstate, PyExc_ValueError,
"set_wakeup_fd only works in main thread "
@@ -874,14 +883,16 @@ The fd must be non-blocking.");
int
PySignal_SetWakeupFd(int fd)
{
+ int old_fd;
+
if (fd < 0) {
fd = -1;
}
#ifdef MS_WINDOWS
- int old_fd = Py_SAFE_DOWNCAST(wakeup.fd, SOCKET_T, int);
+ old_fd = Py_SAFE_DOWNCAST(wakeup.fd, SOCKET_T, int);
#else
- int old_fd = wakeup.fd;
+ old_fd = wakeup.fd;
#endif
wakeup.fd = fd;
wakeup.warn_on_full_buffer = 1;
@@ -1110,17 +1121,19 @@ signal_valid_signals_impl(PyObject *module)
/*[clinic end generated code: output=1609cffbcfcf1314 input=86a3717ff25288f2]*/
{
#ifdef MS_WINDOWS
+ PyObject *tup;
+ PyObject *set;
#ifdef SIGBREAK
- PyObject *tup = Py_BuildValue("(iiiiiii)", SIGABRT, SIGBREAK, SIGFPE,
- SIGILL, SIGINT, SIGSEGV, SIGTERM);
+ tup = Py_BuildValue("(iiiiiii)", SIGABRT, SIGBREAK, SIGFPE,
+ SIGILL, SIGINT, SIGSEGV, SIGTERM);
#else
- PyObject *tup = Py_BuildValue("(iiiiii)", SIGABRT, SIGFPE, SIGILL,
- SIGINT, SIGSEGV, SIGTERM);
+ tup = Py_BuildValue("(iiiiii)", SIGABRT, SIGFPE, SIGILL,
+ SIGINT, SIGSEGV, SIGTERM);
#endif
if (tup == NULL) {
return NULL;
}
- PyObject *set = PySet_New(tup);
+ set = PySet_New(tup);
Py_DECREF(tup);
return set;
#else
@@ -1614,10 +1627,14 @@ signal_add_constants(PyObject *module)
static int
signal_get_set_handlers(signal_state_t *state, PyObject *mod_dict)
{
+ int signum;
+ PyObject *sigint_func;
+
// Get signal handlers
- for (int signum = 1; signum < Py_NSIG; signum++) {
+ for (signum = 1; signum < Py_NSIG; signum++) {
void (*c_handler)(int) = PyOS_getsig(signum);
PyObject *func;
+ PyObject *old_func;
if (c_handler == SIG_DFL) {
func = state->default_handler;
}
@@ -1629,13 +1646,13 @@ signal_get_set_handlers(signal_state_t *state, PyObject *mod_dict)
}
// If signal_module_exec() is called more than one, we must
// clear the strong reference to the previous function.
- PyObject* old_func = get_handler(signum);
+ old_func = get_handler(signum);
set_handler(signum, Py_NewRef(func));
Py_XDECREF(old_func);
}
// Install Python SIGINT handler which raises KeyboardInterrupt
- PyObject* sigint_func = get_handler(SIGINT);
+ sigint_func = get_handler(SIGINT);
if (sigint_func == state->default_handler) {
PyObject *int_handler = PyMapping_GetItemString(mod_dict,
"default_int_handler");
@@ -1654,10 +1671,15 @@ signal_get_set_handlers(signal_state_t *state, PyObject *mod_dict)
static int
signal_module_exec(PyObject *m)
{
+ signal_state_t *state;
+ _signal_module_state *modstate;
+ PyObject *d;
+ PyThreadState *tstate;
+
assert(!PyErr_Occurred());
- signal_state_t *state = &signal_global_state;
- _signal_module_state *modstate = get_signal_state(m);
+ state = &signal_global_state;
+ modstate = get_signal_state(m);
modstate->default_handler = state->default_handler; // borrowed ref
modstate->ignore_handler = state->ignore_handler; // borrowed ref
@@ -1675,7 +1697,7 @@ signal_module_exec(PyObject *m)
}
/* Add some symbolic constants to the module */
- PyObject *d = PyModule_GetDict(m);
+ d = PyModule_GetDict(m);
if (PyDict_SetItemString(d, "SIG_DFL", state->default_handler) < 0) {
return -1;
}
@@ -1700,7 +1722,7 @@ signal_module_exec(PyObject *m)
}
#endif
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
if (_Py_IsMainInterpreter(tstate->interp)) {
if (signal_get_set_handlers(state, d) < 0) {
return -1;
@@ -1747,14 +1769,14 @@ static PyModuleDef_Slot signal_slots[] = {
static struct PyModuleDef signal_module = {
PyModuleDef_HEAD_INIT,
"_signal",
- .m_doc = module_doc,
- .m_size = sizeof(_signal_module_state),
- .m_methods = signal_methods,
- .m_slots = signal_slots,
+ module_doc,
+ sizeof(_signal_module_state),
+ signal_methods,
+ signal_slots,
#ifdef PYHAVE_ITIMER_ERROR
- .m_traverse = _signal_module_traverse,
- .m_clear = _signal_module_clear,
- .m_free = _signal_module_free,
+ _signal_module_traverse,
+ _signal_module_clear,
+ _signal_module_free,
#endif
};
@@ -1769,10 +1791,13 @@ PyInit__signal(void)
void
_PySignal_Fini(void)
{
- signal_state_t *state = &signal_global_state;
+ signal_state_t *state;
+ int signum;
+
+ state = &signal_global_state;
// Restore default signals and clear handlers
- for (int signum = 1; signum < Py_NSIG; signum++) {
+ for (signum = 1; signum < Py_NSIG; signum++) {
PyObject *func = get_handler(signum);
_Py_atomic_store_relaxed(&Handlers[signum].tripped, 0);
set_handler(signum, NULL);
@@ -1815,6 +1840,10 @@ PyErr_CheckSignals(void)
int
_PyErr_CheckSignalsTstate(PyThreadState *tstate)
{
+ _PyInterpreterFrame *frame;
+ signal_state_t *state;
+ int i;
+
_Py_CHECK_EMSCRIPTEN_SIGNALS();
if (!_Py_atomic_load(&is_tripped)) {
return 0;
@@ -1836,12 +1865,16 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
*/
_Py_atomic_store(&is_tripped, 0);
- _PyInterpreterFrame *frame = tstate->cframe->current_frame;
+ frame = tstate->cframe->current_frame;
while (frame && _PyFrame_IsIncomplete(frame)) {
frame = frame->previous;
}
- signal_state_t *state = &signal_global_state;
- for (int i = 1; i < Py_NSIG; i++) {
+ state = &signal_global_state;
+ for (i = 1; i < Py_NSIG; i++) {
+ PyObject *func;
+ PyObject *arglist;
+ PyObject *result;
+
if (!_Py_atomic_load_relaxed(&Handlers[i].tripped)) {
continue;
}
@@ -1853,7 +1886,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
* signal handler for it by the time PyErr_CheckSignals() is called
* (see bpo-43406).
*/
- PyObject *func = get_handler(i);
+ func = get_handler(i);
if (func == NULL || func == Py_None ||
compare_handler(func, state->ignore_handler) ||
compare_handler(func, state->default_handler)) {
@@ -1871,7 +1904,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
PyErr_WriteUnraisable(Py_None);
continue;
}
- PyObject *arglist = NULL;
+ arglist = NULL;
if (frame == NULL) {
arglist = Py_BuildValue("(iO)", i, Py_None);
}
@@ -1881,7 +1914,6 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
arglist = Py_BuildValue("(iO)", i, f);
}
}
- PyObject *result;
if (arglist) {
result = _PyObject_Call(tstate, func, arglist, NULL);
Py_DECREF(arglist);
@@ -1918,12 +1950,15 @@ _PyErr_CheckSignals(void)
int
PyErr_SetInterruptEx(int signum)
{
+ signal_state_t *state;
+ PyObject *func;
+
if (signum < 1 || signum >= Py_NSIG) {
return -1;
}
- signal_state_t *state = &signal_global_state;
- PyObject *func = get_handler(signum);
+ state = &signal_global_state;
+ func = get_handler(signum);
if (!compare_handler(func, state->ignore_handler)
&& !compare_handler(func, state->default_handler)) {
trip_signal(signum);
@@ -1987,7 +2022,10 @@ _Py_RestoreSignals(void)
int
_PySignal_Init(int install_signal_handlers)
{
- signal_state_t *state = &signal_global_state;
+ signal_state_t *state;
+ int signum;
+
+ state = &signal_global_state;
state->default_handler = PyLong_FromVoidPtr((void *)SIG_DFL);
if (state->default_handler == NULL) {
@@ -2008,7 +2046,7 @@ _PySignal_Init(int install_signal_handlers)
}
#endif
- for (int signum = 1; signum < Py_NSIG; signum++) {
+ for (signum = 1; signum < Py_NSIG; signum++) {
_Py_atomic_store_relaxed(&Handlers[signum].tripped, 0);
}
@@ -2053,12 +2091,14 @@ PyOS_InterruptOccurred(void)
static void
_clear_pending_signals(void)
{
+ int i;
+
if (!_Py_atomic_load(&is_tripped)) {
return;
}
_Py_atomic_store(&is_tripped, 0);
- for (int i = 1; i < Py_NSIG; ++i) {
+ for (i = 1; i < Py_NSIG; ++i) {
_Py_atomic_store_relaxed(&Handlers[i].tripped, 0);
}
}
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index f0c9b46..f5d0d6b 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -490,7 +490,7 @@ remove_unusable_flags(PyObject *m)
#endif
#endif
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) && defined(AF_BTH)
#define sockaddr_rc SOCKADDR_BTH_REDEF
#define USE_BLUETOOTH 1
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
index 1b35b11..4550562 100644
--- a/Modules/socketmodule.h
+++ b/Modules/socketmodule.h
@@ -264,7 +264,7 @@ typedef union sock_addr {
struct sockaddr_rc bt_rc;
struct sockaddr_sco bt_sco;
struct sockaddr_hci bt_hci;
-#elif defined(MS_WINDOWS)
+#elif defined(MS_WINDOWS) && defined(AF_BTH)
struct SOCKADDR_BTH_REDEF bt_rc;
#endif
#ifdef HAVE_NETPACKET_PACKET_H
diff --git a/Modules/symtablemodule.c b/Modules/symtablemodule.c
index c25ecc2..57cbc44 100644
--- a/Modules/symtablemodule.c
+++ b/Modules/symtablemodule.c
@@ -27,12 +27,15 @@ _symtable_symtable_impl(PyObject *module, PyObject *source,
struct symtable *st;
PyObject *t;
int start;
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
+ PyCompilerFlags cf;
PyObject *source_copy = NULL;
+ const char *str;
+ cf.cf_flags = 0;
+ cf.cf_feature_version = PY_MINOR_VERSION;
cf.cf_flags = PyCF_SOURCE_IS_UTF8;
- const char *str = _Py_SourceAsString(source, "symtable", "string or bytes", &cf, &source_copy);
+ str = _Py_SourceAsString(source, "symtable", "string or bytes", &cf, &source_copy);
if (str == NULL) {
return NULL;
}
@@ -113,10 +116,11 @@ static PyModuleDef_Slot symtable_slots[] = {
static struct PyModuleDef symtablemodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "_symtable",
- .m_size = 0,
- .m_methods = symtable_methods,
- .m_slots = symtable_slots,
+ "_symtable",
+ NULL,
+ 0,
+ symtable_methods,
+ symtable_slots,
};
PyMODINIT_FUNC
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index b8e0e48..65f0097 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -141,6 +141,8 @@ static int
_PyTime_GetClockWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
{
static int initialized = 0;
+ clock_t ticks;
+ _PyTime_t ns;
if (!initialized) {
initialized = 1;
@@ -161,14 +163,14 @@ _PyTime_GetClockWithInfo(_PyTime_t *tp, _Py_clock_info_t *info)
info->adjustable = 0;
}
- clock_t ticks = clock();
+ ticks = clock();
if (ticks == (clock_t)-1) {
PyErr_SetString(PyExc_RuntimeError,
"the processor time used is not available "
"or its value cannot be represented");
return -1;
}
- _PyTime_t ns = _PyTime_MulDiv(ticks, SEC_TO_NS, (_PyTime_t)CLOCKS_PER_SEC);
+ ns = _PyTime_MulDiv(ticks, SEC_TO_NS, (_PyTime_t)CLOCKS_PER_SEC);
*tp = _PyTime_FromNanoseconds(ns);
return 0;
}
@@ -496,6 +498,7 @@ time_gmtime(PyObject *module, PyObject *args)
{
time_t when;
struct tm buf;
+ time_module_state *state;
if (!parse_time_t_args(args, "|O:gmtime", &when))
return NULL;
@@ -504,7 +507,7 @@ time_gmtime(PyObject *module, PyObject *args)
if (_PyTime_gmtime(when, &buf) != 0)
return NULL;
- time_module_state *state = get_time_state(module);
+ state = get_time_state(module);
#ifdef HAVE_STRUCT_TM_TM_ZONE
return tmtotuple(state, &buf);
#else
@@ -540,13 +543,14 @@ time_localtime(PyObject *module, PyObject *args)
{
time_t when;
struct tm buf;
+ time_module_state *state;
if (!parse_time_t_args(args, "|O:localtime", &when))
return NULL;
if (_PyTime_localtime(when, &buf) != 0)
return NULL;
- time_module_state *state = get_time_state(module);
+ state = get_time_state(module);
#ifdef HAVE_STRUCT_TM_TM_ZONE
return tmtotuple(state, &buf);
#else
@@ -761,6 +765,7 @@ time_strftime(PyObject *module, PyObject *args)
time_char *outbuf = NULL;
size_t i;
PyObject *ret = NULL;
+ time_module_state *state;
memset((void *) &buf, '\0', sizeof(buf));
@@ -770,7 +775,7 @@ time_strftime(PyObject *module, PyObject *args)
if (!PyArg_ParseTuple(args, "U|O:strftime", &format_arg, &tup))
return NULL;
- time_module_state *state = get_time_state(module);
+ state = get_time_state(module);
if (tup == NULL) {
time_t tt = time(NULL);
if (_PyTime_localtime(tt, &buf) != 0)
@@ -962,11 +967,12 @@ time_asctime(PyObject *module, PyObject *args)
{
PyObject *tup = NULL;
struct tm buf;
+ time_module_state *state;
if (!PyArg_UnpackTuple(args, "asctime", 0, 1, &tup))
return NULL;
- time_module_state *state = get_time_state(module);
+ state = get_time_state(module);
if (tup == NULL) {
time_t tt = time(NULL);
if (_PyTime_localtime(tt, &buf) != 0)
@@ -1724,6 +1730,13 @@ get_gmtoff(time_t t, struct tm *p)
static int
init_timezone(PyObject *m)
{
+#ifdef HAVE_DECL_TZNAME
+ PyObject *otz0, *otz1;
+#ifdef MS_WINDOWS
+ TIME_ZONE_INFORMATION tzinfo = {0};
+#endif
+#endif
+
assert(!PyErr_Occurred());
/* This code moved from PyInit_time wholesale to allow calling it from
@@ -1743,7 +1756,6 @@ init_timezone(PyObject *m)
And I'm lazy and hate C so nyer.
*/
#ifdef HAVE_DECL_TZNAME
- PyObject *otz0, *otz1;
tzset();
PyModule_AddIntConstant(m, "timezone", _Py_timezone);
#ifdef HAVE_ALTZONE
@@ -1753,7 +1765,6 @@ init_timezone(PyObject *m)
#endif
PyModule_AddIntConstant(m, "daylight", _Py_daylight);
#ifdef MS_WINDOWS
- TIME_ZONE_INFORMATION tzinfo = {0};
GetTimeZoneInformation(&tzinfo);
otz0 = PyUnicode_FromWideChar(tzinfo.StandardName, -1);
if (otz0 == NULL) {
@@ -2094,14 +2105,14 @@ static struct PyModuleDef_Slot time_slots[] = {
static struct PyModuleDef timemodule = {
PyModuleDef_HEAD_INIT,
- .m_name = "time",
- .m_doc = module_doc,
- .m_size = sizeof(time_module_state),
- .m_methods = time_methods,
- .m_slots = time_slots,
- .m_traverse = time_module_traverse,
- .m_clear = time_module_clear,
- .m_free = time_module_free,
+ "time",
+ module_doc,
+ sizeof(time_module_state),
+ time_methods,
+ time_slots,
+ time_module_traverse,
+ time_module_clear,
+ time_module_free,
};
PyMODINIT_FUNC
@@ -2117,6 +2128,14 @@ PyInit_time(void)
static int
pysleep(_PyTime_t timeout)
{
+#ifdef MS_WINDOWS
+ _PyTime_t timeout_100ns;
+ LARGE_INTEGER relative_timeout;
+ HANDLE timer;
+ HANDLE sigint_event;
+ HANDLE events[2];
+ DWORD rc;
+#endif
assert(timeout >= 0);
#ifndef MS_WINDOWS
@@ -2196,7 +2215,7 @@ pysleep(_PyTime_t timeout)
return 0;
#else // MS_WINDOWS
- _PyTime_t timeout_100ns = _PyTime_As100Nanoseconds(timeout,
+ timeout_100ns = _PyTime_As100Nanoseconds(timeout,
_PyTime_ROUND_CEILING);
// Maintain Windows Sleep() semantics for time.sleep(0)
@@ -2211,13 +2230,12 @@ pysleep(_PyTime_t timeout)
return 0;
}
- LARGE_INTEGER relative_timeout;
// No need to check for integer overflow, both types are signed
assert(sizeof(relative_timeout) == sizeof(timeout_100ns));
// SetWaitableTimer(): a negative due time indicates relative time
relative_timeout.QuadPart = -timeout_100ns;
- HANDLE timer = CreateWaitableTimerExW(NULL, NULL, timer_flags,
+ timer = CreateWaitableTimerExW(NULL, NULL, timer_flags,
TIMER_ALL_ACCESS);
if (timer == NULL) {
PyErr_SetFromWindowsErr(0);
@@ -2237,7 +2255,7 @@ pysleep(_PyTime_t timeout)
// Only the main thread can be interrupted by SIGINT.
// Signal handlers are only executed in the main thread.
if (_PyOS_IsMainThread()) {
- HANDLE sigint_event = _PyOS_SigintEvent();
+ sigint_event = _PyOS_SigintEvent();
while (1) {
// Check for pending SIGINT signal before resetting the event
@@ -2246,8 +2264,8 @@ pysleep(_PyTime_t timeout)
}
ResetEvent(sigint_event);
- HANDLE events[] = {timer, sigint_event};
- DWORD rc;
+ events[0] = timer;
+ events[1] = sigint_event;
Py_BEGIN_ALLOW_THREADS
rc = WaitForMultipleObjects(Py_ARRAY_LENGTH(events), events,
@@ -2272,8 +2290,6 @@ pysleep(_PyTime_t timeout)
}
}
else {
- DWORD rc;
-
Py_BEGIN_ALLOW_THREADS
rc = WaitForSingleObject(timer, INFINITE);
Py_END_ALLOW_THREADS
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 93987c2..c321b2f 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -52,12 +52,14 @@ PyObject_Type(PyObject *o)
Py_ssize_t
PyObject_Size(PyObject *o)
{
+ PySequenceMethods *m;
+
if (o == NULL) {
null_error();
return -1;
}
- PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+ m = Py_TYPE(o)->tp_as_sequence;
if (m && m->sq_length) {
Py_ssize_t len = m->sq_length(o);
assert(_Py_CheckSlotResult(o, "__len__", len >= 0));
@@ -148,18 +150,21 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
PyObject *
PyObject_GetItem(PyObject *o, PyObject *key)
{
+ PyMappingMethods *m;
+ PySequenceMethods *ms;
+
if (o == NULL || key == NULL) {
return null_error();
}
- PyMappingMethods *m = Py_TYPE(o)->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_subscript) {
PyObject *item = m->mp_subscript(o, key);
assert(_Py_CheckSlotResult(o, "__getitem__", item != NULL));
return item;
}
- PySequenceMethods *ms = Py_TYPE(o)->tp_as_sequence;
+ ms = Py_TYPE(o)->tp_as_sequence;
if (ms && ms->sq_item) {
if (_PyIndex_Check(key)) {
Py_ssize_t key_value;
@@ -202,12 +207,14 @@ PyObject_GetItem(PyObject *o, PyObject *key)
int
PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
{
+ PyMappingMethods *m;
+
if (o == NULL || key == NULL || value == NULL) {
null_error();
return -1;
}
- PyMappingMethods *m = Py_TYPE(o)->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_ass_subscript) {
int res = m->mp_ass_subscript(o, key, value);
assert(_Py_CheckSlotResult(o, "__setitem__", res >= 0));
@@ -236,12 +243,14 @@ PyObject_SetItem(PyObject *o, PyObject *key, PyObject *value)
int
PyObject_DelItem(PyObject *o, PyObject *key)
{
+ PyMappingMethods *m;
+
if (o == NULL || key == NULL) {
null_error();
return -1;
}
- PyMappingMethods *m = Py_TYPE(o)->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_ass_subscript) {
int res = m->mp_ass_subscript(o, key, (PyObject*)NULL);
assert(_Py_CheckSlotResult(o, "__delitem__", res >= 0));
@@ -379,7 +388,10 @@ int PyObject_AsWriteBuffer(PyObject *obj,
int
PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
{
- PyBufferProcs *pb = Py_TYPE(obj)->tp_as_buffer;
+ PyBufferProcs *pb;
+ int res;
+
+ pb = Py_TYPE(obj)->tp_as_buffer;
if (pb == NULL || pb->bf_getbuffer == NULL) {
PyErr_Format(PyExc_TypeError,
@@ -387,7 +399,7 @@ PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
Py_TYPE(obj)->tp_name);
return -1;
}
- int res = (*pb->bf_getbuffer)(obj, view, flags);
+ res = (*pb->bf_getbuffer)(obj, view, flags);
assert(_Py_CheckSlotResult(obj, "getbuffer", res >= 0));
return res;
}
@@ -831,9 +843,11 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
int
PyNumber_Check(PyObject *o)
{
+ PyNumberMethods *nb;
+
if (o == NULL)
return 0;
- PyNumberMethods *nb = Py_TYPE(o)->tp_as_number;
+ nb = Py_TYPE(o)->tp_as_number;
return nb && (nb->nb_index || nb->nb_int || nb->nb_float || PyComplex_Check(o));
}
@@ -863,6 +877,8 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot
)
{
binaryfunc slotv;
+ binaryfunc slotw;
+
if (Py_TYPE(v)->tp_as_number != NULL) {
slotv = NB_BINOP(Py_TYPE(v)->tp_as_number, op_slot);
}
@@ -870,7 +886,6 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot
slotv = NULL;
}
- binaryfunc slotw;
if (!Py_IS_TYPE(w, Py_TYPE(v)) && Py_TYPE(w)->tp_as_number != NULL) {
slotw = NB_BINOP(Py_TYPE(w)->tp_as_number, op_slot);
if (slotw == slotv) {
@@ -967,10 +982,15 @@ ternary_op(PyObject *v,
const char *op_name
)
{
- PyNumberMethods *mv = Py_TYPE(v)->tp_as_number;
- PyNumberMethods *mw = Py_TYPE(w)->tp_as_number;
-
+ PyNumberMethods *mv;
+ PyNumberMethods *mw;
+ PyNumberMethods *mz;
ternaryfunc slotv;
+ ternaryfunc slotw;
+
+ mv = Py_TYPE(v)->tp_as_number;
+ mw = Py_TYPE(w)->tp_as_number;
+
if (mv != NULL) {
slotv = NB_TERNOP(mv, op_slot);
}
@@ -978,7 +998,6 @@ ternary_op(PyObject *v,
slotv = NULL;
}
- ternaryfunc slotw;
if (!Py_IS_TYPE(w, Py_TYPE(v)) && mw != NULL) {
slotw = NB_TERNOP(mw, op_slot);
if (slotw == slotv) {
@@ -1015,7 +1034,7 @@ ternary_op(PyObject *v,
Py_DECREF(x); /* can't do it */
}
- PyNumberMethods *mz = Py_TYPE(z)->tp_as_number;
+ mz = Py_TYPE(z)->tp_as_number;
if (mz != NULL) {
ternaryfunc slotz = NB_TERNOP(mz, op_slot);
if (slotz == slotv || slotz == slotw) {
@@ -1070,13 +1089,16 @@ BINARY_FUNC(PyNumber_Divmod, nb_divmod, "divmod()")
PyObject *
PyNumber_Add(PyObject *v, PyObject *w)
{
- PyObject *result = BINARY_OP1(v, w, NB_SLOT(nb_add), "+");
+ PySequenceMethods *m;
+ PyObject *result;
+
+ result = BINARY_OP1(v, w, NB_SLOT(nb_add), "+");
if (result != Py_NotImplemented) {
return result;
}
Py_DECREF(result);
- PySequenceMethods *m = Py_TYPE(v)->tp_as_sequence;
+ m = Py_TYPE(v)->tp_as_sequence;
if (m && m->sq_concat) {
result = (*m->sq_concat)(v, w);
assert(_Py_CheckSlotResult(v, "+", result != NULL));
@@ -1090,6 +1112,8 @@ static PyObject *
sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
{
Py_ssize_t count;
+ PyObject *res;
+
if (_PyIndex_Check(n)) {
count = PyNumber_AsSsize_t(n, PyExc_OverflowError);
if (count == -1 && PyErr_Occurred()) {
@@ -1100,7 +1124,7 @@ sequence_repeat(ssizeargfunc repeatfunc, PyObject *seq, PyObject *n)
return type_error("can't multiply sequence by "
"non-int of type '%.200s'", n);
}
- PyObject *res = (*repeatfunc)(seq, count);
+ res = (*repeatfunc)(seq, count);
assert(_Py_CheckSlotResult(seq, "*", res != NULL));
return res;
}
@@ -1326,11 +1350,13 @@ _PyNumber_InPlacePowerNoMod(PyObject *lhs, PyObject *rhs)
PyObject *
PyNumber_Negative(PyObject *o)
{
+ PyNumberMethods *m;
+
if (o == NULL) {
return null_error();
}
- PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_negative) {
PyObject *res = (*m->nb_negative)(o);
assert(_Py_CheckSlotResult(o, "__neg__", res != NULL));
@@ -1343,11 +1369,13 @@ PyNumber_Negative(PyObject *o)
PyObject *
PyNumber_Positive(PyObject *o)
{
+ PyNumberMethods *m;
+
if (o == NULL) {
return null_error();
}
- PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_positive) {
PyObject *res = (*m->nb_positive)(o);
assert(_Py_CheckSlotResult(o, "__pos__", res != NULL));
@@ -1360,11 +1388,13 @@ PyNumber_Positive(PyObject *o)
PyObject *
PyNumber_Invert(PyObject *o)
{
+ PyNumberMethods *m;
+
if (o == NULL) {
return null_error();
}
- PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_invert) {
PyObject *res = (*m->nb_invert)(o);
assert(_Py_CheckSlotResult(o, "__invert__", res != NULL));
@@ -1377,11 +1407,13 @@ PyNumber_Invert(PyObject *o)
PyObject *
PyNumber_Absolute(PyObject *o)
{
+ PyNumberMethods *m;
+
if (o == NULL) {
return null_error();
}
- PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_absolute) {
PyObject *res = m->nb_absolute(o);
assert(_Py_CheckSlotResult(o, "__abs__", res != NULL));
@@ -1407,6 +1439,8 @@ PyIndex_Check(PyObject *obj)
PyObject *
_PyNumber_Index(PyObject *item)
{
+ PyObject *result;
+
if (item == NULL) {
return null_error();
}
@@ -1422,7 +1456,7 @@ _PyNumber_Index(PyObject *item)
return NULL;
}
- PyObject *result = Py_TYPE(item)->tp_as_number->nb_index(item);
+ result = Py_TYPE(item)->tp_as_number->nb_index(item);
assert(_Py_CheckSlotResult(item, "__index__", result != NULL));
if (!result || PyLong_CheckExact(result)) {
return result;
@@ -1466,6 +1500,7 @@ PyNumber_Index(PyObject *item)
Py_ssize_t
PyNumber_AsSsize_t(PyObject *item, PyObject *err)
{
+ PyThreadState *tstate;
Py_ssize_t result;
PyObject *runerr;
PyObject *value = _PyNumber_Index(item);
@@ -1477,7 +1512,7 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err)
if (result != -1)
goto finish;
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
runerr = _PyErr_Occurred(tstate);
if (!runerr) {
goto finish;
@@ -1633,6 +1668,9 @@ PyNumber_Long(PyObject *o)
PyObject *
PyNumber_Float(PyObject *o)
{
+ PyNumberMethods *m;
+ double val;
+
if (o == NULL) {
return null_error();
}
@@ -1641,7 +1679,7 @@ PyNumber_Float(PyObject *o)
return Py_NewRef(o);
}
- PyNumberMethods *m = Py_TYPE(o)->tp_as_number;
+ m = Py_TYPE(o)->tp_as_number;
if (m && m->nb_float) { /* This should include subclasses of float */
PyObject *res = m->nb_float(o);
assert(_Py_CheckSlotResult(o, "__float__", res != NULL));
@@ -1665,7 +1703,7 @@ PyNumber_Float(PyObject *o)
Py_DECREF(res);
return NULL;
}
- double val = PyFloat_AS_DOUBLE(res);
+ val = PyFloat_AS_DOUBLE(res);
Py_DECREF(res);
return PyFloat_FromDouble(val);
}
@@ -1675,7 +1713,7 @@ PyNumber_Float(PyObject *o)
if (!res) {
return NULL;
}
- double val = PyLong_AsDouble(res);
+ val = PyLong_AsDouble(res);
Py_DECREF(res);
if (val == -1.0 && PyErr_Occurred()) {
return NULL;
@@ -1694,15 +1732,18 @@ PyNumber_Float(PyObject *o)
PyObject *
PyNumber_ToBase(PyObject *n, int base)
{
+ PyObject *index;
+ PyObject *res;
+
if (!(base == 2 || base == 8 || base == 10 || base == 16)) {
PyErr_SetString(PyExc_SystemError,
"PyNumber_ToBase: base must be 2, 8, 10 or 16");
return NULL;
}
- PyObject *index = _PyNumber_Index(n);
+ index = _PyNumber_Index(n);
if (!index)
return NULL;
- PyObject *res = _PyLong_Format(index, base);
+ res = _PyLong_Format(index, base);
Py_DECREF(index);
return res;
}
@@ -1722,12 +1763,14 @@ PySequence_Check(PyObject *s)
Py_ssize_t
PySequence_Size(PyObject *s)
{
+ PySequenceMethods *m;
+
if (s == NULL) {
null_error();
return -1;
}
- PySequenceMethods *m = Py_TYPE(s)->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_length) {
Py_ssize_t len = m->sq_length(s);
assert(_Py_CheckSlotResult(s, "__len__", len >= 0));
@@ -1753,11 +1796,13 @@ PySequence_Length(PyObject *s)
PyObject *
PySequence_Concat(PyObject *s, PyObject *o)
{
+ PySequenceMethods *m;
+
if (s == NULL || o == NULL) {
return null_error();
}
- PySequenceMethods *m = Py_TYPE(s)->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_concat) {
PyObject *res = m->sq_concat(s, o);
assert(_Py_CheckSlotResult(s, "+", res != NULL));
@@ -1779,11 +1824,13 @@ PySequence_Concat(PyObject *s, PyObject *o)
PyObject *
PySequence_Repeat(PyObject *o, Py_ssize_t count)
{
+ PySequenceMethods *m;
+
if (o == NULL) {
return null_error();
}
- PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+ m = Py_TYPE(o)->tp_as_sequence;
if (m && m->sq_repeat) {
PyObject *res = m->sq_repeat(o, count);
assert(_Py_CheckSlotResult(o, "*", res != NULL));
@@ -1810,11 +1857,13 @@ PySequence_Repeat(PyObject *o, Py_ssize_t count)
PyObject *
PySequence_InPlaceConcat(PyObject *s, PyObject *o)
{
+ PySequenceMethods *m;
+
if (s == NULL || o == NULL) {
return null_error();
}
- PySequenceMethods *m = Py_TYPE(s)->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_inplace_concat) {
PyObject *res = m->sq_inplace_concat(s, o);
assert(_Py_CheckSlotResult(s, "+=", res != NULL));
@@ -1839,11 +1888,13 @@ PySequence_InPlaceConcat(PyObject *s, PyObject *o)
PyObject *
PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)
{
+ PySequenceMethods *m;
+
if (o == NULL) {
return null_error();
}
- PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
+ m = Py_TYPE(o)->tp_as_sequence;
if (m && m->sq_inplace_repeat) {
PyObject *res = m->sq_inplace_repeat(o, count);
assert(_Py_CheckSlotResult(o, "*=", res != NULL));
@@ -1873,11 +1924,14 @@ PySequence_InPlaceRepeat(PyObject *o, Py_ssize_t count)
PyObject *
PySequence_GetItem(PyObject *s, Py_ssize_t i)
{
+ PySequenceMethods *m;
+ PyObject *res;
+
if (s == NULL) {
return null_error();
}
- PySequenceMethods *m = Py_TYPE(s)->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_item) {
if (i < 0) {
if (m->sq_length) {
@@ -1889,7 +1943,7 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i)
i += l;
}
}
- PyObject *res = m->sq_item(s, i);
+ res = m->sq_item(s, i);
assert(_Py_CheckSlotResult(s, "__getitem__", res != NULL));
return res;
}
@@ -1903,17 +1957,21 @@ PySequence_GetItem(PyObject *s, Py_ssize_t i)
PyObject *
PySequence_GetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2)
{
+ PyMappingMethods *mp;
+ PyObject *slice;
+ PyObject *res;
+
if (!s) {
return null_error();
}
- PyMappingMethods *mp = Py_TYPE(s)->tp_as_mapping;
+ mp = Py_TYPE(s)->tp_as_mapping;
if (mp && mp->mp_subscript) {
- PyObject *slice = _PySlice_FromIndices(i1, i2);
+ slice = _PySlice_FromIndices(i1, i2);
if (!slice) {
return NULL;
}
- PyObject *res = mp->mp_subscript(s, slice);
+ res = mp->mp_subscript(s, slice);
assert(_Py_CheckSlotResult(s, "__getitem__", res != NULL));
Py_DECREF(slice);
return res;
@@ -1925,12 +1983,15 @@ PySequence_GetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2)
int
PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o)
{
+ PySequenceMethods *m;
+ int res;
+
if (s == NULL) {
null_error();
return -1;
}
- PySequenceMethods *m = Py_TYPE(s)->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
@@ -1942,7 +2003,7 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o)
i += l;
}
}
- int res = m->sq_ass_item(s, i, o);
+ res = m->sq_ass_item(s, i, o);
assert(_Py_CheckSlotResult(s, "__setitem__", res >= 0));
return res;
}
@@ -1958,12 +2019,15 @@ PySequence_SetItem(PyObject *s, Py_ssize_t i, PyObject *o)
int
PySequence_DelItem(PyObject *s, Py_ssize_t i)
{
+ PySequenceMethods *m;
+ int res;
+
if (s == NULL) {
null_error();
return -1;
}
- PySequenceMethods *m = Py_TYPE(s)->tp_as_sequence;
+ m = Py_TYPE(s)->tp_as_sequence;
if (m && m->sq_ass_item) {
if (i < 0) {
if (m->sq_length) {
@@ -1975,7 +2039,7 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i)
i += l;
}
}
- int res = m->sq_ass_item(s, i, (PyObject *)NULL);
+ res = m->sq_ass_item(s, i, (PyObject *)NULL);
assert(_Py_CheckSlotResult(s, "__delitem__", res >= 0));
return res;
}
@@ -1991,17 +2055,21 @@ PySequence_DelItem(PyObject *s, Py_ssize_t i)
int
PySequence_SetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2, PyObject *o)
{
+ PyMappingMethods *mp;
+ PyObject *slice;
+ int res;
+
if (s == NULL) {
null_error();
return -1;
}
- PyMappingMethods *mp = Py_TYPE(s)->tp_as_mapping;
+ mp = Py_TYPE(s)->tp_as_mapping;
if (mp && mp->mp_ass_subscript) {
- PyObject *slice = _PySlice_FromIndices(i1, i2);
+ slice = _PySlice_FromIndices(i1, i2);
if (!slice)
return -1;
- int res = mp->mp_ass_subscript(s, slice, o);
+ res = mp->mp_ass_subscript(s, slice, o);
assert(_Py_CheckSlotResult(s, "__setitem__", res >= 0));
Py_DECREF(slice);
return res;
@@ -2014,18 +2082,22 @@ PySequence_SetSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2, PyObject *o)
int
PySequence_DelSlice(PyObject *s, Py_ssize_t i1, Py_ssize_t i2)
{
+ PyMappingMethods *mp;
+ PyObject *slice;
+ int res;
+
if (s == NULL) {
null_error();
return -1;
}
- PyMappingMethods *mp = Py_TYPE(s)->tp_as_mapping;
+ mp = Py_TYPE(s)->tp_as_mapping;
if (mp && mp->mp_ass_subscript) {
- PyObject *slice = _PySlice_FromIndices(i1, i2);
+ slice = _PySlice_FromIndices(i1, i2);
if (!slice) {
return -1;
}
- int res = mp->mp_ass_subscript(s, slice, NULL);
+ res = mp->mp_ass_subscript(s, slice, NULL);
assert(_Py_CheckSlotResult(s, "__delitem__", res >= 0));
Py_DECREF(slice);
return res;
@@ -2273,13 +2345,14 @@ PySequence_Count(PyObject *s, PyObject *o)
int
PySequence_Contains(PyObject *seq, PyObject *ob)
{
+ Py_ssize_t result;
PySequenceMethods *sqm = Py_TYPE(seq)->tp_as_sequence;
if (sqm != NULL && sqm->sq_contains != NULL) {
int res = (*sqm->sq_contains)(seq, ob);
assert(_Py_CheckSlotResult(seq, "__contains__", res >= 0));
return res;
}
- Py_ssize_t result = _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS);
+ result = _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS);
return Py_SAFE_DOWNCAST(result, Py_ssize_t, int);
}
@@ -2309,12 +2382,14 @@ PyMapping_Check(PyObject *o)
Py_ssize_t
PyMapping_Size(PyObject *o)
{
+ PyMappingMethods *m;
+
if (o == NULL) {
null_error();
return -1;
}
- PyMappingMethods *m = Py_TYPE(o)->tp_as_mapping;
+ m = Py_TYPE(o)->tp_as_mapping;
if (m && m->mp_length) {
Py_ssize_t len = m->mp_length(o);
assert(_Py_CheckSlotResult(o, "__len__", len >= 0));
@@ -2616,6 +2691,14 @@ object_isinstance(PyObject *inst, PyObject *cls)
static int
object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls)
{
+ Py_ssize_t n;
+ Py_ssize_t i;
+ int r;
+ PyObject *item;
+ PyObject *checker;
+ PyObject *res;
+ int ok;
+
/* Quick test for an exact match */
if (Py_IS_TYPE(inst, (PyTypeObject *)cls)) {
return 1;
@@ -2636,10 +2719,10 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls
if (_Py_EnterRecursiveCallTstate(tstate, " in __instancecheck__")) {
return -1;
}
- Py_ssize_t n = PyTuple_GET_SIZE(cls);
- int r = 0;
- for (Py_ssize_t i = 0; i < n; ++i) {
- PyObject *item = PyTuple_GET_ITEM(cls, i);
+ n = PyTuple_GET_SIZE(cls);
+ r = 0;
+ for (i = 0; i < n; ++i) {
+ item = PyTuple_GET_ITEM(cls, i);
r = object_recursive_isinstance(tstate, inst, item);
if (r != 0) {
/* either found it, or got an error */
@@ -2650,21 +2733,21 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls
return r;
}
- PyObject *checker = _PyObject_LookupSpecial(cls, &_Py_ID(__instancecheck__));
+ checker = _PyObject_LookupSpecial(cls, &_Py_ID(__instancecheck__));
if (checker != NULL) {
if (_Py_EnterRecursiveCallTstate(tstate, " in __instancecheck__")) {
Py_DECREF(checker);
return -1;
}
- PyObject *res = PyObject_CallOneArg(checker, inst);
+ res = PyObject_CallOneArg(checker, inst);
_Py_LeaveRecursiveCallTstate(tstate);
Py_DECREF(checker);
if (res == NULL) {
return -1;
}
- int ok = PyObject_IsTrue(res);
+ ok = PyObject_IsTrue(res);
Py_DECREF(res);
return ok;
@@ -2710,6 +2793,12 @@ static int
object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
{
PyObject *checker;
+ Py_ssize_t n;
+ Py_ssize_t i;
+ int r;
+ PyObject *item;
+ PyObject *res;
+ int ok;
/* We know what type's __subclasscheck__ does. */
if (PyType_CheckExact(cls)) {
@@ -2728,10 +2817,10 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
if (_Py_EnterRecursiveCallTstate(tstate, " in __subclasscheck__")) {
return -1;
}
- Py_ssize_t n = PyTuple_GET_SIZE(cls);
- int r = 0;
- for (Py_ssize_t i = 0; i < n; ++i) {
- PyObject *item = PyTuple_GET_ITEM(cls, i);
+ n = PyTuple_GET_SIZE(cls);
+ r = 0;
+ for (i = 0; i < n; ++i) {
+ item = PyTuple_GET_ITEM(cls, i);
r = object_issubclass(tstate, derived, item);
if (r != 0)
/* either found it, or got an error */
@@ -2743,12 +2832,12 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
checker = _PyObject_LookupSpecial(cls, &_Py_ID(__subclasscheck__));
if (checker != NULL) {
- int ok = -1;
+ ok = -1;
if (_Py_EnterRecursiveCallTstate(tstate, " in __subclasscheck__")) {
Py_DECREF(checker);
return ok;
}
- PyObject *res = PyObject_CallOneArg(checker, derived);
+ res = PyObject_CallOneArg(checker, derived);
_Py_LeaveRecursiveCallTstate(tstate);
Py_DECREF(checker);
if (res != NULL) {
@@ -2817,12 +2906,13 @@ PyObject *
PyObject_GetAIter(PyObject *o) {
PyTypeObject *t = Py_TYPE(o);
unaryfunc f;
+ PyObject *it;
if (t->tp_as_async == NULL || t->tp_as_async->am_aiter == NULL) {
return type_error("'%.200s' object is not an async iterable", o);
}
f = t->tp_as_async->am_aiter;
- PyObject *it = (*f)(o);
+ it = (*f)(o);
if (it != NULL && !PyAIter_Check(it)) {
PyErr_Format(PyExc_TypeError,
"aiter() returned not an async iterator of type '%.100s'",
diff --git a/Objects/boolobject.c b/Objects/boolobject.c
index 8a20e36..23abfcc 100644
--- a/Objects/boolobject.c
+++ b/Objects/boolobject.c
@@ -50,11 +50,13 @@ bool_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
long ok = 0;
+ Py_ssize_t nargs;
+
if (!_PyArg_NoKwnames("bool", kwnames)) {
return NULL;
}
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("bool", nargs, 0, 1)) {
return NULL;
}
@@ -190,7 +192,17 @@ PyTypeObject PyBool_Type = {
0, /* tp_init */
0, /* tp_alloc */
bool_new, /* tp_new */
- .tp_vectorcall = bool_vectorcall,
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0, /* tp_weaklist */
+ 0, /* tp_del */
+ 0, /* tp_version_tag */
+ 0, /* tp_finalize */
+ bool_vectorcall, /* tp_vectorcall */
};
/* The objects representing bool values False and True */
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 1c50203..bd1c174 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -320,14 +320,19 @@ bytearray_iconcat(PyByteArrayObject *self, PyObject *other)
static PyObject *
bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count)
{
+ Py_ssize_t mysize;
+ Py_ssize_t size;
+ PyByteArrayObject *result;
+ const char *buf;
+
if (count < 0)
count = 0;
- const Py_ssize_t mysize = Py_SIZE(self);
+ mysize = Py_SIZE(self);
if (count > 0 && mysize > PY_SSIZE_T_MAX / count)
return PyErr_NoMemory();
- Py_ssize_t size = mysize * count;
- PyByteArrayObject* result = (PyByteArrayObject *)PyByteArray_FromStringAndSize(NULL, size);
- const char* buf = PyByteArray_AS_STRING(self);
+ size = mysize * count;
+ result = (PyByteArrayObject *)PyByteArray_FromStringAndSize(NULL, size);
+ buf = PyByteArray_AS_STRING(self);
if (result != NULL && size != 0) {
_PyBytes_Repeat(result->ob_bytes, size, buf, mysize);
}
@@ -337,6 +342,10 @@ bytearray_repeat(PyByteArrayObject *self, Py_ssize_t count)
static PyObject *
bytearray_irepeat(PyByteArrayObject *self, Py_ssize_t count)
{
+ Py_ssize_t mysize;
+ Py_ssize_t size;
+ char *buf;
+
if (count < 0)
count = 0;
else if (count == 1) {
@@ -344,14 +353,14 @@ bytearray_irepeat(PyByteArrayObject *self, Py_ssize_t count)
return (PyObject*)self;
}
- const Py_ssize_t mysize = Py_SIZE(self);
+ mysize = Py_SIZE(self);
if (count > 0 && mysize > PY_SSIZE_T_MAX / count)
return PyErr_NoMemory();
- const Py_ssize_t size = mysize * count;
+ size = mysize * count;
if (PyByteArray_Resize((PyObject *)self, size) < 0)
return NULL;
- char* buf = PyByteArray_AS_STRING(self);
+ buf = PyByteArray_AS_STRING(self);
_PyBytes_Repeat(buf, size, buf, mysize);
Py_INCREF(self);
@@ -594,6 +603,7 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
{
Py_ssize_t start, stop, step, slicelen, needed;
char *buf, *bytes;
+ int ival;
buf = PyByteArray_AS_STRING(self);
if (_PyIndex_Check(index)) {
@@ -603,7 +613,7 @@ bytearray_ass_subscript(PyByteArrayObject *self, PyObject *index, PyObject *valu
return -1;
}
- int ival = -1;
+ ival = -1;
// GH-91153: We need to do this *before* the size check, in case values
// has a nasty __index__ method that changes the size of the bytearray:
@@ -845,14 +855,20 @@ bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
}
if (PyList_CheckExact(arg) || PyTuple_CheckExact(arg)) {
- Py_ssize_t size = PySequence_Fast_GET_SIZE(arg);
+ Py_ssize_t size;
+ PyObject **items;
+ char *s;
+ Py_ssize_t i;
+
+ size = PySequence_Fast_GET_SIZE(arg);
if (PyByteArray_Resize((PyObject *)self, size) < 0) {
return -1;
}
- PyObject **items = PySequence_Fast_ITEMS(arg);
- char *s = PyByteArray_AS_STRING(self);
- for (Py_ssize_t i = 0; i < size; i++) {
+ items = PySequence_Fast_ITEMS(arg);
+ s = PyByteArray_AS_STRING(self);
+ for (i = 0; i < size; i++) {
int value;
+ int rc;
if (!PyLong_CheckExact(items[i])) {
/* Resize to 0 and go through slowpath */
if (Py_SIZE(self) != 0) {
@@ -862,7 +878,7 @@ bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
}
goto slowpath;
}
- int rc = _getbytevalue(items[i], &value);
+ rc = _getbytevalue(items[i], &value);
if (!rc) {
return -1;
}
@@ -1867,6 +1883,8 @@ static PyObject*
bytearray_strip_impl_helper(PyByteArrayObject* self, PyObject* bytes, int striptype)
{
Py_ssize_t mysize, byteslen;
+ Py_ssize_t left;
+ Py_ssize_t right;
const char* myptr;
const char* bytesptr;
Py_buffer vbytes;
@@ -1884,12 +1902,12 @@ bytearray_strip_impl_helper(PyByteArrayObject* self, PyObject* bytes, int stript
myptr = PyByteArray_AS_STRING(self);
mysize = Py_SIZE(self);
- Py_ssize_t left = 0;
+ left = 0;
if (striptype != RIGHTSTRIP) {
while (left < mysize && memchr(bytesptr, (unsigned char)myptr[left], byteslen))
left++;
}
- Py_ssize_t right = mysize;
+ right = mysize;
if (striptype != LEFTSTRIP) {
do {
right--;
@@ -2008,8 +2026,10 @@ static PyObject *
bytearray_join(PyByteArrayObject *self, PyObject *iterable_of_bytes)
/*[clinic end generated code: output=a8516370bf68ae08 input=aba6b1f9b30fcb8e]*/
{
+ PyObject *ret;
+
self->ob_exports++; // this protects `self` from being cleared/resized if `iterable_of_bytes` is a custom iterator
- PyObject* ret = stringlib_bytes_join((PyObject*)self, iterable_of_bytes);
+ ret = stringlib_bytes_join((PyObject*)self, iterable_of_bytes);
self->ob_exports--; // unexport `self`
return ret;
}
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index bc53089..9628807 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -649,6 +649,9 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
Py_ssize_t len = 0;
char onechar; /* For byte_converter() */
Py_ssize_t alloc;
+#ifndef NDEBUG
+ char *before;
+#endif
fmt++;
if (*fmt == '%') {
@@ -961,7 +964,7 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
goto error;
}
#ifndef NDEBUG
- char *before = res;
+ before = res;
#endif
/* Write the sign if needed */
@@ -1303,6 +1306,8 @@ _PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
const char *needle, Py_ssize_t len_needle,
Py_ssize_t offset)
{
+ Py_ssize_t res;
+
assert(len_haystack >= 0);
assert(len_needle >= 0);
// Extra checks because stringlib_find accesses haystack[len_haystack].
@@ -1313,10 +1318,11 @@ _PyBytes_Find(const char *haystack, Py_ssize_t len_haystack,
return -1;
}
assert(len_haystack >= 1);
- Py_ssize_t res = stringlib_find(haystack, len_haystack - 1,
- needle, len_needle, offset);
+ res = stringlib_find(haystack, len_haystack - 1,
+ needle, len_needle, offset);
if (res == -1) {
- Py_ssize_t last_align = len_haystack - len_needle;
+ Py_ssize_t last_align;
+ last_align = len_haystack - len_needle;
if (memcmp(haystack + last_align, needle, len_needle) == 0) {
return offset + last_align;
}
@@ -3613,10 +3619,11 @@ _PyBytes_Repeat(char* dest, Py_ssize_t len_dest,
memset(dest, src[0], len_dest);
}
else {
+ Py_ssize_t copied;
if (src != dest) {
memcpy(dest, src, len_src);
}
- Py_ssize_t copied = len_src;
+ copied = len_src;
while (copied < len_dest) {
Py_ssize_t bytes_to_copy = Py_MIN(copied, len_dest - copied);
memcpy(dest + copied, dest, bytes_to_copy);
diff --git a/Objects/call.c b/Objects/call.c
index 678d162..8afba25 100644
--- a/Objects/call.c
+++ b/Objects/call.c
@@ -118,6 +118,10 @@ _PyObject_FastCallDictTstate(PyThreadState *tstate, PyObject *callable,
PyObject *const *args, size_t nargsf,
PyObject *kwargs)
{
+ Py_ssize_t nargs;
+ vectorcallfunc func;
+ PyObject *res;
+
assert(callable != NULL);
/* PyObject_VectorcallDict() must not be called with an exception set,
@@ -125,18 +129,17 @@ _PyObject_FastCallDictTstate(PyThreadState *tstate, PyObject *callable,
caller loses its exception */
assert(!_PyErr_Occurred(tstate));
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ nargs = PyVectorcall_NARGS(nargsf);
assert(nargs >= 0);
assert(nargs == 0 || args != NULL);
assert(kwargs == NULL || PyDict_Check(kwargs));
- vectorcallfunc func = _PyVectorcall_Function(callable);
+ func = _PyVectorcall_Function(callable);
if (func == NULL) {
/* Use tp_call instead */
return _PyObject_MakeTpCall(tstate, callable, args, nargs, kwargs);
}
- PyObject *res;
if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
res = func(callable, args, nargsf, NULL);
}
@@ -171,13 +174,18 @@ _PyObject_MakeTpCall(PyThreadState *tstate, PyObject *callable,
PyObject *const *args, Py_ssize_t nargs,
PyObject *keywords)
{
+ ternaryfunc call;
+ PyObject *argstuple;
+ PyObject *kwdict;
+ PyObject *result;
+
assert(nargs >= 0);
assert(nargs == 0 || args != NULL);
assert(keywords == NULL || PyTuple_Check(keywords) || PyDict_Check(keywords));
/* Slow path: build a temporary tuple for positional arguments and a
* temporary dictionary for keyword arguments (if any) */
- ternaryfunc call = Py_TYPE(callable)->tp_call;
+ call = Py_TYPE(callable)->tp_call;
if (call == NULL) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object is not callable",
@@ -185,12 +193,11 @@ _PyObject_MakeTpCall(PyThreadState *tstate, PyObject *callable,
return NULL;
}
- PyObject *argstuple = _PyTuple_FromArray(args, nargs);
+ argstuple = _PyTuple_FromArray(args, nargs);
if (argstuple == NULL) {
return NULL;
}
- PyObject *kwdict;
if (keywords == NULL || PyDict_Check(keywords)) {
kwdict = keywords;
}
@@ -208,7 +215,7 @@ _PyObject_MakeTpCall(PyThreadState *tstate, PyObject *callable,
}
}
- PyObject *result = NULL;
+ result = NULL;
if (_Py_EnterRecursiveCallTstate(tstate, " while calling a Python object") == 0)
{
result = _PyCFunctionWithKeywords_TrampolineCall(
@@ -236,9 +243,14 @@ static PyObject *
_PyVectorcall_Call(PyThreadState *tstate, vectorcallfunc func,
PyObject *callable, PyObject *tuple, PyObject *kwargs)
{
+ Py_ssize_t nargs;
+ PyObject *const *args;
+ PyObject *kwnames;
+ PyObject *result;
+
assert(func != NULL);
- Py_ssize_t nargs = PyTuple_GET_SIZE(tuple);
+ nargs = PyTuple_GET_SIZE(tuple);
/* Fast path for no keywords */
if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
@@ -246,15 +258,13 @@ _PyVectorcall_Call(PyThreadState *tstate, vectorcallfunc func,
}
/* Convert arguments & call */
- PyObject *const *args;
- PyObject *kwnames;
args = _PyStack_UnpackDict(tstate,
_PyTuple_ITEMS(tuple), nargs,
kwargs, &kwnames);
if (args == NULL) {
return NULL;
}
- PyObject *result = func(callable, args,
+ result = func(callable, args,
nargs | PY_VECTORCALL_ARGUMENTS_OFFSET, kwnames);
_PyStack_UnpackDict_Free(args, nargs, kwnames);
@@ -265,11 +275,15 @@ _PyVectorcall_Call(PyThreadState *tstate, vectorcallfunc func,
PyObject *
PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
{
- PyThreadState *tstate = _PyThreadState_GET();
+ PyThreadState *tstate;
+ Py_ssize_t offset;
+ vectorcallfunc func;
+
+ tstate = _PyThreadState_GET();
/* get vectorcallfunc as in _PyVectorcall_Function, but without
* the Py_TPFLAGS_HAVE_VECTORCALL check */
- Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset;
+ offset = Py_TYPE(callable)->tp_vectorcall_offset;
if (offset <= 0) {
_PyErr_Format(tstate, PyExc_TypeError,
"'%.200s' object does not support vectorcall",
@@ -278,7 +292,6 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
}
assert(PyCallable_Check(callable));
- vectorcallfunc func;
memcpy(&func, (char *) callable + offset, sizeof(func));
if (func == NULL) {
_PyErr_Format(tstate, PyExc_TypeError,
@@ -315,6 +328,7 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable,
{
ternaryfunc call;
PyObject *result;
+ vectorcallfunc vector_func;
/* PyObject_Call() must not be called with an exception set,
because it can clear it (directly or indirectly) and so the
@@ -323,7 +337,7 @@ _PyObject_Call(PyThreadState *tstate, PyObject *callable,
assert(PyTuple_Check(args));
assert(kwargs == NULL || PyDict_Check(kwargs));
- vectorcallfunc vector_func = _PyVectorcall_Function(callable);
+ vector_func = _PyVectorcall_Function(callable);
if (vector_func != NULL) {
return _PyVectorcall_Call(tstate, vector_func, callable, args, kwargs);
}
@@ -367,12 +381,16 @@ PyCFunction_Call(PyObject *callable, PyObject *args, PyObject *kwargs)
PyObject *
PyObject_CallOneArg(PyObject *func, PyObject *arg)
{
- assert(arg != NULL);
PyObject *_args[2];
- PyObject **args = _args + 1; // For PY_VECTORCALL_ARGUMENTS_OFFSET
+ PyObject **args;
+ PyThreadState *tstate;
+ size_t nargsf;
+
+ assert(arg != NULL);
+ args = _args + 1; // For PY_VECTORCALL_ARGUMENTS_OFFSET
args[0] = arg;
- PyThreadState *tstate = _PyThreadState_GET();
- size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
+ tstate = _PyThreadState_GET();
+ nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
return _PyObject_VectorcallTstate(tstate, func, args, nargsf, NULL);
}
@@ -383,11 +401,15 @@ PyObject *
_PyFunction_Vectorcall(PyObject *func, PyObject* const* stack,
size_t nargsf, PyObject *kwnames)
{
+ PyFunctionObject *f;
+ Py_ssize_t nargs;
+ PyThreadState *tstate;
+
assert(PyFunction_Check(func));
- PyFunctionObject *f = (PyFunctionObject *)func;
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ f = (PyFunctionObject *)func;
+ nargs = PyVectorcall_NARGS(nargsf);
assert(nargs >= 0);
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
assert(nargs == 0 || stack != NULL);
if (((PyCodeObject *)f->func_code)->co_flags & CO_OPTIMIZED) {
return _PyEval_Vector(tstate, f, NULL, stack, nargs, kwnames);
@@ -456,12 +478,14 @@ PyObject *
_PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable,
PyObject *obj, PyObject *args, PyObject *kwargs)
{
- assert(PyTuple_Check(args));
-
PyObject *small_stack[_PY_FASTCALL_SMALL_STACK];
PyObject **stack;
+ Py_ssize_t argcount;
+ PyObject *result;
- Py_ssize_t argcount = PyTuple_GET_SIZE(args);
+ assert(PyTuple_Check(args));
+
+ argcount = PyTuple_GET_SIZE(args);
if (argcount + 1 <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
stack = small_stack;
}
@@ -479,7 +503,7 @@ _PyObject_Call_Prepend(PyThreadState *tstate, PyObject *callable,
_PyTuple_ITEMS(args),
argcount * sizeof(PyObject *));
- PyObject *result = _PyObject_FastCallDictTstate(tstate, callable,
+ result = _PyObject_FastCallDictTstate(tstate, callable,
stack, argcount + 1,
kwargs);
if (stack != small_stack) {
@@ -584,10 +608,11 @@ PyObject *
_PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
-
va_list va;
+ PyObject *result;
+
va_start(va, format);
- PyObject *result = _PyObject_CallFunctionVa(tstate, callable, format, va, 1);
+ result = _PyObject_CallFunctionVa(tstate, callable, format, va, 1);
va_end(va);
return result;
@@ -612,19 +637,21 @@ PyObject *
PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *callable;
+ va_list va;
+ PyObject *retval;
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *callable = PyObject_GetAttrString(obj, name);
+ callable = PyObject_GetAttrString(obj, name);
if (callable == NULL) {
return NULL;
}
- va_list va;
va_start(va, format);
- PyObject *retval = callmethod(tstate, callable, format, va, 0);
+ retval = callmethod(tstate, callable, format, va, 0);
va_end(va);
Py_DECREF(callable);
@@ -639,18 +666,21 @@ PyObject *
PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *callable;
+ va_list va;
+ PyObject *retval;
+
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *callable = PyObject_GetAttrString(obj, name);
+ callable = PyObject_GetAttrString(obj, name);
if (callable == NULL) {
return NULL;
}
- va_list va;
va_start(va, format);
- PyObject *retval = callmethod(tstate, callable, format, va, 0);
+ retval = callmethod(tstate, callable, format, va, 0);
va_end(va);
Py_DECREF(callable);
@@ -663,18 +693,21 @@ _PyObject_CallMethod(PyObject *obj, PyObject *name,
const char *format, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *callable;
+ va_list va;
+ PyObject *retval;
+
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *callable = PyObject_GetAttr(obj, name);
+ callable = PyObject_GetAttr(obj, name);
if (callable == NULL) {
return NULL;
}
- va_list va;
va_start(va, format);
- PyObject *retval = callmethod(tstate, callable, format, va, 1);
+ retval = callmethod(tstate, callable, format, va, 1);
va_end(va);
Py_DECREF(callable);
@@ -687,18 +720,21 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
const char *format, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *callable;
+ va_list va;
+ PyObject *retval;
+
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *callable = _PyObject_GetAttrId(obj, name);
+ callable = _PyObject_GetAttrId(obj, name);
if (callable == NULL) {
return NULL;
}
- va_list va;
va_start(va, format);
- PyObject *retval = callmethod(tstate, callable, format, va, 0);
+ retval = callmethod(tstate, callable, format, va, 0);
va_end(va);
Py_DECREF(callable);
@@ -710,8 +746,10 @@ PyObject * _PyObject_CallMethodFormat(PyThreadState *tstate, PyObject *callable,
const char *format, ...)
{
va_list va;
+ PyObject *retval;
+
va_start(va, format);
- PyObject *retval = callmethod(tstate, callable, format, va, 0);
+ retval = callmethod(tstate, callable, format, va, 0);
va_end(va);
return retval;
}
@@ -722,18 +760,21 @@ _PyObject_CallMethod_SizeT(PyObject *obj, const char *name,
const char *format, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *callable;
+ va_list va;
+ PyObject *retval;
+
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *callable = PyObject_GetAttrString(obj, name);
+ callable = PyObject_GetAttrString(obj, name);
if (callable == NULL) {
return NULL;
}
- va_list va;
va_start(va, format);
- PyObject *retval = callmethod(tstate, callable, format, va, 1);
+ retval = callmethod(tstate, callable, format, va, 1);
va_end(va);
Py_DECREF(callable);
@@ -746,18 +787,21 @@ _PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name,
const char *format, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *callable;
+ va_list va;
+ PyObject *retval;
+
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *callable = _PyObject_GetAttrId(obj, name);
+ callable = _PyObject_GetAttrId(obj, name);
if (callable == NULL) {
return NULL;
}
- va_list va;
va_start(va, format);
- PyObject *retval = callmethod(tstate, callable, format, va, 1);
+ retval = callmethod(tstate, callable, format, va, 1);
va_end(va);
Py_DECREF(callable);
@@ -829,14 +873,19 @@ PyObject *
PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
+ PyThreadState *tstate;
+ PyObject *callable;
+ int unbound;
+ PyObject *result;
+
assert(name != NULL);
assert(args != NULL);
assert(PyVectorcall_NARGS(nargsf) >= 1);
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *callable = NULL;
+ tstate = _PyThreadState_GET();
+ callable = NULL;
/* Use args[0] as "self" argument */
- int unbound = _PyObject_GetMethod(args[0], name, &callable);
+ unbound = _PyObject_GetMethod(args[0], name, &callable);
if (callable == NULL) {
return NULL;
}
@@ -852,7 +901,7 @@ PyObject_VectorcallMethod(PyObject *name, PyObject *const *args,
args++;
nargsf--;
}
- PyObject *result = _PyObject_VectorcallTstate(tstate, callable,
+ result = _PyObject_VectorcallTstate(tstate, callable,
args, nargsf, kwnames);
Py_DECREF(callable);
return result;
@@ -863,20 +912,24 @@ PyObject *
PyObject_CallMethodObjArgs(PyObject *obj, PyObject *name, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *callable;
+ int is_method;
+ va_list vargs;
+ PyObject *result;
+
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *callable = NULL;
- int is_method = _PyObject_GetMethod(obj, name, &callable);
+ callable = NULL;
+ is_method = _PyObject_GetMethod(obj, name, &callable);
if (callable == NULL) {
return NULL;
}
obj = is_method ? obj : NULL;
- va_list vargs;
va_start(vargs, name);
- PyObject *result = object_vacall(tstate, obj, callable, vargs);
+ result = object_vacall(tstate, obj, callable, vargs);
va_end(vargs);
Py_DECREF(callable);
@@ -888,25 +941,30 @@ PyObject *
_PyObject_CallMethodIdObjArgs(PyObject *obj, _Py_Identifier *name, ...)
{
PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *oname;
+ PyObject *callable;
+ int is_method;
+ va_list vargs;
+ PyObject *result;
+
if (obj == NULL || name == NULL) {
return null_error(tstate);
}
- PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
+ oname = _PyUnicode_FromId(name); /* borrowed */
if (!oname) {
return NULL;
}
- PyObject *callable = NULL;
- int is_method = _PyObject_GetMethod(obj, oname, &callable);
+ callable = NULL;
+ is_method = _PyObject_GetMethod(obj, oname, &callable);
if (callable == NULL) {
return NULL;
}
obj = is_method ? obj : NULL;
- va_list vargs;
va_start(vargs, name);
- PyObject *result = object_vacall(tstate, obj, callable, vargs);
+ result = object_vacall(tstate, obj, callable, vargs);
va_end(vargs);
Py_DECREF(callable);
@@ -960,28 +1018,39 @@ _PyStack_UnpackDict(PyThreadState *tstate,
PyObject *const *args, Py_ssize_t nargs,
PyObject *kwargs, PyObject **p_kwnames)
{
+ Py_ssize_t nkwargs;
+ Py_ssize_t maxnargs;
+ PyObject **stack;
+ PyObject *kwnames;
+ PyObject **kwstack;
+ Py_ssize_t pos;
+ Py_ssize_t i;
+ PyObject *key;
+ PyObject *value;
+ unsigned long keys_are_strings;
+
assert(nargs >= 0);
assert(kwargs != NULL);
assert(PyDict_Check(kwargs));
- Py_ssize_t nkwargs = PyDict_GET_SIZE(kwargs);
+ nkwargs = PyDict_GET_SIZE(kwargs);
/* Check for overflow in the PyMem_Malloc() call below. The subtraction
* in this check cannot overflow: both maxnargs and nkwargs are
* non-negative signed integers, so their difference fits in the type. */
- Py_ssize_t maxnargs = PY_SSIZE_T_MAX / sizeof(args[0]) - 1;
+ maxnargs = PY_SSIZE_T_MAX / sizeof(args[0]) - 1;
if (nargs > maxnargs - nkwargs) {
_PyErr_NoMemory(tstate);
return NULL;
}
/* Add 1 to support PY_VECTORCALL_ARGUMENTS_OFFSET */
- PyObject **stack = PyMem_Malloc((1 + nargs + nkwargs) * sizeof(args[0]));
+ stack = PyMem_Malloc((1 + nargs + nkwargs) * sizeof(args[0]));
if (stack == NULL) {
_PyErr_NoMemory(tstate);
return NULL;
}
- PyObject *kwnames = PyTuple_New(nkwargs);
+ kwnames = PyTuple_New(nkwargs);
if (kwnames == NULL) {
PyMem_Free(stack);
return NULL;
@@ -990,18 +1059,18 @@ _PyStack_UnpackDict(PyThreadState *tstate,
stack++; /* For PY_VECTORCALL_ARGUMENTS_OFFSET */
/* Copy positional arguments */
- for (Py_ssize_t i = 0; i < nargs; i++) {
+ for (i = 0; i < nargs; i++) {
Py_INCREF(args[i]);
stack[i] = args[i];
}
- PyObject **kwstack = stack + nargs;
+ kwstack = stack + nargs;
/* This loop doesn't support lookup function mutating the dictionary
to change its size. It's a deliberate choice for speed, this function is
called in the performance critical hot code. */
- Py_ssize_t pos = 0, i = 0;
- PyObject *key, *value;
- unsigned long keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS;
+ pos = 0;
+ i = 0;
+ keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS;
while (PyDict_Next(kwargs, &pos, &key, &value)) {
keys_are_strings &= Py_TYPE(key)->tp_flags;
Py_INCREF(key);
@@ -1032,7 +1101,8 @@ _PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs,
PyObject *kwnames)
{
Py_ssize_t n = PyTuple_GET_SIZE(kwnames) + nargs;
- for (Py_ssize_t i = 0; i < n; i++) {
+ Py_ssize_t i;
+ for (i = 0; i < n; i++) {
Py_DECREF(stack[i]);
}
PyMem_Free((PyObject **)stack - 1);
diff --git a/Objects/classobject.c b/Objects/classobject.c
index b9708ba..86bab3d 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -42,33 +42,43 @@ static PyObject *
method_vectorcall(PyObject *method, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
- assert(Py_IS_TYPE(method, &PyMethod_Type));
+ PyThreadState *tstate;
+ PyObject *self;
+ PyObject *func;
+ Py_ssize_t nargs;
+ PyObject *result;
- PyThreadState *tstate = _PyThreadState_GET();
- PyObject *self = PyMethod_GET_SELF(method);
- PyObject *func = PyMethod_GET_FUNCTION(method);
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ assert(Py_IS_TYPE(method, &PyMethod_Type));
- PyObject *result;
+ tstate = _PyThreadState_GET();
+ self = PyMethod_GET_SELF(method);
+ func = PyMethod_GET_FUNCTION(method);
+ nargs = PyVectorcall_NARGS(nargsf);
if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) {
+ PyObject **newargs;
+ PyObject *tmp;
+
/* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */
- PyObject **newargs = (PyObject**)args - 1;
+ newargs = (PyObject**)args - 1;
nargs += 1;
- PyObject *tmp = newargs[0];
+ tmp = newargs[0];
newargs[0] = self;
result = _PyObject_VectorcallTstate(tstate, func, newargs,
nargs, kwnames);
newargs[0] = tmp;
}
else {
- Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
- Py_ssize_t totalargs = nargs + nkwargs;
+ Py_ssize_t nkwargs;
+ Py_ssize_t totalargs;
+ PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
+ PyObject **newargs;
+
+ nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
+ totalargs = nargs + nkwargs;
if (totalargs == 0) {
return _PyObject_VectorcallTstate(tstate, func, &self, 1, NULL);
}
- PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
- PyObject **newargs;
if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
newargs = newargs_stack;
}
@@ -104,11 +114,13 @@ method_vectorcall(PyObject *method, PyObject *const *args,
PyObject *
PyMethod_New(PyObject *func, PyObject *self)
{
+ PyMethodObject *im;
+
if (self == NULL) {
PyErr_BadInternalCall();
return NULL;
}
- PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
+ im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
if (im == NULL) {
return NULL;
}
@@ -323,6 +335,7 @@ method_traverse(PyMethodObject *im, visitproc visit, void *arg)
PyTypeObject PyMethod_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_name = "method",
.tp_basicsize = sizeof(PyMethodObject),
.tp_dealloc = (destructor)method_dealloc,
@@ -342,6 +355,7 @@ PyTypeObject PyMethod_Type = {
.tp_members = method_memberlist,
.tp_getset = method_getset,
.tp_new = method_new,
+#endif
};
/* ------------------------------------------------------------------------
@@ -527,6 +541,7 @@ instancemethod_new_impl(PyTypeObject *type, PyObject *function)
PyTypeObject PyInstanceMethod_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_name = "instancemethod",
.tp_basicsize = sizeof(PyInstanceMethodObject),
.tp_dealloc = instancemethod_dealloc,
@@ -542,4 +557,47 @@ PyTypeObject PyInstanceMethod_Type = {
.tp_getset = instancemethod_getset,
.tp_descr_get = instancemethod_descr_get,
.tp_new = instancemethod_new,
+#endif
};
+
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+void
+_PyClassObject_InitTypes(void)
+{
+ PyMethod_Type.tp_name = "method";
+ PyMethod_Type.tp_basicsize = sizeof(PyMethodObject);
+ PyMethod_Type.tp_dealloc = (destructor)method_dealloc;
+ PyMethod_Type.tp_vectorcall_offset = offsetof(PyMethodObject, vectorcall);
+ PyMethod_Type.tp_repr = (reprfunc)method_repr;
+ PyMethod_Type.tp_hash = (hashfunc)method_hash;
+ PyMethod_Type.tp_call = PyVectorcall_Call;
+ PyMethod_Type.tp_getattro = method_getattro;
+ PyMethod_Type.tp_setattro = PyObject_GenericSetAttr;
+ PyMethod_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
+ Py_TPFLAGS_HAVE_VECTORCALL;
+ PyMethod_Type.tp_doc = method_new__doc__;
+ PyMethod_Type.tp_traverse = (traverseproc)method_traverse;
+ PyMethod_Type.tp_richcompare = method_richcompare;
+ PyMethod_Type.tp_weaklistoffset = offsetof(PyMethodObject, im_weakreflist);
+ PyMethod_Type.tp_methods = method_methods;
+ PyMethod_Type.tp_members = method_memberlist;
+ PyMethod_Type.tp_getset = method_getset;
+ PyMethod_Type.tp_new = method_new;
+
+ PyInstanceMethod_Type.tp_name = "instancemethod";
+ PyInstanceMethod_Type.tp_basicsize = sizeof(PyInstanceMethodObject);
+ PyInstanceMethod_Type.tp_dealloc = instancemethod_dealloc;
+ PyInstanceMethod_Type.tp_repr = (reprfunc)instancemethod_repr;
+ PyInstanceMethod_Type.tp_call = instancemethod_call;
+ PyInstanceMethod_Type.tp_getattro = instancemethod_getattro;
+ PyInstanceMethod_Type.tp_setattro = PyObject_GenericSetAttr;
+ PyInstanceMethod_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC;
+ PyInstanceMethod_Type.tp_doc = instancemethod_new__doc__;
+ PyInstanceMethod_Type.tp_traverse = instancemethod_traverse;
+ PyInstanceMethod_Type.tp_richcompare = instancemethod_richcompare;
+ PyInstanceMethod_Type.tp_members = instancemethod_memberlist;
+ PyInstanceMethod_Type.tp_getset = instancemethod_getset;
+ PyInstanceMethod_Type.tp_descr_get = instancemethod_descr_get;
+ PyInstanceMethod_Type.tp_new = instancemethod_new;
+}
+#endif
diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h
index 0b5c01a..ab2bea8 100644
--- a/Objects/clinic/bytearrayobject.c.h
+++ b/Objects/clinic/bytearrayobject.c.h
@@ -14,6 +14,8 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs)
static _PyArg_Parser _parser = {NULL, _keywords, "bytearray", 0};
PyObject *argsbuf[3];
PyObject * const *fastargs;
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
PyObject *arg = NULL;
@@ -38,7 +40,6 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("bytearray", "argument 'encoding'", "str", fastargs[1]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -55,7 +56,6 @@ bytearray___init__(PyObject *self, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("bytearray", "argument 'errors'", "str", fastargs[2]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
if (errors == NULL) {
goto exit;
@@ -846,6 +846,8 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
static const char * const _keywords[] = {"encoding", "errors", NULL};
static _PyArg_Parser _parser = {NULL, _keywords, "decode", 0};
PyObject *argsbuf[2];
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
const char *encoding = NULL;
const char *errors = NULL;
@@ -862,7 +864,6 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
_PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -879,7 +880,6 @@ bytearray_decode(PyByteArrayObject *self, PyObject *const *args, Py_ssize_t narg
_PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
if (errors == NULL) {
goto exit;
diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h
index 7e85720..64c63bc 100644
--- a/Objects/clinic/bytesobject.c.h
+++ b/Objects/clinic/bytesobject.c.h
@@ -640,6 +640,8 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
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, 0, 2, 0, argsbuf);
if (!args) {
@@ -653,7 +655,6 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
_PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -670,7 +671,6 @@ bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObj
_PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
if (errors == NULL) {
goto exit;
@@ -845,6 +845,8 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
PyObject *x = NULL;
const char *encoding = NULL;
const char *errors = NULL;
+ Py_ssize_t encoding_length;
+ Py_ssize_t errors_length;
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
if (!fastargs) {
@@ -864,7 +866,6 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("bytes", "argument 'encoding'", "str", fastargs[1]);
goto exit;
}
- Py_ssize_t encoding_length;
encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
if (encoding == NULL) {
goto exit;
@@ -881,7 +882,6 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
_PyArg_BadArgument("bytes", "argument 'errors'", "str", fastargs[2]);
goto exit;
}
- Py_ssize_t errors_length;
errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
if (errors == NULL) {
goto exit;
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h
index bf0748f..cbf2851 100644
--- a/Objects/clinic/floatobject.c.h
+++ b/Objects/clinic/floatobject.c.h
@@ -270,12 +270,12 @@ float___getformat__(PyTypeObject *type, PyObject *arg)
{
PyObject *return_value = NULL;
const char *typestr;
+ Py_ssize_t typestr_length;
if (!PyUnicode_Check(arg)) {
_PyArg_BadArgument("__getformat__", "argument", "str", arg);
goto exit;
}
- Py_ssize_t typestr_length;
typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length);
if (typestr == NULL) {
goto exit;
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index c4a0d9a..bb481b2 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -54,7 +54,9 @@ intern_strings(PyObject *tuple)
static int
intern_string_constants(PyObject *tuple, int *modified)
{
- for (Py_ssize_t i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
+ Py_ssize_t i;
+
+ for (i = PyTuple_GET_SIZE(tuple); --i >= 0; ) {
PyObject *v = PyTuple_GET_ITEM(tuple, i);
if (PyUnicode_CheckExact(v)) {
if (PyUnicode_READY(v) == -1) {
@@ -80,10 +82,12 @@ intern_string_constants(PyObject *tuple, int *modified)
else if (PyFrozenSet_CheckExact(v)) {
PyObject *w = v;
PyObject *tmp = PySequence_Tuple(v);
+ int tmp_modified;
+
if (tmp == NULL) {
return -1;
}
- int tmp_modified = 0;
+ tmp_modified = 0;
if (intern_string_constants(tmp, &tmp_modified) < 0) {
Py_DECREF(tmp);
return -1;
@@ -174,7 +178,9 @@ get_localsplus_counts(PyObject *names, PyObject *kinds,
int ncellvars = 0;
int nfreevars = 0;
Py_ssize_t nlocalsplus = PyTuple_GET_SIZE(names);
- for (int i = 0; i < nlocalsplus; i++) {
+ int i;
+
+ for (i = 0; i < nlocalsplus; i++) {
_PyLocals_Kind kind = _PyLocals_GetKind(kinds, i);
if (kind & CO_FAST_LOCAL) {
nlocals += 1;
@@ -208,17 +214,22 @@ static PyObject *
get_localsplus_names(PyCodeObject *co, _PyLocals_Kind kind, int num)
{
PyObject *names = PyTuple_New(num);
+ int index;
+ int offset;
if (names == NULL) {
return NULL;
}
- int index = 0;
- for (int offset = 0; offset < co->co_nlocalsplus; offset++) {
- _PyLocals_Kind k = _PyLocals_GetKind(co->co_localspluskinds, offset);
+ index = 0;
+ for (offset = 0; offset < co->co_nlocalsplus; offset++) {
+ _PyLocals_Kind k;
+ PyObject *name;
+
+ k = _PyLocals_GetKind(co->co_localspluskinds, offset);
if ((k & kind) == 0) {
continue;
}
assert(index < num);
- PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, offset);
+ name = PyTuple_GET_ITEM(co->co_localsplusnames, offset);
Py_INCREF(name);
PyTuple_SET_ITEM(names, index, name);
index += 1;
@@ -230,6 +241,9 @@ get_localsplus_names(PyCodeObject *co, _PyLocals_Kind kind, int num)
int
_PyCode_Validate(struct _PyCodeConstructor *con)
{
+ int nlocals;
+ int nplainlocals;
+
/* Check argument types */
if (con->argcount < con->posonlyargcount || con->posonlyargcount < 0 ||
con->kwonlyargcount < 0 ||
@@ -269,10 +283,9 @@ _PyCode_Validate(struct _PyCodeConstructor *con)
/* Ensure that the co_varnames has enough names to cover the arg counts.
* Note that totalargs = nlocals - nplainlocals. We check nplainlocals
* here to avoid the possibility of overflow (however remote). */
- int nlocals;
get_localsplus_counts(con->localsplusnames, con->localspluskinds,
&nlocals, NULL, NULL, NULL);
- int nplainlocals = nlocals -
+ nplainlocals = nlocals -
con->argcount -
con->kwonlyargcount -
((con->flags & CO_VARARGS) != 0) -
@@ -290,6 +303,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
{
int nlocalsplus = (int)PyTuple_GET_SIZE(con->localsplusnames);
int nlocals, nplaincellvars, ncellvars, nfreevars;
+ int entry_point;
get_localsplus_counts(con->localsplusnames, con->localspluskinds,
&nlocals, &nplaincellvars, &ncellvars, &nfreevars);
@@ -341,7 +355,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
co->_co_linearray = NULL;
memcpy(_PyCode_CODE(co), PyBytes_AS_STRING(con->code),
PyBytes_GET_SIZE(con->code));
- int entry_point = 0;
+ entry_point = 0;
while (entry_point < Py_SIZE(co) &&
_Py_OPCODE(_PyCode_CODE(co)[entry_point]) != RESUME) {
entry_point++;
@@ -403,28 +417,33 @@ remove_column_info(PyObject *locations)
int offset = 0;
const uint8_t *data = (const uint8_t *)PyBytes_AS_STRING(locations);
PyObject *res = PyBytes_FromStringAndSize(NULL, 32);
+ uint8_t *output;
+ Py_ssize_t write_offset;
+
if (res == NULL) {
PyErr_NoMemory();
return NULL;
}
- uint8_t *output = (uint8_t *)PyBytes_AS_STRING(res);
+ output = (uint8_t *)PyBytes_AS_STRING(res);
while (offset < PyBytes_GET_SIZE(locations)) {
- Py_ssize_t write_offset = output - (uint8_t *)PyBytes_AS_STRING(res);
+ int code;
+ write_offset = output - (uint8_t *)PyBytes_AS_STRING(res);
if (write_offset + 16 >= PyBytes_GET_SIZE(res)) {
if (_PyBytes_Resize(&res, PyBytes_GET_SIZE(res) * 2) < 0) {
return NULL;
}
output = (uint8_t *)PyBytes_AS_STRING(res) + write_offset;
}
- int code = (data[offset] >> 3) & 15;
+ code = (data[offset] >> 3) & 15;
if (code == PY_CODE_LOCATION_INFO_NONE) {
*output++ = data[offset];
}
else {
+ int ldelta;
int blength = (data[offset] & 7)+1;
output += write_location_entry_start(
output, PY_CODE_LOCATION_INFO_NO_COLUMNS, blength);
- int ldelta = get_line_delta(&data[offset]);
+ ldelta = get_line_delta(&data[offset]);
output += write_signed_varint(output, ldelta);
}
offset++;
@@ -433,7 +452,7 @@ remove_column_info(PyObject *locations)
offset++;
}
}
- Py_ssize_t write_offset = output - (uint8_t *)PyBytes_AS_STRING(res);
+ write_offset = output - (uint8_t *)PyBytes_AS_STRING(res);
if (_PyBytes_Resize(&res, write_offset)) {
return NULL;
}
@@ -445,6 +464,10 @@ remove_column_info(PyObject *locations)
PyCodeObject *
_PyCode_New(struct _PyCodeConstructor *con)
{
+ PyObject *replacement_locations;
+ Py_ssize_t size;
+ PyCodeObject *co;
+
/* Ensure that strings are ready Unicode string */
if (PyUnicode_READY(con->name) < 0) {
return NULL;
@@ -466,7 +489,7 @@ _PyCode_New(struct _PyCodeConstructor *con)
return NULL;
}
- PyObject *replacement_locations = NULL;
+ replacement_locations = NULL;
// Compact the linetable if we are opted out of debug
// ranges.
if (!_Py_GetConfig()->code_debug_ranges) {
@@ -477,8 +500,8 @@ _PyCode_New(struct _PyCodeConstructor *con)
con->linetable = replacement_locations;
}
- Py_ssize_t size = PyBytes_GET_SIZE(con->code) / sizeof(_Py_CODEUNIT);
- PyCodeObject *co = PyObject_NewVar(PyCodeObject, &PyCode_Type, size);
+ size = PyBytes_GET_SIZE(con->code) / sizeof(_Py_CODEUNIT);
+ co = PyObject_NewVar(PyCodeObject, &PyCode_Type, size);
if (co == NULL) {
Py_XDECREF(replacement_locations);
PyErr_NoMemory();
@@ -507,6 +530,18 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
PyCodeObject *co = NULL;
PyObject *localsplusnames = NULL;
PyObject *localspluskinds = NULL;
+ int nvarnames;
+ int ncellvars;
+ int nfreevars;
+ int nlocalsplus;
+ int offset;
+ int i;
+ int j;
+ PyObject *local_name;
+ int argoffset;
+ int cmp;
+ _PyLocals_Kind kind;
+ struct _PyCodeConstructor con = {0};
if (varnames == NULL || !PyTuple_Check(varnames) ||
cellvars == NULL || !PyTuple_Check(cellvars) ||
@@ -517,10 +552,10 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
}
// Set the "fast locals plus" info.
- int nvarnames = (int)PyTuple_GET_SIZE(varnames);
- int ncellvars = (int)PyTuple_GET_SIZE(cellvars);
- int nfreevars = (int)PyTuple_GET_SIZE(freevars);
- int nlocalsplus = nvarnames + ncellvars + nfreevars;
+ nvarnames = (int)PyTuple_GET_SIZE(varnames);
+ ncellvars = (int)PyTuple_GET_SIZE(cellvars);
+ nfreevars = (int)PyTuple_GET_SIZE(freevars);
+ nlocalsplus = nvarnames + ncellvars + nfreevars;
localsplusnames = PyTuple_New(nlocalsplus);
if (localsplusnames == NULL) {
goto error;
@@ -529,18 +564,18 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
if (localspluskinds == NULL) {
goto error;
}
- int offset = 0;
- for (int i = 0; i < nvarnames; i++, offset++) {
- PyObject *name = PyTuple_GET_ITEM(varnames, i);
- _Py_set_localsplus_info(offset, name, CO_FAST_LOCAL,
+ offset = 0;
+ for (i = 0; i < nvarnames; i++, offset++) {
+ local_name = PyTuple_GET_ITEM(varnames, i);
+ _Py_set_localsplus_info(offset, local_name, CO_FAST_LOCAL,
localsplusnames, localspluskinds);
}
- for (int i = 0; i < ncellvars; i++, offset++) {
- PyObject *name = PyTuple_GET_ITEM(cellvars, i);
- int argoffset = -1;
- for (int j = 0; j < nvarnames; j++) {
- int cmp = PyUnicode_Compare(PyTuple_GET_ITEM(varnames, j),
- name);
+ for (i = 0; i < ncellvars; i++, offset++) {
+ local_name = PyTuple_GET_ITEM(cellvars, i);
+ argoffset = -1;
+ for (j = 0; j < nvarnames; j++) {
+ cmp = PyUnicode_Compare(PyTuple_GET_ITEM(varnames, j),
+ local_name);
assert(!PyErr_Occurred());
if (cmp == 0) {
argoffset = j;
@@ -551,16 +586,16 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
// Merge the localsplus indices.
nlocalsplus -= 1;
offset -= 1;
- _PyLocals_Kind kind = _PyLocals_GetKind(localspluskinds, argoffset);
+ kind = _PyLocals_GetKind(localspluskinds, argoffset);
_PyLocals_SetKind(localspluskinds, argoffset, kind | CO_FAST_CELL);
continue;
}
- _Py_set_localsplus_info(offset, name, CO_FAST_CELL,
+ _Py_set_localsplus_info(offset, local_name, CO_FAST_CELL,
localsplusnames, localspluskinds);
}
- for (int i = 0; i < nfreevars; i++, offset++) {
- PyObject *name = PyTuple_GET_ITEM(freevars, i);
- _Py_set_localsplus_info(offset, name, CO_FAST_FREE,
+ for (i = 0; i < nfreevars; i++, offset++) {
+ local_name = PyTuple_GET_ITEM(freevars, i);
+ _Py_set_localsplus_info(offset, local_name, CO_FAST_FREE,
localsplusnames, localspluskinds);
}
// If any cells were args then nlocalsplus will have shrunk.
@@ -571,30 +606,22 @@ PyCode_NewWithPosOnlyArgs(int argcount, int posonlyargcount, int kwonlyargcount,
}
}
- struct _PyCodeConstructor con = {
- .filename = filename,
- .name = name,
- .qualname = qualname,
- .flags = flags,
-
- .code = code,
- .firstlineno = firstlineno,
- .linetable = linetable,
-
- .consts = consts,
- .names = names,
-
- .localsplusnames = localsplusnames,
- .localspluskinds = localspluskinds,
-
- .argcount = argcount,
- .posonlyargcount = posonlyargcount,
- .kwonlyargcount = kwonlyargcount,
-
- .stacksize = stacksize,
-
- .exceptiontable = exceptiontable,
- };
+ con.filename = filename;
+ con.name = name;
+ con.qualname = qualname;
+ con.flags = flags;
+ con.code = code;
+ con.firstlineno = firstlineno;
+ con.linetable = linetable;
+ con.consts = consts;
+ con.names = names;
+ con.localsplusnames = localsplusnames;
+ con.localspluskinds = localspluskinds;
+ con.argcount = argcount;
+ con.posonlyargcount = posonlyargcount;
+ con.kwonlyargcount = kwonlyargcount;
+ con.stacksize = stacksize;
+ con.exceptiontable = exceptiontable;
if (_PyCode_Validate(&con) < 0) {
goto error;
@@ -661,6 +688,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
PyObject *code_ob = NULL;
PyObject *linetable_ob = NULL;
PyCodeObject *result = NULL;
+ struct _PyCodeConstructor con = {0};
nulltuple = PyTuple_New(0);
if (nulltuple == NULL) {
@@ -684,20 +712,18 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
}
#define emptystring (PyObject *)&_Py_SINGLETON(bytes_empty)
- struct _PyCodeConstructor con = {
- .filename = filename_ob,
- .name = funcname_ob,
- .qualname = funcname_ob,
- .code = code_ob,
- .firstlineno = firstlineno,
- .linetable = linetable_ob,
- .consts = nulltuple,
- .names = nulltuple,
- .localsplusnames = nulltuple,
- .localspluskinds = emptystring,
- .exceptiontable = emptystring,
- .stacksize = 1,
- };
+ con.filename = filename_ob;
+ con.name = funcname_ob;
+ con.qualname = funcname_ob;
+ con.code = code_ob;
+ con.firstlineno = firstlineno;
+ con.linetable = linetable_ob;
+ con.consts = nulltuple;
+ con.names = nulltuple;
+ con.localsplusnames = nulltuple;
+ con.localspluskinds = emptystring;
+ con.exceptiontable = emptystring;
+ con.stacksize = 1;
result = _PyCode_New(&con);
failed:
@@ -721,10 +747,12 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
int
_PyCode_CreateLineArray(PyCodeObject *co)
{
- assert(co->_co_linearray == NULL);
PyCodeAddressRange bounds;
int size;
- int max_line = 0;
+ int max_line;
+
+ assert(co->_co_linearray == NULL);
+ max_line = 0;
_PyCode_InitAddressRange(co, &bounds);
while(_PyLineTable_NextAddressRange(&bounds)) {
if (bounds.ar_line > max_line) {
@@ -747,7 +775,8 @@ _PyCode_CreateLineArray(PyCodeObject *co)
while(_PyLineTable_NextAddressRange(&bounds)) {
int start = bounds.ar_start / sizeof(_Py_CODEUNIT);
int end = bounds.ar_end / sizeof(_Py_CODEUNIT);
- for (int index = start; index < end; index++) {
+ int index;
+ for (index = start; index < end; index++) {
assert(index < (int)Py_SIZE(co));
if (size == 2) {
assert(((int16_t)bounds.ar_line) == bounds.ar_line);
@@ -765,6 +794,8 @@ _PyCode_CreateLineArray(PyCodeObject *co)
int
PyCode_Addr2Line(PyCodeObject *co, int addrq)
{
+ PyCodeAddressRange bounds;
+
if (addrq < 0) {
return co->co_firstlineno;
}
@@ -772,7 +803,6 @@ PyCode_Addr2Line(PyCodeObject *co, int addrq)
if (co->_co_linearray) {
return _PyCode_LineNumberFromArray(co, addrq / sizeof(_Py_CODEUNIT));
}
- PyCodeAddressRange bounds;
_PyCode_InitAddressRange(co, &bounds);
return _PyCode_CheckLineNumber(addrq, &bounds);
}
@@ -791,9 +821,12 @@ _PyLineTable_InitAddressRange(const char *linetable, Py_ssize_t length, int firs
int
_PyCode_InitAddressRange(PyCodeObject* co, PyCodeAddressRange *bounds)
{
+ const char *linetable;
+ Py_ssize_t length;
+
assert(co->co_linetable != NULL);
- const char *linetable = PyBytes_AS_STRING(co->co_linetable);
- Py_ssize_t length = PyBytes_GET_SIZE(co->co_linetable);
+ linetable = PyBytes_AS_STRING(co->co_linetable);
+ length = PyBytes_GET_SIZE(co->co_linetable);
_PyLineTable_InitAddressRange(linetable, length, co->co_firstlineno, bounds);
return bounds->ar_line;
}
@@ -839,12 +872,13 @@ next_code_delta(PyCodeAddressRange *bounds)
static int
previous_code_delta(PyCodeAddressRange *bounds)
{
+ const uint8_t *ptr;
if (bounds->ar_start == 0) {
// If we looking at the first entry, the
// "previous" entry has an implicit length of 1.
return 1;
}
- const uint8_t *ptr = bounds->opaque.lo_next-1;
+ ptr = bounds->opaque.lo_next-1;
while (((*ptr) & 128) == 0) {
ptr--;
}
@@ -926,9 +960,12 @@ advance(PyCodeAddressRange *bounds)
static void
advance_with_locations(PyCodeAddressRange *bounds, int *endline, int *column, int *endcolumn)
{
+ int first_byte;
+ int code;
+
ASSERT_VALID_BOUNDS(bounds);
- int first_byte = read_byte(bounds);
- int code = (first_byte >> 3) & 15;
+ first_byte = read_byte(bounds);
+ code = (first_byte >> 3) & 15;
bounds->ar_start = bounds->ar_end;
bounds->ar_end = bounds->ar_start + ((first_byte & 7) + 1) * sizeof(_Py_CODEUNIT);
switch(code) {
@@ -982,13 +1019,13 @@ PyCode_Addr2Location(PyCodeObject *co, int addrq,
int *start_line, int *start_column,
int *end_line, int *end_column)
{
+ PyCodeAddressRange bounds;
if (addrq < 0) {
*start_line = *end_line = co->co_firstlineno;
*start_column = *end_column = 0;
return 1;
}
assert(addrq >= 0 && addrq < _PyCode_NBYTES(co));
- PyCodeAddressRange bounds;
_PyCode_InitAddressRange(co, &bounds);
_PyCode_CheckLineNumber(addrq, &bounds);
retreat(&bounds);
@@ -1028,14 +1065,17 @@ _PyLineTable_NextAddressRange(PyCodeAddressRange *range)
int
_PyLineTable_StartsLine(PyCodeAddressRange *range)
{
+ const uint8_t *ptr;
+ int code;
+
if (range->ar_start <= 0) {
return 0;
}
- const uint8_t *ptr = range->opaque.lo_next;
+ ptr = range->opaque.lo_next;
do {
ptr--;
} while (((*ptr) & 128) == 0);
- int code = ((*ptr)>> 3) & 15;
+ code = ((*ptr)>> 3) & 15;
switch(code) {
case PY_CODE_LOCATION_INFO_LONG:
return 0;
@@ -1055,12 +1095,13 @@ _PyLineTable_StartsLine(PyCodeAddressRange *range)
static int
emit_pair(PyObject **bytes, int *offset, int a, int b)
{
+ unsigned char *lnotab;
Py_ssize_t len = PyBytes_GET_SIZE(*bytes);
if (*offset + 2 >= len) {
if (_PyBytes_Resize(bytes, len * 2) < 0)
return 0;
}
- unsigned char *lnotab = (unsigned char *) PyBytes_AS_STRING(*bytes);
+ lnotab = (unsigned char *) PyBytes_AS_STRING(*bytes);
lnotab += *offset;
*lnotab++ = a;
*lnotab++ = b;
@@ -1142,13 +1183,18 @@ static PyObject *
lineiter_next(lineiterator *li)
{
PyCodeAddressRange *bounds = &li->li_line;
+ PyObject *start;
+ PyObject *end;
+ PyObject *line;
+ PyObject *result;
+
if (!_PyLineTable_NextAddressRange(bounds)) {
return NULL;
}
- PyObject *start = NULL;
- PyObject *end = NULL;
- PyObject *line = NULL;
- PyObject *result = PyTuple_New(3);
+ start = NULL;
+ end = NULL;
+ line = NULL;
+ result = PyTuple_New(3);
start = PyLong_FromLong(bounds->ar_start);
end = PyLong_FromLong(bounds->ar_end);
if (bounds->ar_line < 0) {
@@ -1345,13 +1391,16 @@ typedef struct {
int
_PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
{
+ PyCodeObject *o;
+ _PyCodeObjectExtra *co_extra;
+
if (!PyCode_Check(code)) {
PyErr_BadInternalCall();
return -1;
}
- PyCodeObject *o = (PyCodeObject*) code;
- _PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra*) o->co_extra;
+ o = (PyCodeObject*) code;
+ co_extra = (_PyCodeObjectExtra*) o->co_extra;
if (co_extra == NULL || index < 0 || co_extra->ce_size <= index) {
*extra = NULL;
@@ -1367,6 +1416,10 @@ int
_PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
{
PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyCodeObject *o;
+ _PyCodeObjectExtra *co_extra;
+ Py_ssize_t i;
+ freefunc free;
if (!PyCode_Check(code) || index < 0 ||
index >= interp->co_extra_user_count) {
@@ -1374,11 +1427,11 @@ _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
return -1;
}
- PyCodeObject *o = (PyCodeObject*) code;
- _PyCodeObjectExtra *co_extra = (_PyCodeObjectExtra *) o->co_extra;
+ o = (PyCodeObject*) code;
+ co_extra = (_PyCodeObjectExtra *) o->co_extra;
if (co_extra == NULL || co_extra->ce_size <= index) {
- Py_ssize_t i = (co_extra == NULL ? 0 : co_extra->ce_size);
+ i = (co_extra == NULL ? 0 : co_extra->ce_size);
co_extra = PyMem_Realloc(
co_extra,
sizeof(_PyCodeObjectExtra) +
@@ -1394,7 +1447,7 @@ _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
}
if (co_extra->ce_extras[index] != NULL) {
- freefunc free = interp->co_extra_freefuncs[index];
+ free = interp->co_extra_freefuncs[index];
if (free != NULL) {
free(co_extra->ce_extras[index]);
}
@@ -1448,7 +1501,9 @@ PyCode_GetFreevars(PyCodeObject *code)
static void
deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len)
{
- for (int i = 0; i < len; i++) {
+ int i;
+
+ for (i = 0; i < len; i++) {
_Py_CODEUNIT instruction = instructions[i];
int opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)];
int caches = _PyOpcode_Caches[opcode];
@@ -1462,10 +1517,12 @@ deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len)
PyObject *
_PyCode_GetCode(PyCodeObject *co)
{
+ PyObject *code;
+
if (co->_co_code != NULL) {
return Py_NewRef(co->_co_code);
}
- PyObject *code = PyBytes_FromStringAndSize((const char *)_PyCode_CODE(co),
+ code = PyBytes_FromStringAndSize((const char *)_PyCode_CODE(co),
_PyCode_NBYTES(co));
if (code == NULL) {
return NULL;
@@ -1610,8 +1667,9 @@ code_dealloc(PyCodeObject *co)
if (co->co_extra != NULL) {
PyInterpreterState *interp = _PyInterpreterState_GET();
_PyCodeObjectExtra *co_extra = co->co_extra;
+ Py_ssize_t i;
- for (Py_ssize_t i = 0; i < co_extra->ce_size; i++) {
+ for (i = 0; i < co_extra->ce_size; i++) {
freefunc free_extra = interp->co_extra_freefuncs[i];
if (free_extra != NULL) {
@@ -1670,6 +1728,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
int eq;
PyObject *consts1, *consts2;
PyObject *res;
+ int i;
if ((op != Py_EQ && op != Py_NE) ||
!PyCode_Check(self) ||
@@ -1696,7 +1755,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
if (!eq) {
goto unequal;
}
- for (int i = 0; i < Py_SIZE(co); i++) {
+ for (i = 0; i < Py_SIZE(co); i++) {
_Py_CODEUNIT co_instr = _PyCode_CODE(co)[i];
_Py_CODEUNIT cp_instr = _PyCode_CODE(cp)[i];
_Py_SET_OPCODE(co_instr, _PyOpcode_Deopt[_Py_OPCODE(co_instr)]);
@@ -1760,6 +1819,7 @@ static Py_hash_t
code_hash(PyCodeObject *co)
{
Py_hash_t h, h0, h1, h2, h3;
+ Py_hash_t h4, h5;
h0 = PyObject_Hash(co->co_name);
if (h0 == -1) return -1;
h1 = PyObject_Hash(co->co_consts);
@@ -1768,11 +1828,11 @@ code_hash(PyCodeObject *co)
if (h2 == -1) return -1;
h3 = PyObject_Hash(co->co_localsplusnames);
if (h3 == -1) return -1;
- Py_hash_t h4 = PyObject_Hash(co->co_linetable);
+ h4 = PyObject_Hash(co->co_linetable);
if (h4 == -1) {
return -1;
}
- Py_hash_t h5 = PyObject_Hash(co->co_exceptiontable);
+ h5 = PyObject_Hash(co->co_exceptiontable);
if (h5 == -1) {
return -1;
}
@@ -1913,6 +1973,12 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
PyObject *co_exceptiontable)
/*[clinic end generated code: output=e75c48a15def18b9 input=18e280e07846c122]*/
{
+ PyObject *code;
+ PyCodeObject *co;
+ PyObject *varnames;
+ PyObject *cellvars;
+ PyObject *freevars;
+
#define CHECK_INT_ARG(ARG) \
if (ARG < 0) { \
PyErr_SetString(PyExc_ValueError, \
@@ -1930,7 +1996,7 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
#undef CHECK_INT_ARG
- PyObject *code = NULL;
+ code = NULL;
if (co_code == NULL) {
code = _PyCode_GetCode(self);
if (code == NULL) {
@@ -1947,10 +2013,10 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
return NULL;
}
- PyCodeObject *co = NULL;
- PyObject *varnames = NULL;
- PyObject *cellvars = NULL;
- PyObject *freevars = NULL;
+ co = NULL;
+ varnames = NULL;
+ cellvars = NULL;
+ freevars = NULL;
if (co_varnames == NULL) {
varnames = get_localsplus_names(self, CO_FAST_LOCAL, self->co_nlocals);
if (varnames == NULL) {
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 8369fed..227bd60 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -106,6 +106,8 @@ descr_check(PyDescrObject *descr, PyObject *obj)
static PyObject *
classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
{
+ PyTypeObject *cls;
+
/* Ensure a valid type. Class methods ignore obj. */
if (type == NULL) {
if (obj != NULL)
@@ -138,7 +140,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
((PyTypeObject *)type)->tp_name);
return NULL;
}
- PyTypeObject *cls = NULL;
+ cls = NULL;
if (descr->d_method->ml_flags & METH_METHOD) {
cls = descr->d_common.d_type;
}
@@ -271,9 +273,12 @@ getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
static inline int
method_check_args(PyObject *func, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
+ PyObject *self;
+ PyObject *funcstr;
+
assert(!PyErr_Occurred());
if (nargs < 1) {
- PyObject *funcstr = _PyObject_FunctionStr(func);
+ funcstr = _PyObject_FunctionStr(func);
if (funcstr != NULL) {
PyErr_Format(PyExc_TypeError,
"unbound method %U needs an argument", funcstr);
@@ -281,12 +286,12 @@ method_check_args(PyObject *func, PyObject *const *args, Py_ssize_t nargs, PyObj
}
return -1;
}
- PyObject *self = args[0];
+ self = args[0];
if (descr_check((PyDescrObject *)func, self) < 0) {
return -1;
}
if (kwnames && PyTuple_GET_SIZE(kwnames)) {
- PyObject *funcstr = _PyObject_FunctionStr(func);
+ funcstr = _PyObject_FunctionStr(func);
if (funcstr != NULL) {
PyErr_Format(PyExc_TypeError,
"%U takes no keyword arguments", funcstr);
@@ -315,19 +320,22 @@ method_vectorcall_VARARGS(
{
PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ PyObject *argstuple;
+ PyCFunction meth;
+ PyObject *result;
if (method_check_args(func, args, nargs, kwnames)) {
return NULL;
}
- PyObject *argstuple = _PyTuple_FromArray(args+1, nargs-1);
+ argstuple = _PyTuple_FromArray(args+1, nargs-1);
if (argstuple == NULL) {
return NULL;
}
- PyCFunction meth = (PyCFunction)method_enter_call(tstate, func);
+ meth = (PyCFunction)method_enter_call(tstate, func);
if (meth == NULL) {
Py_DECREF(argstuple);
return NULL;
}
- PyObject *result = _PyCFunction_TrampolineCall(
+ result = _PyCFunction_TrampolineCall(
meth, args[0], argstuple);
Py_DECREF(argstuple);
_Py_LeaveRecursiveCallTstate(tstate);
@@ -340,23 +348,27 @@ method_vectorcall_VARARGS_KEYWORDS(
{
PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ PyObject *argstuple;
+ PyObject *result;
+ PyObject *kwdict;
+ PyCFunctionWithKeywords meth;
if (method_check_args(func, args, nargs, NULL)) {
return NULL;
}
- PyObject *argstuple = _PyTuple_FromArray(args+1, nargs-1);
+ argstuple = _PyTuple_FromArray(args+1, nargs-1);
if (argstuple == NULL) {
return NULL;
}
- PyObject *result = NULL;
+ result = NULL;
/* Create a temporary dict for keyword arguments */
- PyObject *kwdict = NULL;
+ kwdict = NULL;
if (kwnames != NULL && PyTuple_GET_SIZE(kwnames) > 0) {
kwdict = _PyStack_AsDict(args + nargs, kwnames);
if (kwdict == NULL) {
goto exit;
}
}
- PyCFunctionWithKeywords meth = (PyCFunctionWithKeywords)
+ meth = (PyCFunctionWithKeywords)
method_enter_call(tstate, func);
if (meth == NULL) {
goto exit;
@@ -376,14 +388,16 @@ method_vectorcall_FASTCALL_KEYWORDS_METHOD(
{
PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ PyCMethod meth;
+ PyObject *result;
if (method_check_args(func, args, nargs, NULL)) {
return NULL;
}
- PyCMethod meth = (PyCMethod) method_enter_call(tstate, func);
+ meth = (PyCMethod) method_enter_call(tstate, func);
if (meth == NULL) {
return NULL;
}
- PyObject *result = meth(args[0],
+ result = meth(args[0],
((PyMethodDescrObject *)func)->d_common.d_type,
args+1, nargs-1, kwnames);
_Py_LeaveRecursiveCall();
@@ -396,15 +410,17 @@ method_vectorcall_FASTCALL(
{
PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ _PyCFunctionFast meth;
+ PyObject *result;
if (method_check_args(func, args, nargs, kwnames)) {
return NULL;
}
- _PyCFunctionFast meth = (_PyCFunctionFast)
+ meth = (_PyCFunctionFast)
method_enter_call(tstate, func);
if (meth == NULL) {
return NULL;
}
- PyObject *result = meth(args[0], args+1, nargs-1);
+ result = meth(args[0], args+1, nargs-1);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@@ -415,15 +431,17 @@ method_vectorcall_FASTCALL_KEYWORDS(
{
PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ _PyCFunctionFastWithKeywords meth;
+ PyObject *result;
if (method_check_args(func, args, nargs, NULL)) {
return NULL;
}
- _PyCFunctionFastWithKeywords meth = (_PyCFunctionFastWithKeywords)
+ meth = (_PyCFunctionFastWithKeywords)
method_enter_call(tstate, func);
if (meth == NULL) {
return NULL;
}
- PyObject *result = meth(args[0], args+1, nargs-1, kwnames);
+ result = meth(args[0], args+1, nargs-1, kwnames);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@@ -434,11 +452,14 @@ method_vectorcall_NOARGS(
{
PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ PyObject *funcstr;
+ PyCFunction meth;
+ PyObject *result;
if (method_check_args(func, args, nargs, kwnames)) {
return NULL;
}
if (nargs != 1) {
- PyObject *funcstr = _PyObject_FunctionStr(func);
+ funcstr = _PyObject_FunctionStr(func);
if (funcstr != NULL) {
PyErr_Format(PyExc_TypeError,
"%U takes no arguments (%zd given)", funcstr, nargs-1);
@@ -446,11 +467,11 @@ method_vectorcall_NOARGS(
}
return NULL;
}
- PyCFunction meth = (PyCFunction)method_enter_call(tstate, func);
+ meth = (PyCFunction)method_enter_call(tstate, func);
if (meth == NULL) {
return NULL;
}
- PyObject *result = _PyCFunction_TrampolineCall(meth, args[0], NULL);
+ result = _PyCFunction_TrampolineCall(meth, args[0], NULL);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@@ -461,11 +482,14 @@ method_vectorcall_O(
{
PyThreadState *tstate = _PyThreadState_GET();
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ PyObject *funcstr;
+ PyCFunction meth;
+ PyObject *result;
if (method_check_args(func, args, nargs, kwnames)) {
return NULL;
}
if (nargs != 2) {
- PyObject *funcstr = _PyObject_FunctionStr(func);
+ funcstr = _PyObject_FunctionStr(func);
if (funcstr != NULL) {
PyErr_Format(PyExc_TypeError,
"%U takes exactly one argument (%zd given)",
@@ -474,11 +498,11 @@ method_vectorcall_O(
}
return NULL;
}
- PyCFunction meth = (PyCFunction)method_enter_call(tstate, func);
+ meth = (PyCFunction)method_enter_call(tstate, func);
if (meth == NULL) {
return NULL;
}
- PyObject *result = _PyCFunction_TrampolineCall(meth, args[0], args[1]);
+ result = _PyCFunction_TrampolineCall(meth, args[0], args[1]);
_Py_LeaveRecursiveCallTstate(tstate);
return result;
}
@@ -496,7 +520,12 @@ static PyObject *
classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
PyObject *kwds)
{
- Py_ssize_t argc = PyTuple_GET_SIZE(args);
+ Py_ssize_t argc;
+ PyObject *self;
+ PyObject *bound;
+ PyObject *res;
+
+ argc = PyTuple_GET_SIZE(args);
if (argc < 1) {
PyErr_Format(PyExc_TypeError,
"descriptor '%V' of '%.100s' "
@@ -505,12 +534,12 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
PyDescr_TYPE(descr)->tp_name);
return NULL;
}
- PyObject *self = PyTuple_GET_ITEM(args, 0);
- PyObject *bound = classmethod_get(descr, NULL, self);
+ self = PyTuple_GET_ITEM(args, 0);
+ bound = classmethod_get(descr, NULL, self);
if (bound == NULL) {
return NULL;
}
- PyObject *res = PyObject_VectorcallDict(bound, _PyTuple_ITEMS(args)+1,
+ res = PyObject_VectorcallDict(bound, _PyTuple_ITEMS(args)+1,
argc-1, kwds);
Py_DECREF(bound);
return res;
@@ -920,6 +949,7 @@ descr_new(PyTypeObject *descrtype, PyTypeObject *type, const char *name)
PyObject *
PyDescr_NewMethod(PyTypeObject *type, PyMethodDef *method)
{
+ PyMethodDescrObject *descr;
/* Figure out correct vectorcall function to use */
vectorcallfunc vectorcall;
switch (method->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS |
@@ -952,8 +982,6 @@ PyDescr_NewMethod(PyTypeObject *type, PyMethodDef *method)
return NULL;
}
- PyMethodDescrObject *descr;
-
descr = (PyMethodDescrObject *)descr_new(&PyMethodDescr_Type,
type, method->ml_name);
if (descr != NULL) {
@@ -1066,10 +1094,21 @@ mappingproxy_ior(PyObject *self, PyObject *Py_UNUSED(other))
"'|=' is not supported by %s; use '|' instead", Py_TYPE(self)->tp_name);
}
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
static PyNumberMethods mappingproxy_as_number = {
.nb_or = mappingproxy_or,
.nb_inplace_or = mappingproxy_ior,
};
+#else
+static PyNumberMethods mappingproxy_as_number = {0};
+
+void
+_PyDesc_InitTypes(void)
+{
+ mappingproxy_as_number.nb_or = mappingproxy_or;
+ mappingproxy_as_number.nb_inplace_or = mappingproxy_ior;
+}
+#endif
static int
mappingproxy_contains(mappingproxyobject *pp, PyObject *key)
@@ -1558,6 +1597,9 @@ PyDoc_STRVAR(set_name_doc,
static PyObject *
property_set_name(PyObject *self, PyObject *args) {
+ propertyobject *prop;
+ PyObject *name;
+
if (PyTuple_GET_SIZE(args) != 2) {
PyErr_Format(
PyExc_TypeError,
@@ -1566,8 +1608,8 @@ property_set_name(PyObject *self, PyObject *args) {
return NULL;
}
- propertyobject *prop = (propertyobject *)self;
- PyObject *name = PyTuple_GET_ITEM(args, 1);
+ prop = (propertyobject *)self;
+ name = PyTuple_GET_ITEM(args, 1);
Py_XINCREF(name);
Py_XSETREF(prop->prop_name, name);
@@ -1601,12 +1643,14 @@ property_dealloc(PyObject *self)
static PyObject *
property_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
+ propertyobject *gs;
+
if (obj == NULL || obj == Py_None) {
Py_INCREF(self);
return self;
}
- propertyobject *gs = (propertyobject *)self;
+ gs = (propertyobject *)self;
if (gs->prop_get == NULL) {
PyObject *qualname = PyType_GetQualName(Py_TYPE(obj));
if (gs->prop_name != NULL && qualname != NULL) {
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 0e9c6d2..c1ed9d8 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -504,16 +504,31 @@ dump_entries(PyDictKeysObject *dk)
int
_PyDict_CheckConsistency(PyObject *op, int check_content)
{
+ PyDictObject *mp;
+ PyDictKeysObject *keys;
+ int splitted;
+ Py_ssize_t usable;
+ Py_ssize_t i;
+ Py_ssize_t ix;
+ PyDictKeyEntry *key_entries;
+ PyDictKeyEntry *dict_entry;
+ PyDictUnicodeEntry *unicode_entries;
+ PyDictUnicodeEntry *unicode_entry;
+ PyObject *key;
+ Py_hash_t hash;
+ int duplicate_check;
+ int index;
+
#define CHECK(expr) \
do { if (!(expr)) { _PyObject_ASSERT_FAILED_MSG(op, Py_STRINGIFY(expr)); } } while (0)
assert(op != NULL);
CHECK(PyDict_Check(op));
- PyDictObject *mp = (PyDictObject *)op;
+ mp = (PyDictObject *)op;
- PyDictKeysObject *keys = mp->ma_keys;
- int splitted = _PyDict_HasSplitTable(mp);
- Py_ssize_t usable = USABLE_FRACTION(DK_SIZE(keys));
+ keys = mp->ma_keys;
+ splitted = _PyDict_HasSplitTable(mp);
+ usable = USABLE_FRACTION(DK_SIZE(keys));
CHECK(0 <= mp->ma_used && mp->ma_used <= usable);
CHECK(0 <= keys->dk_usable && keys->dk_usable <= usable);
@@ -531,46 +546,46 @@ _PyDict_CheckConsistency(PyObject *op, int check_content)
}
if (check_content) {
- for (Py_ssize_t i=0; i < DK_SIZE(keys); i++) {
- Py_ssize_t ix = dictkeys_get_index(keys, i);
+ for (i=0; i < DK_SIZE(keys); i++) {
+ ix = dictkeys_get_index(keys, i);
CHECK(DKIX_DUMMY <= ix && ix <= usable);
}
if (keys->dk_kind == DICT_KEYS_GENERAL) {
- PyDictKeyEntry *entries = DK_ENTRIES(keys);
- for (Py_ssize_t i=0; i < usable; i++) {
- PyDictKeyEntry *entry = &entries[i];
- PyObject *key = entry->me_key;
+ key_entries = DK_ENTRIES(keys);
+ for (i=0; i < usable; i++) {
+ dict_entry = &key_entries[i];
+ key = dict_entry->me_key;
if (key != NULL) {
/* test_dict fails if PyObject_Hash() is called again */
- CHECK(entry->me_hash != -1);
- CHECK(entry->me_value != NULL);
+ CHECK(dict_entry->me_hash != -1);
+ CHECK(dict_entry->me_value != NULL);
if (PyUnicode_CheckExact(key)) {
- Py_hash_t hash = unicode_get_hash(key);
- CHECK(entry->me_hash == hash);
+ hash = unicode_get_hash(key);
+ CHECK(dict_entry->me_hash == hash);
}
}
}
}
else {
- PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
- for (Py_ssize_t i=0; i < usable; i++) {
- PyDictUnicodeEntry *entry = &entries[i];
- PyObject *key = entry->me_key;
+ unicode_entries = DK_UNICODE_ENTRIES(keys);
+ for (i=0; i < usable; i++) {
+ unicode_entry = &unicode_entries[i];
+ key = unicode_entry->me_key;
if (key != NULL) {
CHECK(PyUnicode_CheckExact(key));
- Py_hash_t hash = unicode_get_hash(key);
+ hash = unicode_get_hash(key);
CHECK(hash != -1);
if (!splitted) {
- CHECK(entry->me_value != NULL);
+ CHECK(unicode_entry->me_value != NULL);
}
}
if (splitted) {
- CHECK(entry->me_value == NULL);
+ CHECK(unicode_entry->me_value == NULL);
}
}
}
@@ -578,9 +593,9 @@ _PyDict_CheckConsistency(PyObject *op, int check_content)
if (splitted) {
CHECK(mp->ma_used <= SHARED_KEYS_MAX_SIZE);
/* splitted table */
- int duplicate_check = 0;
- for (Py_ssize_t i=0; i < mp->ma_used; i++) {
- int index = get_index_from_order(mp, i);
+ duplicate_check = 0;
+ for (i=0; i < mp->ma_used; i++) {
+ index = get_index_from_order(mp, i);
CHECK((duplicate_check & (1<<index)) == 0);
duplicate_check |= (1<<index);
CHECK(mp->ma_values->values[index] != NULL);
@@ -600,6 +615,9 @@ new_keys_object(uint8_t log2_size, bool unicode)
Py_ssize_t usable;
int log2_bytes;
size_t entry_size = unicode ? sizeof(PyDictUnicodeEntry) : sizeof(PyDictKeyEntry);
+#if PyDict_MAXFREELIST > 0
+ struct _Py_dict_state *state;
+#endif
assert(log2_size >= PyDict_LOG_MINSIZE);
@@ -620,7 +638,7 @@ new_keys_object(uint8_t log2_size, bool unicode)
}
#if PyDict_MAXFREELIST > 0
- struct _Py_dict_state *state = get_dict_state();
+ state = get_dict_state();
#ifdef Py_DEBUG
// new_keys_object() must not be called after _PyDict_Fini()
assert(state->keys_numfree != -1);
@@ -658,25 +676,30 @@ new_keys_object(uint8_t log2_size, bool unicode)
static void
free_keys_object(PyDictKeysObject *keys)
{
+ PyDictUnicodeEntry *unicode_entries;
+ PyDictKeyEntry *key_entries;
+ Py_ssize_t i, n;
+#if PyDict_MAXFREELIST > 0
+ struct _Py_dict_state *state;
+#endif
+
assert(keys != Py_EMPTY_KEYS);
if (DK_IS_UNICODE(keys)) {
- PyDictUnicodeEntry *entries = DK_UNICODE_ENTRIES(keys);
- Py_ssize_t i, n;
+ unicode_entries = DK_UNICODE_ENTRIES(keys);
for (i = 0, n = keys->dk_nentries; i < n; i++) {
- Py_XDECREF(entries[i].me_key);
- Py_XDECREF(entries[i].me_value);
+ Py_XDECREF(unicode_entries[i].me_key);
+ Py_XDECREF(unicode_entries[i].me_value);
}
}
else {
- PyDictKeyEntry *entries = DK_ENTRIES(keys);
- Py_ssize_t i, n;
+ key_entries = DK_ENTRIES(keys);
for (i = 0, n = keys->dk_nentries; i < n; i++) {
- Py_XDECREF(entries[i].me_key);
- Py_XDECREF(entries[i].me_value);
+ Py_XDECREF(key_entries[i].me_key);
+ Py_XDECREF(key_entries[i].me_value);
}
}
#if PyDict_MAXFREELIST > 0
- struct _Py_dict_state *state = get_dict_state();
+ state = get_dict_state();
#ifdef Py_DEBUG
// free_keys_object() must not be called after _PyDict_Fini()
assert(state->keys_numfree != -1);
@@ -695,11 +718,15 @@ free_keys_object(PyDictKeysObject *keys)
static inline PyDictValues*
new_values(Py_ssize_t size)
{
+ size_t prefix_size;
+ size_t n;
+ uint8_t *mem;
+
assert(size > 0);
- size_t prefix_size = _Py_SIZE_ROUND_UP(size+2, sizeof(PyObject *));
+ prefix_size = _Py_SIZE_ROUND_UP(size+2, sizeof(PyObject *));
assert(prefix_size < 256);
- size_t n = prefix_size + size * sizeof(PyObject *);
- uint8_t *mem = PyMem_Malloc(n);
+ n = prefix_size + size * sizeof(PyObject *);
+ mem = PyMem_Malloc(n);
if (mem == NULL) {
return NULL;
}
@@ -720,9 +747,12 @@ static PyObject *
new_dict(PyDictKeysObject *keys, PyDictValues *values, Py_ssize_t used, int free_values_on_failure)
{
PyDictObject *mp;
+#if PyDict_MAXFREELIST > 0
+ struct _Py_dict_state *state;
+#endif
assert(keys != NULL);
#if PyDict_MAXFREELIST > 0
- struct _Py_dict_state *state = get_dict_state();
+ state = get_dict_state();
#ifdef Py_DEBUG
// new_dict() must not be called after _PyDict_Fini()
assert(state->numfree != -1);
@@ -784,13 +814,23 @@ new_dict_with_shared_keys(PyDictKeysObject *keys)
static PyDictKeysObject *
clone_combined_dict_keys(PyDictObject *orig)
{
+ size_t keys_size;
+ PyDictKeysObject *keys;
+ PyObject **pkey;
+ PyObject **pvalue;
+ size_t offs;
+ Py_ssize_t n;
+ Py_ssize_t i;
+ PyDictUnicodeEntry *unicode_ep0;
+ PyDictKeyEntry *key_ep0;
+
assert(PyDict_Check(orig));
assert(Py_TYPE(orig)->tp_iter == (getiterfunc)dict_iter);
assert(orig->ma_values == NULL);
assert(orig->ma_keys->dk_refcnt == 1);
- Py_ssize_t keys_size = _PyDict_KeysSize(orig->ma_keys);
- PyDictKeysObject *keys = PyObject_Malloc(keys_size);
+ keys_size = _PyDict_KeysSize(orig->ma_keys);
+ keys = PyObject_Malloc(keys_size);
if (keys == NULL) {
PyErr_NoMemory();
return NULL;
@@ -801,23 +841,21 @@ clone_combined_dict_keys(PyDictObject *orig)
/* After copying key/value pairs, we need to incref all
keys and values and they are about to be co-owned by a
new dict object. */
- PyObject **pkey, **pvalue;
- size_t offs;
if (DK_IS_UNICODE(orig->ma_keys)) {
- PyDictUnicodeEntry *ep0 = DK_UNICODE_ENTRIES(keys);
- pkey = &ep0->me_key;
- pvalue = &ep0->me_value;
+ unicode_ep0 = DK_UNICODE_ENTRIES(keys);
+ pkey = &unicode_ep0->me_key;
+ pvalue = &unicode_ep0->me_value;
offs = sizeof(PyDictUnicodeEntry) / sizeof(PyObject*);
}
else {
- PyDictKeyEntry *ep0 = DK_ENTRIES(keys);
- pkey = &ep0->me_key;
- pvalue = &ep0->me_value;
+ key_ep0 = DK_ENTRIES(keys);
+ pkey = &key_ep0->me_key;
+ pvalue = &key_ep0->me_value;
offs = sizeof(PyDictKeyEntry) / sizeof(PyObject*);
}
- Py_ssize_t n = keys->dk_nentries;
- for (Py_ssize_t i = 0; i < n; i++) {
+ n = keys->dk_nentries;
+ for (i = 0; i < n; i++) {
PyObject *value = *pvalue;
if (value != NULL) {
Py_INCREF(value);
@@ -875,6 +913,7 @@ unicodekeys_lookup_generic(PyDictObject *mp, PyDictKeysObject* dk, PyObject *key
size_t perturb = hash;
size_t i = (size_t)hash & mask;
Py_ssize_t ix;
+ int cmp;
for (;;) {
ix = dictkeys_get_index(dk, i);
if (ix >= 0) {
@@ -887,7 +926,7 @@ unicodekeys_lookup_generic(PyDictObject *mp, PyDictKeysObject* dk, PyObject *key
if (unicode_get_hash(ep->me_key) == hash) {
PyObject *startkey = ep->me_key;
Py_INCREF(startkey);
- int cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
+ cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
Py_DECREF(startkey);
if (cmp < 0) {
return DKIX_ERROR;
@@ -965,6 +1004,7 @@ dictkeys_generic_lookup(PyDictObject *mp, PyDictKeysObject* dk, PyObject *key, P
size_t perturb = hash;
size_t i = (size_t)hash & mask;
Py_ssize_t ix;
+ int cmp;
for (;;) {
ix = dictkeys_get_index(dk, i);
if (ix >= 0) {
@@ -976,7 +1016,7 @@ dictkeys_generic_lookup(PyDictObject *mp, PyDictKeysObject* dk, PyObject *key, P
if (ep->me_hash == hash) {
PyObject *startkey = ep->me_key;
Py_INCREF(startkey);
- int cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
+ cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
Py_DECREF(startkey);
if (cmp < 0) {
return DKIX_ERROR;
@@ -1010,11 +1050,14 @@ dictkeys_generic_lookup(PyDictObject *mp, PyDictKeysObject* dk, PyObject *key, P
Py_ssize_t
_PyDictKeys_StringLookup(PyDictKeysObject* dk, PyObject *key)
{
- DictKeysKind kind = dk->dk_kind;
+ DictKeysKind kind;
+ Py_hash_t hash;
+
+ kind = dk->dk_kind;
if (!PyUnicode_CheckExact(key) || kind == DICT_KEYS_GENERAL) {
return DKIX_ERROR;
}
- Py_hash_t hash = unicode_get_hash(key);
+ hash = unicode_get_hash(key);
if (hash == -1) {
hash = PyUnicode_Type.tp_hash(key);
if (hash == -1) {
@@ -1167,12 +1210,17 @@ _PyDict_MaybeUntrack(PyObject *op)
static Py_ssize_t
find_empty_slot(PyDictKeysObject *keys, Py_hash_t hash)
{
+ size_t mask;
+ size_t i;
+ size_t perturb;
+ Py_ssize_t ix;
+
assert(keys != NULL);
- const size_t mask = DK_MASK(keys);
- size_t i = hash & mask;
- Py_ssize_t ix = dictkeys_get_index(keys, i);
- for (size_t perturb = hash; ix >= 0;) {
+ mask = DK_MASK(keys);
+ i = hash & mask;
+ ix = dictkeys_get_index(keys, i);
+ for (perturb = hash; ix >= 0;) {
perturb >>= PERTURB_SHIFT;
i = (i*5 + perturb + 1) & mask;
ix = dictkeys_get_index(keys, i);
@@ -1189,8 +1237,13 @@ insertion_resize(PyDictObject *mp, int unicode)
static Py_ssize_t
insert_into_dictkeys(PyDictKeysObject *keys, PyObject *name)
{
+ Py_hash_t hash;
+ Py_ssize_t ix;
+ Py_ssize_t hashpos;
+ PyDictUnicodeEntry *ep;
+
assert(PyUnicode_CheckExact(name));
- Py_hash_t hash = unicode_get_hash(name);
+ hash = unicode_get_hash(name);
if (hash == -1) {
hash = PyUnicode_Type.tp_hash(name);
if (hash == -1) {
@@ -1198,7 +1251,7 @@ insert_into_dictkeys(PyDictKeysObject *keys, PyObject *name)
return DKIX_EMPTY;
}
}
- Py_ssize_t ix = unicodekeys_lookup_unicode(keys, name, hash);
+ ix = unicodekeys_lookup_unicode(keys, name, hash);
if (ix == DKIX_EMPTY) {
if (keys->dk_usable <= 0) {
return DKIX_EMPTY;
@@ -1206,9 +1259,9 @@ insert_into_dictkeys(PyDictKeysObject *keys, PyObject *name)
Py_INCREF(name);
/* Insert into new slot. */
keys->dk_version = 0;
- Py_ssize_t hashpos = find_empty_slot(keys, hash);
+ hashpos = find_empty_slot(keys, hash);
ix = keys->dk_nentries;
- PyDictUnicodeEntry *ep = &DK_UNICODE_ENTRIES(keys)[ix];
+ ep = &DK_UNICODE_ENTRIES(keys)[ix];
dictkeys_set_index(keys, hashpos, ix);
assert(ep->me_key == NULL);
ep->me_key = name;
@@ -1229,6 +1282,8 @@ static int
insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
{
PyObject *old_value;
+ Py_ssize_t ix;
+ Py_ssize_t hashpos;
if (DK_IS_UNICODE(mp->ma_keys) && !PyUnicode_CheckExact(key)) {
if (insertion_resize(mp, 0) < 0)
@@ -1236,7 +1291,7 @@ insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
assert(mp->ma_keys->dk_kind == DICT_KEYS_GENERAL);
}
- Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &old_value);
+ ix = _Py_dict_lookup(mp, key, hash, &old_value);
if (ix == DKIX_ERROR)
goto Fail;
@@ -1252,7 +1307,7 @@ insertdict(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
goto Fail;
}
- Py_ssize_t hashpos = find_empty_slot(mp->ma_keys, hash);
+ hashpos = find_empty_slot(mp->ma_keys, hash);
dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries);
if (DK_IS_UNICODE(mp->ma_keys)) {
@@ -1321,10 +1376,16 @@ static int
insert_to_emptydict(PyDictObject *mp, PyObject *key, Py_hash_t hash,
PyObject *value)
{
+ int unicode;
+ PyDictKeysObject *newkeys;
+ size_t hashpos;
+ PyDictUnicodeEntry *unicode_ep;
+ PyDictKeyEntry *key_ep;
+
assert(mp->ma_keys == Py_EMPTY_KEYS);
- int unicode = PyUnicode_CheckExact(key);
- PyDictKeysObject *newkeys = new_keys_object(PyDict_LOG_MINSIZE, unicode);
+ unicode = PyUnicode_CheckExact(key);
+ newkeys = new_keys_object(PyDict_LOG_MINSIZE, unicode);
if (newkeys == NULL) {
Py_DECREF(key);
Py_DECREF(value);
@@ -1336,7 +1397,7 @@ insert_to_emptydict(PyDictObject *mp, PyObject *key, Py_hash_t hash,
MAINTAIN_TRACKING(mp, key, value);
- size_t hashpos = (size_t)hash & (PyDict_MINSIZE-1);
+ hashpos = (size_t)hash & (PyDict_MINSIZE-1);
dictkeys_set_index(mp->ma_keys, hashpos, 0);
if (unicode) {
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(mp->ma_keys);
@@ -1362,11 +1423,17 @@ Internal routine used by dictresize() to build a hashtable of entries.
static void
build_indices_generic(PyDictKeysObject *keys, PyDictKeyEntry *ep, Py_ssize_t n)
{
- size_t mask = DK_MASK(keys);
- for (Py_ssize_t ix = 0; ix != n; ix++, ep++) {
- Py_hash_t hash = ep->me_hash;
- size_t i = hash & mask;
- for (size_t perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) {
+ size_t mask;
+ size_t i;
+ size_t perturb;
+ Py_ssize_t ix;
+ Py_hash_t hash;
+
+ mask = DK_MASK(keys);
+ for (ix = 0; ix != n; ix++, ep++) {
+ hash = ep->me_hash;
+ i = hash & mask;
+ for (perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) {
perturb >>= PERTURB_SHIFT;
i = mask & (i*5 + perturb + 1);
}
@@ -1377,12 +1444,18 @@ build_indices_generic(PyDictKeysObject *keys, PyDictKeyEntry *ep, Py_ssize_t n)
static void
build_indices_unicode(PyDictKeysObject *keys, PyDictUnicodeEntry *ep, Py_ssize_t n)
{
- size_t mask = DK_MASK(keys);
- for (Py_ssize_t ix = 0; ix != n; ix++, ep++) {
- Py_hash_t hash = unicode_get_hash(ep->me_key);
+ size_t mask;
+ size_t i;
+ size_t perturb;
+ Py_ssize_t ix;
+ Py_hash_t hash;
+
+ mask = DK_MASK(keys);
+ for (ix = 0; ix != n; ix++, ep++) {
+ hash = unicode_get_hash(ep->me_key);
assert(hash != -1);
- size_t i = hash & mask;
- for (size_t perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) {
+ i = hash & mask;
+ for (perturb = hash; dictkeys_get_index(keys, i) != DKIX_EMPTY;) {
perturb >>= PERTURB_SHIFT;
i = mask & (i*5 + perturb + 1);
}
@@ -1409,6 +1482,18 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize, int unicode)
{
PyDictKeysObject *oldkeys;
PyDictValues *oldvalues;
+ Py_ssize_t numentries;
+ Py_ssize_t i;
+ int index;
+ PyDictUnicodeEntry *old_unicode_entries;
+ PyDictUnicodeEntry *new_unicode_entries;
+ PyDictUnicodeEntry *unicode_entry;
+ PyDictKeyEntry *old_key_entries;
+ PyDictKeyEntry *new_key_entries;
+ PyDictKeyEntry *key_entry;
+#if PyDict_MAXFREELIST > 0
+ struct _Py_dict_state *state;
+#endif
if (log2_newsize >= SIZEOF_SIZE_T*8) {
PyErr_NoMemory();
@@ -1437,40 +1522,40 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize, int unicode)
// New table must be large enough.
assert(mp->ma_keys->dk_usable >= mp->ma_used);
- Py_ssize_t numentries = mp->ma_used;
+ numentries = mp->ma_used;
if (oldvalues != NULL) {
- PyDictUnicodeEntry *oldentries = DK_UNICODE_ENTRIES(oldkeys);
+ old_unicode_entries = DK_UNICODE_ENTRIES(oldkeys);
/* Convert split table into new combined table.
* We must incref keys; we can transfer values.
*/
if (mp->ma_keys->dk_kind == DICT_KEYS_GENERAL) {
// split -> generic
- PyDictKeyEntry *newentries = DK_ENTRIES(mp->ma_keys);
+ new_key_entries = DK_ENTRIES(mp->ma_keys);
- for (Py_ssize_t i = 0; i < numentries; i++) {
- int index = get_index_from_order(mp, i);
- PyDictUnicodeEntry *ep = &oldentries[index];
+ for (i = 0; i < numentries; i++) {
+ index = get_index_from_order(mp, i);
+ unicode_entry = &old_unicode_entries[index];
assert(oldvalues->values[index] != NULL);
- Py_INCREF(ep->me_key);
- newentries[i].me_key = ep->me_key;
- newentries[i].me_hash = unicode_get_hash(ep->me_key);
- newentries[i].me_value = oldvalues->values[index];
+ Py_INCREF(unicode_entry->me_key);
+ new_key_entries[i].me_key = unicode_entry->me_key;
+ new_key_entries[i].me_hash = unicode_get_hash(unicode_entry->me_key);
+ new_key_entries[i].me_value = oldvalues->values[index];
}
- build_indices_generic(mp->ma_keys, newentries, numentries);
+ build_indices_generic(mp->ma_keys, new_key_entries, numentries);
}
else { // split -> combined unicode
- PyDictUnicodeEntry *newentries = DK_UNICODE_ENTRIES(mp->ma_keys);
+ new_unicode_entries = DK_UNICODE_ENTRIES(mp->ma_keys);
- for (Py_ssize_t i = 0; i < numentries; i++) {
- int index = get_index_from_order(mp, i);
- PyDictUnicodeEntry *ep = &oldentries[index];
+ for (i = 0; i < numentries; i++) {
+ index = get_index_from_order(mp, i);
+ unicode_entry = &old_unicode_entries[index];
assert(oldvalues->values[index] != NULL);
- Py_INCREF(ep->me_key);
- newentries[i].me_key = ep->me_key;
- newentries[i].me_value = oldvalues->values[index];
+ Py_INCREF(unicode_entry->me_key);
+ new_unicode_entries[i].me_key = unicode_entry->me_key;
+ new_unicode_entries[i].me_value = oldvalues->values[index];
}
- build_indices_unicode(mp->ma_keys, newentries, numentries);
+ build_indices_unicode(mp->ma_keys, new_unicode_entries, numentries);
}
dictkeys_decref(oldkeys);
mp->ma_values = NULL;
@@ -1480,50 +1565,50 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize, int unicode)
if (oldkeys->dk_kind == DICT_KEYS_GENERAL) {
// generic -> generic
assert(mp->ma_keys->dk_kind == DICT_KEYS_GENERAL);
- PyDictKeyEntry *oldentries = DK_ENTRIES(oldkeys);
- PyDictKeyEntry *newentries = DK_ENTRIES(mp->ma_keys);
+ old_key_entries = DK_ENTRIES(oldkeys);
+ new_key_entries = DK_ENTRIES(mp->ma_keys);
if (oldkeys->dk_nentries == numentries) {
- memcpy(newentries, oldentries, numentries * sizeof(PyDictKeyEntry));
+ memcpy(new_key_entries, old_key_entries, numentries * sizeof(PyDictKeyEntry));
}
else {
- PyDictKeyEntry *ep = oldentries;
- for (Py_ssize_t i = 0; i < numentries; i++) {
- while (ep->me_value == NULL)
- ep++;
- newentries[i] = *ep++;
+ key_entry = old_key_entries;
+ for (i = 0; i < numentries; i++) {
+ while (key_entry->me_value == NULL)
+ key_entry++;
+ new_key_entries[i] = *key_entry++;
}
}
- build_indices_generic(mp->ma_keys, newentries, numentries);
+ build_indices_generic(mp->ma_keys, new_key_entries, numentries);
}
else { // oldkeys is combined unicode
- PyDictUnicodeEntry *oldentries = DK_UNICODE_ENTRIES(oldkeys);
+ old_unicode_entries = DK_UNICODE_ENTRIES(oldkeys);
if (unicode) { // combined unicode -> combined unicode
- PyDictUnicodeEntry *newentries = DK_UNICODE_ENTRIES(mp->ma_keys);
+ new_unicode_entries = DK_UNICODE_ENTRIES(mp->ma_keys);
if (oldkeys->dk_nentries == numentries && mp->ma_keys->dk_kind == DICT_KEYS_UNICODE) {
- memcpy(newentries, oldentries, numentries * sizeof(PyDictUnicodeEntry));
+ memcpy(new_unicode_entries, old_unicode_entries, numentries * sizeof(PyDictUnicodeEntry));
}
else {
- PyDictUnicodeEntry *ep = oldentries;
- for (Py_ssize_t i = 0; i < numentries; i++) {
- while (ep->me_value == NULL)
- ep++;
- newentries[i] = *ep++;
+ unicode_entry = old_unicode_entries;
+ for (i = 0; i < numentries; i++) {
+ while (unicode_entry->me_value == NULL)
+ unicode_entry++;
+ new_unicode_entries[i] = *unicode_entry++;
}
}
- build_indices_unicode(mp->ma_keys, newentries, numentries);
+ build_indices_unicode(mp->ma_keys, new_unicode_entries, numentries);
}
else { // combined unicode -> generic
- PyDictKeyEntry *newentries = DK_ENTRIES(mp->ma_keys);
- PyDictUnicodeEntry *ep = oldentries;
- for (Py_ssize_t i = 0; i < numentries; i++) {
- while (ep->me_value == NULL)
- ep++;
- newentries[i].me_key = ep->me_key;
- newentries[i].me_hash = unicode_get_hash(ep->me_key);
- newentries[i].me_value = ep->me_value;
- ep++;
+ new_key_entries = DK_ENTRIES(mp->ma_keys);
+ unicode_entry = old_unicode_entries;
+ for (i = 0; i < numentries; i++) {
+ while (unicode_entry->me_value == NULL)
+ unicode_entry++;
+ new_key_entries[i].me_key = unicode_entry->me_key;
+ new_key_entries[i].me_hash = unicode_get_hash(unicode_entry->me_key);
+ new_key_entries[i].me_value = unicode_entry->me_value;
+ unicode_entry++;
}
- build_indices_generic(mp->ma_keys, newentries, numentries);
+ build_indices_generic(mp->ma_keys, new_key_entries, numentries);
}
}
@@ -1540,7 +1625,7 @@ dictresize(PyDictObject *mp, uint8_t log2_newsize, int unicode)
assert(oldkeys->dk_kind != DICT_KEYS_SPLIT);
assert(oldkeys->dk_refcnt == 1);
#if PyDict_MAXFREELIST > 0
- struct _Py_dict_state *state = get_dict_state();
+ state = get_dict_state();
#ifdef Py_DEBUG
// dictresize() must not be called after _PyDict_Fini()
assert(state->keys_numfree != -1);
@@ -1607,8 +1692,11 @@ _PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
{
bool unicode = true;
PyObject *const *ks = keys;
+ PyObject *const *vs;
+ PyObject *dict;
+ Py_ssize_t i;
- for (Py_ssize_t i = 0; i < length; i++) {
+ for (i = 0; i < length; i++) {
if (!PyUnicode_CheckExact(*ks)) {
unicode = false;
break;
@@ -1616,15 +1704,15 @@ _PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
ks += keys_offset;
}
- PyObject *dict = dict_new_presized(length, unicode);
+ dict = dict_new_presized(length, unicode);
if (dict == NULL) {
return NULL;
}
ks = keys;
- PyObject *const *vs = values;
+ vs = values;
- for (Py_ssize_t i = 0; i < length; i++) {
+ for (i = 0; i < length; i++) {
PyObject *key = *ks;
PyObject *value = *vs;
if (PyDict_SetItem(dict, key, value) < 0) {
@@ -1651,12 +1739,18 @@ _PyDict_FromItems(PyObject *const *keys, Py_ssize_t keys_offset,
PyObject *
PyDict_GetItem(PyObject *op, PyObject *key)
{
+ PyDictObject *mp;
+ Py_hash_t hash;
+ PyThreadState *tstate;
+ PyObject *exc_type, *exc_value, *exc_tb;
+ PyObject *value;
+ Py_ssize_t ix;
+
if (!PyDict_Check(op)) {
return NULL;
}
- PyDictObject *mp = (PyDictObject *)op;
+ mp = (PyDictObject *)op;
- Py_hash_t hash;
if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
hash = PyObject_Hash(key);
if (hash == -1) {
@@ -1665,7 +1759,7 @@ PyDict_GetItem(PyObject *op, PyObject *key)
}
}
- PyThreadState *tstate = _PyThreadState_GET();
+ tstate = _PyThreadState_GET();
#ifdef Py_DEBUG
// bpo-40839: Before Python 3.10, it was possible to call PyDict_GetItem()
// with the GIL released.
@@ -1673,9 +1767,6 @@ PyDict_GetItem(PyObject *op, PyObject *key)
#endif
/* Preserve the existing exception */
- PyObject *exc_type, *exc_value, *exc_tb;
- PyObject *value;
- Py_ssize_t ix; (void)ix;
_PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb);
ix = _Py_dict_lookup(mp, key, hash, &value);
@@ -1692,6 +1783,8 @@ Py_ssize_t
_PyDict_GetItemHint(PyDictObject *mp, PyObject *key,
Py_ssize_t hint, PyObject **value)
{
+ Py_hash_t hash;
+
assert(*value == NULL);
assert(PyDict_CheckExact((PyObject*)mp));
assert(PyUnicode_CheckExact(key));
@@ -1733,7 +1826,7 @@ _PyDict_GetItemHint(PyDictObject *mp, PyObject *key,
}
}
- Py_hash_t hash = unicode_get_hash(key);
+ hash = unicode_get_hash(key);
if (hash == -1) {
hash = PyObject_Hash(key);
if (hash == -1) {
@@ -1751,10 +1844,11 @@ _PyDict_GetItemHint(PyDictObject *mp, PyObject *key,
PyObject *
_PyDict_GetItem_KnownHash(PyObject *op, PyObject *key, Py_hash_t hash)
{
- Py_ssize_t ix; (void)ix;
- PyDictObject *mp = (PyDictObject *)op;
+ Py_ssize_t ix;
+ PyDictObject *mp;
PyObject *value;
+ mp = (PyDictObject *)op;
if (!PyDict_Check(op)) {
PyErr_BadInternalCall();
return NULL;
@@ -1772,7 +1866,7 @@ _PyDict_GetItem_KnownHash(PyObject *op, PyObject *key, Py_hash_t hash)
PyObject *
PyDict_GetItemWithError(PyObject *op, PyObject *key)
{
- Py_ssize_t ix; (void)ix;
+ Py_ssize_t ix;
Py_hash_t hash;
PyDictObject*mp = (PyDictObject *)op;
PyObject *value;
@@ -1797,8 +1891,10 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key)
PyObject *
_PyDict_GetItemWithError(PyObject *dp, PyObject *kv)
{
+ Py_hash_t hash;
+
assert(PyUnicode_CheckExact(kv));
- Py_hash_t hash = kv->ob_type->tp_hash(kv);
+ hash = kv->ob_type->tp_hash(kv);
if (hash == -1) {
return NULL;
}
@@ -1809,10 +1905,12 @@ PyObject *
_PyDict_GetItemIdWithError(PyObject *dp, _Py_Identifier *key)
{
PyObject *kv;
+ Py_hash_t hash;
+
kv = _PyUnicode_FromId(key); /* borrowed */
if (kv == NULL)
return NULL;
- Py_hash_t hash = unicode_get_hash(kv);
+ hash = unicode_get_hash(kv);
assert (hash != -1); /* interned strings have their hash value initialised */
return _PyDict_GetItem_KnownHash(dp, kv, hash);
}
@@ -1870,10 +1968,11 @@ _PyDict_LoadGlobal(PyDictObject *globals, PyDictObject *builtins, PyObject *key)
int
_PyDict_SetItem_Take2(PyDictObject *mp, PyObject *key, PyObject *value)
{
+ Py_hash_t hash;
+
assert(key);
assert(value);
assert(PyDict_Check(mp));
- Py_hash_t hash;
if (!PyUnicode_CheckExact(key) || (hash = unicode_get_hash(key)) == -1) {
hash = PyObject_Hash(key);
if (hash == -1) {
@@ -2126,6 +2225,7 @@ _PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey,
PyDictObject *mp;
PyObject *key, *value;
Py_hash_t hash;
+ int index;
if (!PyDict_Check(op))
return 0;
@@ -2135,7 +2235,7 @@ _PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey,
assert(mp->ma_used <= SHARED_KEYS_MAX_SIZE);
if (i < 0 || i >= mp->ma_used)
return 0;
- int index = get_index_from_order(mp, i);
+ index = get_index_from_order(mp, i);
value = mp->ma_values->values[index];
key = DK_UNICODE_ENTRIES(mp->ma_keys)[index].me_key;
@@ -2365,6 +2465,9 @@ dict_dealloc(PyDictObject *mp)
PyDictValues *values = mp->ma_values;
PyDictKeysObject *keys = mp->ma_keys;
Py_ssize_t i, n;
+#if PyDict_MAXFREELIST > 0
+ struct _Py_dict_state *state;
+#endif
/* bpo-31095: UnTrack is needed before calling any callbacks */
PyObject_GC_UnTrack(mp);
@@ -2381,7 +2484,7 @@ dict_dealloc(PyDictObject *mp)
dictkeys_decref(keys);
}
#if PyDict_MAXFREELIST > 0
- struct _Py_dict_state *state = get_dict_state();
+ state = get_dict_state();
#ifdef Py_DEBUG
// new_dict() must not be called after _PyDict_Fini()
assert(state->numfree != -1);
@@ -2544,6 +2647,8 @@ dict_keys(PyDictObject *mp)
{
PyObject *v;
Py_ssize_t n;
+ Py_ssize_t j, pos;
+ PyObject *key;
again:
n = mp->ma_used;
@@ -2559,8 +2664,8 @@ dict_keys(PyDictObject *mp)
}
/* Nothing we do below makes any function calls. */
- Py_ssize_t j = 0, pos = 0;
- PyObject *key;
+ j = 0;
+ pos = 0;
while (_PyDict_Next((PyObject*)mp, &pos, &key, NULL, NULL)) {
assert(j < n);
Py_INCREF(key);
@@ -2575,7 +2680,9 @@ static PyObject *
dict_values(PyDictObject *mp)
{
PyObject *v;
+ PyObject *value;
Py_ssize_t n;
+ Py_ssize_t j, pos;
again:
n = mp->ma_used;
@@ -2591,8 +2698,8 @@ dict_values(PyDictObject *mp)
}
/* Nothing we do below makes any function calls. */
- Py_ssize_t j = 0, pos = 0;
- PyObject *value;
+ j = 0;
+ pos = 0;
while (_PyDict_Next((PyObject*)mp, &pos, NULL, &value, NULL)) {
assert(j < n);
Py_INCREF(value);
@@ -2609,6 +2716,8 @@ dict_items(PyDictObject *mp)
PyObject *v;
Py_ssize_t i, n;
PyObject *item;
+ Py_ssize_t j, pos;
+ PyObject *key, *value;
/* Preallocate the list of tuples, to avoid allocations during
* the loop over the items, which could trigger GC, which
@@ -2636,11 +2745,11 @@ dict_items(PyDictObject *mp)
}
/* Nothing we do below makes any function calls. */
- Py_ssize_t j = 0, pos = 0;
- PyObject *key, *value;
+ j = 0;
+ pos = 0;
while (_PyDict_Next((PyObject*)mp, &pos, &key, &value, NULL)) {
assert(j < n);
- PyObject *item = PyList_GET_ITEM(v, j);
+ item = PyList_GET_ITEM(v, j);
Py_INCREF(key);
PyTuple_SET_ITEM(item, 0, key);
Py_INCREF(value);
@@ -2672,10 +2781,11 @@ dict_fromkeys_impl(PyTypeObject *type, PyObject *iterable, PyObject *value)
static int
dict_update_arg(PyObject *self, PyObject *arg)
{
+ PyObject *func;
+
if (PyDict_CheckExact(arg)) {
return PyDict_Merge(self, arg, 1);
}
- PyObject *func;
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
return -1;
}
@@ -2819,6 +2929,10 @@ static int
dict_merge(PyObject *a, PyObject *b, int override)
{
PyDictObject *mp, *other;
+ PyDictKeysObject *okeys;
+ Py_ssize_t orig_size, pos;
+ Py_hash_t hash;
+ PyObject *key, *value;
assert(0 <= override && override <= 2);
@@ -2843,7 +2957,7 @@ dict_merge(PyObject *a, PyObject *b, int override)
* skips the unnecessary test.
*/
override = 1;
- PyDictKeysObject *okeys = other->ma_keys;
+ okeys = other->ma_keys;
// If other is clean, combined, and just allocated, just clone it.
if (other->ma_values == NULL &&
@@ -2885,10 +2999,8 @@ dict_merge(PyObject *a, PyObject *b, int override)
}
}
- Py_ssize_t orig_size = other->ma_keys->dk_nentries;
- Py_ssize_t pos = 0;
- Py_hash_t hash;
- PyObject *key, *value;
+ orig_size = other->ma_keys->dk_nentries;
+ pos = 0;
while (_PyDict_Next((PyObject*)other, &pos, &key, &value, &hash)) {
int err = 0;
@@ -3017,7 +3129,12 @@ PyDict_Copy(PyObject *o)
{
PyObject *copy;
PyDictObject *mp;
- Py_ssize_t i, n;
+ PyDictObject *split_copy;
+ PyDictObject *new;
+ PyDictKeysObject *keys;
+ PyDictValues *newvalues;
+ Py_ssize_t i, n, size;
+ size_t prefix_size;
if (o == NULL || !PyDict_Check(o)) {
PyErr_BadInternalCall();
@@ -3031,9 +3148,7 @@ PyDict_Copy(PyObject *o)
}
if (_PyDict_HasSplitTable(mp)) {
- PyDictObject *split_copy;
- Py_ssize_t size = shared_keys_usable_size(mp->ma_keys);
- PyDictValues *newvalues;
+ size = shared_keys_usable_size(mp->ma_keys);
newvalues = new_values(size);
if (newvalues == NULL)
return PyErr_NoMemory();
@@ -3042,7 +3157,7 @@ PyDict_Copy(PyObject *o)
free_values(newvalues);
return NULL;
}
- size_t prefix_size = ((uint8_t *)newvalues)[-1];
+ prefix_size = ((uint8_t *)newvalues)[-1];
memcpy(((char *)newvalues)-prefix_size, ((char *)mp->ma_values)-prefix_size, prefix_size-1);
split_copy->ma_values = newvalues;
split_copy->ma_keys = mp->ma_keys;
@@ -3077,11 +3192,11 @@ PyDict_Copy(PyObject *o)
operations and copied after that. In cases like this, we defer to
PyDict_Merge, which produces a compacted copy.
*/
- PyDictKeysObject *keys = clone_combined_dict_keys(mp);
+ keys = clone_combined_dict_keys(mp);
if (keys == NULL) {
return NULL;
}
- PyDictObject *new = (PyDictObject *)new_dict(keys, NULL, 0, 0);
+ new = (PyDictObject *)new_dict(keys, NULL, 0, 0);
if (new == NULL) {
/* In case of an error, `new_dict()` takes care of
cleaning up `keys`. */
@@ -3300,9 +3415,14 @@ dict_get_impl(PyDictObject *self, PyObject *key, PyObject *default_value)
PyObject *
PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj)
{
- PyDictObject *mp = (PyDictObject *)d;
+ PyDictObject *mp;
PyObject *value;
Py_hash_t hash;
+ Py_ssize_t ix, hashpos, index;
+ PyDictUnicodeEntry *unicode_ep;
+ PyDictKeyEntry *key_ep;
+
+ mp = (PyDictObject *)d;
if (!PyDict_Check(d)) {
PyErr_BadInternalCall();
@@ -3330,7 +3450,7 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj)
}
}
- Py_ssize_t ix = _Py_dict_lookup(mp, key, hash, &value);
+ ix = _Py_dict_lookup(mp, key, hash, &value);
if (ix == DKIX_ERROR)
return NULL;
@@ -3342,28 +3462,28 @@ PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *defaultobj)
return NULL;
}
}
- Py_ssize_t hashpos = find_empty_slot(mp->ma_keys, hash);
+ hashpos = find_empty_slot(mp->ma_keys, hash);
dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries);
if (DK_IS_UNICODE(mp->ma_keys)) {
assert(PyUnicode_CheckExact(key));
- PyDictUnicodeEntry *ep = &DK_UNICODE_ENTRIES(mp->ma_keys)[mp->ma_keys->dk_nentries];
- ep->me_key = key;
+ unicode_ep = &DK_UNICODE_ENTRIES(mp->ma_keys)[mp->ma_keys->dk_nentries];
+ unicode_ep->me_key = key;
if (_PyDict_HasSplitTable(mp)) {
- Py_ssize_t index = (int)mp->ma_keys->dk_nentries;
+ index = (int)mp->ma_keys->dk_nentries;
assert(index < SHARED_KEYS_MAX_SIZE);
assert(mp->ma_values->values[index] == NULL);
mp->ma_values->values[index] = value;
_PyDictValues_AddToInsertionOrder(mp->ma_values, index);
}
else {
- ep->me_value = value;
+ unicode_ep->me_value = value;
}
}
else {
- PyDictKeyEntry *ep = &DK_ENTRIES(mp->ma_keys)[mp->ma_keys->dk_nentries];
- ep->me_key = key;
- ep->me_hash = hash;
- ep->me_value = value;
+ key_ep = &DK_ENTRIES(mp->ma_keys)[mp->ma_keys->dk_nentries];
+ key_ep->me_key = key;
+ key_ep->me_hash = hash;
+ key_ep->me_value = value;
}
Py_INCREF(key);
Py_INCREF(value);
@@ -3456,6 +3576,8 @@ dict_popitem_impl(PyDictObject *self)
{
Py_ssize_t i, j;
PyObject *res;
+ PyObject *key, *value;
+ Py_hash_t hash;
/* Allocate the result tuple before checking the size. Believe it
* or not, this allocation could trigger a garbage collection which
@@ -3484,8 +3606,6 @@ dict_popitem_impl(PyDictObject *self)
self->ma_keys->dk_version = 0;
/* Pop last item */
- PyObject *key, *value;
- Py_hash_t hash;
if (DK_IS_UNICODE(self->ma_keys)) {
PyDictUnicodeEntry *ep0 = DK_UNICODE_ENTRIES(self->ma_keys);
i = self->ma_keys->dk_nentries - 1;
@@ -3608,10 +3728,12 @@ dict_sizeof(PyDictObject *mp, PyObject *Py_UNUSED(ignored))
static PyObject *
dict_or(PyObject *self, PyObject *other)
{
+ PyObject *new;
+
if (!PyDict_Check(self) || !PyDict_Check(other)) {
Py_RETURN_NOTIMPLEMENTED;
}
- PyObject *new = PyDict_Copy(self);
+ new = PyDict_Copy(self);
if (new == NULL) {
return NULL;
}
@@ -3747,24 +3869,46 @@ static PySequenceMethods dict_as_sequence = {
0, /* sq_inplace_repeat */
};
+static PyObject *dict_vectorcall(PyObject *type, PyObject * const*args,
+ size_t nargsf, PyObject *kwnames);
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+static void _PyDict_InitViewTypes(void);
+#endif
+
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
static PyNumberMethods dict_as_number = {
.nb_or = dict_or,
.nb_inplace_or = dict_ior,
};
+#else
+static PyNumberMethods dict_as_number = {0};
+
+void
+_PyDict_InitTypes(void)
+{
+ dict_as_number.nb_or = dict_or;
+ dict_as_number.nb_inplace_or = dict_ior;
+ PyDict_Type.tp_vectorcall = dict_vectorcall;
+ _PyDict_InitViewTypes();
+}
+#endif
static PyObject *
dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
+ PyObject *self;
+ PyDictObject *d;
+
assert(type != NULL);
assert(type->tp_alloc != NULL);
// dict subclasses must implement the GC protocol
assert(_PyType_IS_GC(type));
- PyObject *self = type->tp_alloc(type, 0);
+ self = type->tp_alloc(type, 0);
if (self == NULL) {
return NULL;
}
- PyDictObject *d = (PyDictObject *)self;
+ d = (PyDictObject *)self;
d->ma_used = 0;
d->ma_version_tag = DICT_NEXT_VERSION();
@@ -3797,11 +3941,14 @@ dict_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ Py_ssize_t i;
+ PyObject *self;
+
if (!_PyArg_CheckPositional("dict", nargs, 0, 1)) {
return NULL;
}
- PyObject *self = dict_new(_PyType_CAST(type), NULL, NULL);
+ self = dict_new(_PyType_CAST(type), NULL, NULL);
if (self == NULL) {
return NULL;
}
@@ -3813,7 +3960,7 @@ dict_vectorcall(PyObject *type, PyObject * const*args,
args++;
}
if (kwnames != NULL) {
- for (Py_ssize_t i = 0; i < PyTuple_GET_SIZE(kwnames); i++) {
+ for (i = 0; i < PyTuple_GET_SIZE(kwnames); i++) {
if (PyDict_SetItem(self, PyTuple_GET_ITEM(kwnames, i), args[i]) < 0) {
Py_DECREF(self);
return NULL;
@@ -3882,7 +4029,9 @@ PyTypeObject PyDict_Type = {
_PyType_AllocNoTrack, /* tp_alloc */
dict_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_vectorcall = dict_vectorcall,
+#endif
};
/* For backward compatibility with old dictionary interface */
@@ -4048,6 +4197,7 @@ dictiter_iternextkey(dictiterobject *di)
Py_ssize_t i;
PyDictKeysObject *k;
PyDictObject *d = di->di_dict;
+ int index;
if (d == NULL)
return NULL;
@@ -4066,7 +4216,7 @@ dictiter_iternextkey(dictiterobject *di)
if (d->ma_values) {
if (i >= d->ma_used)
goto fail;
- int index = get_index_from_order(d, i);
+ index = get_index_from_order(d, i);
key = DK_UNICODE_ENTRIES(k)[index].me_key;
assert(d->ma_values->values[index] != NULL);
}
@@ -4148,6 +4298,7 @@ dictiter_iternextvalue(dictiterobject *di)
{
PyObject *value;
Py_ssize_t i;
+ int index;
PyDictObject *d = di->di_dict;
if (d == NULL)
@@ -4166,7 +4317,7 @@ dictiter_iternextvalue(dictiterobject *di)
if (d->ma_values) {
if (i >= d->ma_used)
goto fail;
- int index = get_index_from_order(d, i);
+ index = get_index_from_order(d, i);
value = d->ma_values->values[index];
assert(value != NULL);
}
@@ -4248,6 +4399,7 @@ dictiter_iternextitem(dictiterobject *di)
{
PyObject *key, *value, *result;
Py_ssize_t i;
+ int index;
PyDictObject *d = di->di_dict;
if (d == NULL)
@@ -4266,7 +4418,7 @@ dictiter_iternextitem(dictiterobject *di)
if (d->ma_values) {
if (i >= d->ma_used)
goto fail;
- int index = get_index_from_order(d, i);
+ index = get_index_from_order(d, i);
key = DK_UNICODE_ENTRIES(d->ma_keys)[index].me_key;
value = d->ma_values->values[index];
assert(value != NULL);
@@ -4375,6 +4527,10 @@ PyTypeObject PyDictIterItem_Type = {
static PyObject *
dictreviter_iternext(dictiterobject *di)
{
+ Py_ssize_t i;
+ PyDictKeysObject *k;
+ PyObject *key, *value, *result;
+ int index;
PyDictObject *d = di->di_dict;
if (d == NULL) {
@@ -4389,15 +4545,14 @@ dictreviter_iternext(dictiterobject *di)
return NULL;
}
- Py_ssize_t i = di->di_pos;
- PyDictKeysObject *k = d->ma_keys;
- PyObject *key, *value, *result;
+ i = di->di_pos;
+ k = d->ma_keys;
if (i < 0) {
goto fail;
}
if (d->ma_values) {
- int index = get_index_from_order(d, i);
+ index = get_index_from_order(d, i);
key = DK_UNICODE_ENTRIES(k)[index].me_key;
value = d->ma_values->values[index];
assert (value != NULL);
@@ -4479,12 +4634,32 @@ PyTypeObject PyDictRevIterKey_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dict_reversekeyiterator",
sizeof(dictiterobject),
- .tp_dealloc = (destructor)dictiter_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
- .tp_traverse = (traverseproc)dictiter_traverse,
- .tp_iter = PyObject_SelfIter,
- .tp_iternext = (iternextfunc)dictreviter_iternext,
- .tp_methods = dictiter_methods
+ 0,
+ (destructor)dictiter_dealloc,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ PyObject_GenericGetAttr,
+ 0,
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ 0,
+ (traverseproc)dictiter_traverse,
+ 0,
+ 0,
+ 0,
+ PyObject_SelfIter,
+ (iternextfunc)dictreviter_iternext,
+ dictiter_methods,
+ 0,
};
@@ -4505,11 +4680,14 @@ dict___reversed___impl(PyDictObject *self)
static PyObject *
dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored))
{
+ dictiterobject tmp;
+ PyObject *list;
+
/* copy the iterator state */
- dictiterobject tmp = *di;
+ tmp = *di;
Py_XINCREF(tmp.di_dict);
- PyObject *list = PySequence_List((PyObject*)&tmp);
+ list = PySequence_List((PyObject*)&tmp);
Py_XDECREF(tmp.di_dict);
if (list == NULL) {
return NULL;
@@ -4521,24 +4699,40 @@ PyTypeObject PyDictRevIterItem_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dict_reverseitemiterator",
sizeof(dictiterobject),
- .tp_dealloc = (destructor)dictiter_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
- .tp_traverse = (traverseproc)dictiter_traverse,
- .tp_iter = PyObject_SelfIter,
- .tp_iternext = (iternextfunc)dictreviter_iternext,
- .tp_methods = dictiter_methods
+ 0,
+ (destructor)dictiter_dealloc,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ PyObject_GenericGetAttr,
+ 0,
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ 0,
+ (traverseproc)dictiter_traverse,
+ 0, 0, 0,
+ PyObject_SelfIter,
+ (iternextfunc)dictreviter_iternext,
+ dictiter_methods,
+ 0,
};
PyTypeObject PyDictRevIterValue_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"dict_reversevalueiterator",
sizeof(dictiterobject),
- .tp_dealloc = (destructor)dictiter_dealloc,
- .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
- .tp_traverse = (traverseproc)dictiter_traverse,
- .tp_iter = PyObject_SelfIter,
- .tp_iternext = (iternextfunc)dictreviter_iternext,
- .tp_methods = dictiter_methods
+ 0,
+ (destructor)dictiter_dealloc,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ PyObject_GenericGetAttr,
+ 0,
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ 0,
+ (traverseproc)dictiter_traverse,
+ 0, 0, 0,
+ PyObject_SelfIter,
+ (iternextfunc)dictreviter_iternext,
+ dictiter_methods,
+ 0,
};
/***********************************************/
@@ -4598,11 +4792,13 @@ _PyDictView_New(PyObject *dict, PyTypeObject *type)
static PyObject *
dictview_mapping(PyObject *view, void *Py_UNUSED(ignored)) {
+ PyObject *mapping;
+
assert(view != NULL);
assert(PyDictKeys_Check(view)
|| PyDictValues_Check(view)
|| PyDictItems_Check(view));
- PyObject *mapping = (PyObject *)((_PyDictViewObject *)view)->dv_dict;
+ mapping = (PyObject *)((_PyDictViewObject *)view)->dv_dict;
return PyDictProxy_New(mapping);
}
@@ -4612,6 +4808,16 @@ static PyGetSetDef dictview_getset[] = {
{0}
};
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+static void
+_PyDict_InitViewTypes(void)
+{
+ PyDictKeys_Type.tp_getset = dictview_getset;
+ PyDictItems_Type.tp_getset = dictview_getset;
+ PyDictValues_Type.tp_getset = dictview_getset;
+}
+#endif
+
/* TODO(guido): The views objects are not complete:
* support more set operations
@@ -4779,12 +4985,15 @@ dictviews_to_set(PyObject *self)
static PyObject*
dictviews_sub(PyObject *self, PyObject *other)
{
- PyObject *result = dictviews_to_set(self);
+ PyObject *result;
+ PyObject *tmp;
+
+ result = dictviews_to_set(self);
if (result == NULL) {
return NULL;
}
- PyObject *tmp = PyObject_CallMethodOneArg(
+ tmp = PyObject_CallMethodOneArg(
result, &_Py_ID(difference_update), other);
if (tmp == NULL) {
Py_DECREF(result);
@@ -4901,31 +5110,38 @@ dictviews_or(PyObject* self, PyObject *other)
static PyObject *
dictitems_xor(PyObject *self, PyObject *other)
{
+ PyObject *d1, *d2, *temp_dict, *result_set;
+ PyObject *key, *val1, *val2, *remaining_pairs;
+ Py_ssize_t pos;
+ Py_hash_t hash;
+ int to_delete;
+
assert(PyDictItems_Check(self));
assert(PyDictItems_Check(other));
- PyObject *d1 = (PyObject *)((_PyDictViewObject *)self)->dv_dict;
- PyObject *d2 = (PyObject *)((_PyDictViewObject *)other)->dv_dict;
+ d1 = (PyObject *)((_PyDictViewObject *)self)->dv_dict;
+ d2 = (PyObject *)((_PyDictViewObject *)other)->dv_dict;
- PyObject *temp_dict = PyDict_Copy(d1);
+ temp_dict = PyDict_Copy(d1);
if (temp_dict == NULL) {
return NULL;
}
- PyObject *result_set = PySet_New(NULL);
+ result_set = PySet_New(NULL);
if (result_set == NULL) {
Py_CLEAR(temp_dict);
return NULL;
}
- PyObject *key = NULL, *val1 = NULL, *val2 = NULL;
- Py_ssize_t pos = 0;
- Py_hash_t hash;
+ key = NULL;
+ val1 = NULL;
+ val2 = NULL;
+ pos = 0;
while (_PyDict_Next(d2, &pos, &key, &val2, &hash)) {
Py_INCREF(key);
Py_INCREF(val2);
val1 = _PyDict_GetItem_KnownHash(temp_dict, key, hash);
- int to_delete;
+ to_delete = 0;
if (val1 == NULL) {
if (PyErr_Occurred()) {
goto error;
@@ -4962,7 +5178,7 @@ dictitems_xor(PyObject *self, PyObject *other)
}
key = val1 = val2 = NULL;
- PyObject *remaining_pairs = PyObject_CallMethodNoArgs(
+ remaining_pairs = PyObject_CallMethodNoArgs(
temp_dict, &_Py_ID(items));
if (remaining_pairs == NULL) {
goto error;
@@ -4987,15 +5203,18 @@ dictitems_xor(PyObject *self, PyObject *other)
static PyObject*
dictviews_xor(PyObject* self, PyObject *other)
{
+ PyObject *result;
+ PyObject *tmp;
+
if (PyDictItems_Check(self) && PyDictItems_Check(other)) {
return dictitems_xor(self, other);
}
- PyObject *result = dictviews_to_set(self);
+ result = dictviews_to_set(self);
if (result == NULL) {
return NULL;
}
- PyObject *tmp = PyObject_CallMethodOneArg(
+ tmp = PyObject_CallMethodOneArg(
result, &_Py_ID(symmetric_difference_update), other);
if (tmp == NULL) {
Py_DECREF(result);
@@ -5122,7 +5341,9 @@ PyTypeObject PyDictKeys_Type = {
(getiterfunc)dictkeys_iter, /* tp_iter */
0, /* tp_iternext */
dictkeys_methods, /* tp_methods */
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_getset = dictview_getset,
+#endif
};
static PyObject *
@@ -5228,7 +5449,9 @@ PyTypeObject PyDictItems_Type = {
(getiterfunc)dictitems_iter, /* tp_iter */
0, /* tp_iternext */
dictitems_methods, /* tp_methods */
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_getset = dictview_getset,
+#endif
};
static PyObject *
@@ -5309,7 +5532,9 @@ PyTypeObject PyDictValues_Type = {
(getiterfunc)dictvalues_iter, /* tp_iter */
0, /* tp_iternext */
dictvalues_methods, /* tp_methods */
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_getset = dictview_getset,
+#endif
};
static PyObject *
@@ -5351,24 +5576,29 @@ _PyDict_NewKeysForClass(void)
static int
init_inline_values(PyObject *obj, PyTypeObject *tp)
{
+ PyDictKeysObject *keys;
+ Py_ssize_t size;
+ PyDictValues *values;
+ int i;
+
assert(tp->tp_flags & Py_TPFLAGS_HEAPTYPE);
// assert(type->tp_dictoffset > 0); -- TO DO Update this assert.
assert(tp->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- PyDictKeysObject *keys = CACHED_KEYS(tp);
+ keys = CACHED_KEYS(tp);
assert(keys != NULL);
if (keys->dk_usable > 1) {
keys->dk_usable--;
}
- Py_ssize_t size = shared_keys_usable_size(keys);
+ size = shared_keys_usable_size(keys);
assert(size > 0);
- PyDictValues *values = new_values(size);
+ values = new_values(size);
if (values == NULL) {
PyErr_NoMemory();
return -1;
}
assert(((uint8_t *)values)[-1] >= size+2);
((uint8_t *)values)[-2] = 0;
- for (int i = 0; i < size; i++) {
+ for (i = 0; i < size; i++) {
values->values[i] = NULL;
}
*_PyObject_ValuesPointer(obj) = values;
@@ -5378,7 +5608,11 @@ init_inline_values(PyObject *obj, PyTypeObject *tp)
int
_PyObject_InitializeDict(PyObject *obj)
{
- PyTypeObject *tp = Py_TYPE(obj);
+ PyTypeObject *tp;
+ PyObject *dict;
+ PyObject **dictptr;
+
+ tp = Py_TYPE(obj);
if (tp->tp_dictoffset == 0) {
return 0;
}
@@ -5386,7 +5620,6 @@ _PyObject_InitializeDict(PyObject *obj)
OBJECT_STAT_INC(new_values);
return init_inline_values(obj, tp);
}
- PyObject *dict;
if (_PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE) && CACHED_KEYS(tp)) {
dictkeys_incref(CACHED_KEYS(tp));
dict = new_dict_with_shared_keys(CACHED_KEYS(tp));
@@ -5397,7 +5630,7 @@ _PyObject_InitializeDict(PyObject *obj)
if (dict == NULL) {
return -1;
}
- PyObject **dictptr = _PyObject_DictPointer(obj);
+ dictptr = _PyObject_DictPointer(obj);
*dictptr = dict;
return 0;
}
@@ -5405,17 +5638,20 @@ _PyObject_InitializeDict(PyObject *obj)
static PyObject *
make_dict_from_instance_attributes(PyDictKeysObject *keys, PyDictValues *values)
{
+ Py_ssize_t used, track, i;
+ PyObject *val, *res;
+
dictkeys_incref(keys);
- Py_ssize_t used = 0;
- Py_ssize_t track = 0;
- for (Py_ssize_t i = 0; i < shared_keys_usable_size(keys); i++) {
- PyObject *val = values->values[i];
+ used = 0;
+ track = 0;
+ for (i = 0; i < shared_keys_usable_size(keys); i++) {
+ val = values->values[i];
if (val != NULL) {
used += 1;
track += _PyObject_GC_MAY_BE_TRACKED(val);
}
}
- PyObject *res = new_dict(keys, values, used, 0);
+ res = new_dict(keys, values, used, 0);
if (track && res) {
_PyObject_GC_TRACK(res);
}
@@ -5425,8 +5661,10 @@ make_dict_from_instance_attributes(PyDictKeysObject *keys, PyDictValues *values)
PyObject *
_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values)
{
+ PyDictKeysObject *keys;
+
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
+ keys = CACHED_KEYS(Py_TYPE(obj));
OBJECT_STAT_INC(dict_materialized_on_request);
return make_dict_from_instance_attributes(keys, values);
}
@@ -5435,11 +5673,15 @@ int
_PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
PyObject *name, PyObject *value)
{
- PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
+ PyDictKeysObject *keys;
+ Py_ssize_t ix;
+ PyObject *dict, *old_value;
+
+ keys = CACHED_KEYS(Py_TYPE(obj));
assert(keys != NULL);
assert(values != NULL);
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- Py_ssize_t ix = DKIX_EMPTY;
+ ix = DKIX_EMPTY;
if (PyUnicode_CheckExact(name)) {
ix = insert_into_dictkeys(keys, name);
}
@@ -5457,7 +5699,7 @@ _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
OBJECT_STAT_INC(dict_materialized_str_subclass);
}
#endif
- PyObject *dict = make_dict_from_instance_attributes(keys, values);
+ dict = make_dict_from_instance_attributes(keys, values);
if (dict == NULL) {
return -1;
}
@@ -5470,7 +5712,7 @@ _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
return PyDict_SetItem(dict, name, value);
}
}
- PyObject *old_value = values->values[ix];
+ old_value = values->values[ix];
Py_XINCREF(value);
values->values[ix] = value;
if (old_value == NULL) {
@@ -5495,14 +5737,18 @@ PyObject *
_PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
PyObject *name)
{
+ PyDictKeysObject *keys;
+ Py_ssize_t ix;
+ PyObject *value;
+
assert(PyUnicode_CheckExact(name));
- PyDictKeysObject *keys = CACHED_KEYS(Py_TYPE(obj));
+ keys = CACHED_KEYS(Py_TYPE(obj));
assert(keys != NULL);
- Py_ssize_t ix = _PyDictKeys_StringLookup(keys, name);
+ ix = _PyDictKeys_StringLookup(keys, name);
if (ix == DKIX_EMPTY) {
return NULL;
}
- PyObject *value = values->values[ix];
+ value = values->values[ix];
Py_XINCREF(value);
return value;
}
@@ -5510,16 +5756,22 @@ _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
int
_PyObject_IsInstanceDictEmpty(PyObject *obj)
{
- PyTypeObject *tp = Py_TYPE(obj);
+ PyTypeObject *tp;
+ PyObject **dictptr;
+ PyObject *dict;
+ PyDictValues *values;
+ PyDictKeysObject *keys;
+ Py_ssize_t i;
+
+ tp = Py_TYPE(obj);
if (tp->tp_dictoffset == 0) {
return 1;
}
- PyObject **dictptr;
if (tp->tp_flags & Py_TPFLAGS_MANAGED_DICT) {
- PyDictValues *values = *_PyObject_ValuesPointer(obj);
+ values = *_PyObject_ValuesPointer(obj);
if (values) {
- PyDictKeysObject *keys = CACHED_KEYS(tp);
- for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
+ keys = CACHED_KEYS(tp);
+ for (i = 0; i < keys->dk_nentries; i++) {
if (values->values[i] != NULL) {
return 0;
}
@@ -5531,7 +5783,7 @@ _PyObject_IsInstanceDictEmpty(PyObject *obj)
else {
dictptr = _PyObject_DictPointer(obj);
}
- PyObject *dict = *dictptr;
+ dict = *dictptr;
if (dict == NULL) {
return 1;
}
@@ -5542,14 +5794,19 @@ _PyObject_IsInstanceDictEmpty(PyObject *obj)
int
_PyObject_VisitInstanceAttributes(PyObject *self, visitproc visit, void *arg)
{
- PyTypeObject *tp = Py_TYPE(self);
+ PyTypeObject *tp;
+ PyDictValues **values_ptr;
+ PyDictKeysObject *keys;
+ Py_ssize_t i;
+
+ tp = Py_TYPE(self);
assert(Py_TYPE(self)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- PyDictValues **values_ptr = _PyObject_ValuesPointer(self);
+ values_ptr = _PyObject_ValuesPointer(self);
if (*values_ptr == NULL) {
return 0;
}
- PyDictKeysObject *keys = CACHED_KEYS(tp);
- for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
+ keys = CACHED_KEYS(tp);
+ for (i = 0; i < keys->dk_nentries; i++) {
Py_VISIT((*values_ptr)->values[i]);
}
return 0;
@@ -5558,14 +5815,19 @@ _PyObject_VisitInstanceAttributes(PyObject *self, visitproc visit, void *arg)
void
_PyObject_ClearInstanceAttributes(PyObject *self)
{
- PyTypeObject *tp = Py_TYPE(self);
+ PyTypeObject *tp;
+ PyDictValues **values_ptr;
+ PyDictKeysObject *keys;
+ Py_ssize_t i;
+
+ tp = Py_TYPE(self);
assert(Py_TYPE(self)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- PyDictValues **values_ptr = _PyObject_ValuesPointer(self);
+ values_ptr = _PyObject_ValuesPointer(self);
if (*values_ptr == NULL) {
return;
}
- PyDictKeysObject *keys = CACHED_KEYS(tp);
- for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
+ keys = CACHED_KEYS(tp);
+ for (i = 0; i < keys->dk_nentries; i++) {
Py_CLEAR((*values_ptr)->values[i]);
}
}
@@ -5573,16 +5835,22 @@ _PyObject_ClearInstanceAttributes(PyObject *self)
void
_PyObject_FreeInstanceAttributes(PyObject *self)
{
- PyTypeObject *tp = Py_TYPE(self);
+ PyTypeObject *tp;
+ PyDictValues **values_ptr;
+ PyDictValues *values;
+ PyDictKeysObject *keys;
+ Py_ssize_t i;
+
+ tp = Py_TYPE(self);
assert(Py_TYPE(self)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
- PyDictValues **values_ptr = _PyObject_ValuesPointer(self);
- PyDictValues *values = *values_ptr;
+ values_ptr = _PyObject_ValuesPointer(self);
+ values = *values_ptr;
if (values == NULL) {
return;
}
*values_ptr = NULL;
- PyDictKeysObject *keys = CACHED_KEYS(tp);
- for (Py_ssize_t i = 0; i < keys->dk_nentries; i++) {
+ keys = CACHED_KEYS(tp);
+ for (i = 0; i < keys->dk_nentries; i++) {
Py_XDECREF(values->values[i]);
}
free_values(values);
@@ -5687,13 +5955,15 @@ static uint32_t next_dict_keys_version = 2;
uint32_t _PyDictKeys_GetVersionForCurrentState(PyDictKeysObject *dictkeys)
{
+ uint32_t v;
+
if (dictkeys->dk_version != 0) {
return dictkeys->dk_version;
}
if (next_dict_keys_version == 0) {
return 0;
}
- uint32_t v = next_dict_keys_version++;
+ v = next_dict_keys_version++;
dictkeys->dk_version = v;
return v;
}
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index d84bac6..718f239 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -328,7 +328,9 @@ PyTypeObject PyEnum_Type = {
PyType_GenericAlloc, /* tp_alloc */
enum_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_vectorcall = (vectorcallfunc)enumerate_vectorcall
+#endif
};
/* Reversed Object ***************************************************************/
@@ -398,11 +400,13 @@ static PyObject *
reversed_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
+ Py_ssize_t nargs;
+
if (!_PyArg_NoKwnames("reversed", kwnames)) {
return NULL;
}
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("reversed", nargs, 1, 1)) {
return NULL;
}
@@ -541,5 +545,16 @@ PyTypeObject PyReversed_Type = {
PyType_GenericAlloc, /* tp_alloc */
reversed_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
+#if !defined(MS_WINDOWS) || !defined(_MSC_VER) || _MSC_VER >= 1300
.tp_vectorcall = (vectorcallfunc)reversed_vectorcall,
+#endif
};
+
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+void
+_PyEnum_InitTypes(void)
+{
+ PyEnum_Type.tp_vectorcall = (vectorcallfunc)enumerate_vectorcall;
+ PyReversed_Type.tp_vectorcall = (vectorcallfunc)reversed_vectorcall;
+}
+#endif
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 86cabbf..59b9c4e 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -160,6 +160,7 @@ BaseException_setstate(PyObject *self, PyObject *state)
{
PyObject *d_key, *d_value;
Py_ssize_t i = 0;
+ int res;
if (state != Py_None) {
if (!PyDict_Check(state)) {
@@ -169,7 +170,7 @@ BaseException_setstate(PyObject *self, PyObject *state)
while (PyDict_Next(state, &i, &d_key, &d_value)) {
Py_INCREF(d_key);
Py_INCREF(d_value);
- int res = PyObject_SetAttr(self, d_key, d_value);
+ res = PyObject_SetAttr(self, d_key, d_value);
Py_DECREF(d_value);
Py_DECREF(d_key);
if (res < 0) {
@@ -203,6 +204,8 @@ _PyBaseExceptionObject_cast(PyObject *exc)
static PyObject *
BaseException_add_note(PyObject *self, PyObject *note)
{
+ PyObject *notes;
+
if (!PyUnicode_Check(note)) {
PyErr_Format(PyExc_TypeError,
"note must be a str, not '%s'",
@@ -210,7 +213,6 @@ BaseException_add_note(PyObject *self, PyObject *note)
return NULL;
}
- PyObject *notes;
if (_PyObject_LookupAttr(self, &_Py_ID(__notes__), &notes) < 0) {
return NULL;
}
@@ -698,12 +700,21 @@ _PyBaseExceptionGroupObject_cast(PyObject *exc)
static PyObject *
BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- struct _Py_exc_state *state = get_exc_state();
- PyTypeObject *PyExc_ExceptionGroup =
+ struct _Py_exc_state *state;
+ PyTypeObject *PyExc_ExceptionGroup;
+ PyObject *message, *exceptions, *exc;
+ Py_ssize_t numexcs, i;
+ bool nested_base_exceptions;
+ int is_nonbase_exception;
+ PyTypeObject *cls;
+ PyBaseExceptionGroupObject *self;
+
+ state = get_exc_state();
+ PyExc_ExceptionGroup =
(PyTypeObject*)state->PyExc_ExceptionGroup;
- PyObject *message = NULL;
- PyObject *exceptions = NULL;
+ message = NULL;
+ exceptions = NULL;
if (!PyArg_ParseTuple(args,
"UO:BaseExceptionGroup.__new__",
@@ -726,7 +737,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* We are now holding a ref to the exceptions tuple */
- Py_ssize_t numexcs = PyTuple_GET_SIZE(exceptions);
+ numexcs = PyTuple_GET_SIZE(exceptions);
if (numexcs == 0) {
PyErr_SetString(
PyExc_ValueError,
@@ -734,9 +745,9 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto error;
}
- bool nested_base_exceptions = false;
- for (Py_ssize_t i = 0; i < numexcs; i++) {
- PyObject *exc = PyTuple_GET_ITEM(exceptions, i);
+ nested_base_exceptions = false;
+ for (i = 0; i < numexcs; i++) {
+ exc = PyTuple_GET_ITEM(exceptions, i);
if (!exc) {
goto error;
}
@@ -747,7 +758,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
i);
goto error;
}
- int is_nonbase_exception = PyObject_IsInstance(exc, PyExc_Exception);
+ is_nonbase_exception = PyObject_IsInstance(exc, PyExc_Exception);
if (is_nonbase_exception < 0) {
goto error;
}
@@ -756,7 +767,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
- PyTypeObject *cls = type;
+ cls = type;
if (cls == PyExc_ExceptionGroup) {
if (nested_base_exceptions) {
PyErr_SetString(PyExc_TypeError,
@@ -794,8 +805,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
*/
cls = (PyTypeObject*)PyExc_BaseExceptionGroup;
}
- PyBaseExceptionGroupObject *self =
- _PyBaseExceptionGroupObject_cast(BaseException_new(cls, args, kwds));
+ self = _PyBaseExceptionGroupObject_cast(BaseException_new(cls, args, kwds));
if (!self) {
goto error;
}
@@ -811,16 +821,18 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject *
_PyExc_CreateExceptionGroup(const char *msg_str, PyObject *excs)
{
- PyObject *msg = PyUnicode_FromString(msg_str);
+ PyObject *msg, *args, *result;
+
+ msg = PyUnicode_FromString(msg_str);
if (!msg) {
return NULL;
}
- PyObject *args = PyTuple_Pack(2, msg, excs);
+ args = PyTuple_Pack(2, msg, excs);
Py_DECREF(msg);
if (!args) {
return NULL;
}
- PyObject *result = PyObject_CallObject(PyExc_BaseExceptionGroup, args);
+ result = PyObject_CallObject(PyExc_BaseExceptionGroup, args);
Py_DECREF(args);
return result;
}
@@ -866,11 +878,13 @@ BaseExceptionGroup_traverse(PyBaseExceptionGroupObject *self,
static PyObject *
BaseExceptionGroup_str(PyBaseExceptionGroupObject *self)
{
+ Py_ssize_t num_excs;
+
assert(self->msg);
assert(PyUnicode_Check(self->msg));
assert(PyTuple_CheckExact(self->excs));
- Py_ssize_t num_excs = PyTuple_Size(self->excs);
+ num_excs = PyTuple_Size(self->excs);
return PyUnicode_FromFormat(
"%S (%zd sub-exception%s)",
self->msg, num_excs, num_excs > 1 ? "s" : "");
@@ -879,16 +893,19 @@ BaseExceptionGroup_str(PyBaseExceptionGroupObject *self)
static PyObject *
BaseExceptionGroup_derive(PyObject *self_, PyObject *args)
{
- PyBaseExceptionGroupObject *self = _PyBaseExceptionGroupObject_cast(self_);
- PyObject *excs = NULL;
+ PyBaseExceptionGroupObject *self;
+ PyObject *excs, *init_args, *eg;
+
+ self = _PyBaseExceptionGroupObject_cast(self_);
+ excs = NULL;
if (!PyArg_ParseTuple(args, "O", &excs)) {
return NULL;
}
- PyObject *init_args = PyTuple_Pack(2, self->msg, excs);
+ init_args = PyTuple_Pack(2, self->msg, excs);
if (!init_args) {
return NULL;
}
- PyObject *eg = PyObject_CallObject(
+ eg = PyObject_CallObject(
PyExc_BaseExceptionGroup, init_args);
Py_DECREF(init_args);
return eg;
@@ -898,6 +915,10 @@ static int
exceptiongroup_subset(
PyBaseExceptionGroupObject *_orig, PyObject *excs, PyObject **result)
{
+ PyObject *orig, *eg, *tb, *notes, *notes_copy;
+ Py_ssize_t num_excs;
+ int res;
+
/* Sets *result to an ExceptionGroup wrapping excs with metadata from
* _orig. If excs is empty, sets *result to NULL.
* Returns 0 on success and -1 on error.
@@ -906,10 +927,10 @@ exceptiongroup_subset(
* so excs is the matching or non-matching sub-sequence of orig->excs
* (this function does not verify that it is a subsequence).
*/
- PyObject *orig = (PyObject *)_orig;
+ orig = (PyObject *)_orig;
*result = NULL;
- Py_ssize_t num_excs = PySequence_Size(excs);
+ num_excs = PySequence_Size(excs);
if (num_excs < 0) {
return -1;
}
@@ -917,7 +938,7 @@ exceptiongroup_subset(
return 0;
}
- PyObject *eg = PyObject_CallMethod(
+ eg = PyObject_CallMethod(
orig, "derive", "(O)", excs);
if (!eg) {
return -1;
@@ -931,9 +952,9 @@ exceptiongroup_subset(
/* Now we hold a reference to the new eg */
- PyObject *tb = PyException_GetTraceback(orig);
+ tb = PyException_GetTraceback(orig);
if (tb) {
- int res = PyException_SetTraceback(eg, tb);
+ res = PyException_SetTraceback(eg, tb);
Py_DECREF(tb);
if (res < 0) {
goto error;
@@ -942,19 +963,18 @@ exceptiongroup_subset(
PyException_SetContext(eg, PyException_GetContext(orig));
PyException_SetCause(eg, PyException_GetCause(orig));
- PyObject *notes;
if (_PyObject_LookupAttr(orig, &_Py_ID(__notes__), &notes) < 0) {
goto error;
}
if (notes) {
if (PySequence_Check(notes)) {
/* Make a copy so the parts have independent notes lists. */
- PyObject *notes_copy = PySequence_List(notes);
+ notes_copy = PySequence_List(notes);
Py_DECREF(notes);
if (notes_copy == NULL) {
goto error;
}
- int res = PyObject_SetAttr(eg, &_Py_ID(__notes__), notes_copy);
+ res = PyObject_SetAttr(eg, &_Py_ID(__notes__), notes_copy);
Py_DECREF(notes_copy);
if (res < 0) {
goto error;
@@ -992,6 +1012,8 @@ static int
get_matcher_type(PyObject *value,
_exceptiongroup_split_matcher_type *type)
{
+ Py_ssize_t n, i;
+
assert(value);
if (PyFunction_Check(value)) {
@@ -1005,8 +1027,8 @@ get_matcher_type(PyObject *value,
}
if (PyTuple_CheckExact(value)) {
- Py_ssize_t n = PyTuple_GET_SIZE(value);
- for (Py_ssize_t i=0; i<n; i++) {
+ n = PyTuple_GET_SIZE(value);
+ for (i = 0; i < n; i++) {
if (!PyExceptionClass_Check(PyTuple_GET_ITEM(value, i))) {
goto error;
}
@@ -1027,6 +1049,9 @@ exceptiongroup_split_check_match(PyObject *exc,
_exceptiongroup_split_matcher_type matcher_type,
PyObject *matcher_value)
{
+ PyObject *exc_matches, *exc_id;
+ int is_true, res;
+
switch (matcher_type) {
case EXCEPTION_GROUP_MATCH_BY_TYPE: {
assert(PyExceptionClass_Check(matcher_value) ||
@@ -1035,22 +1060,22 @@ exceptiongroup_split_check_match(PyObject *exc,
}
case EXCEPTION_GROUP_MATCH_BY_PREDICATE: {
assert(PyFunction_Check(matcher_value));
- PyObject *exc_matches = PyObject_CallOneArg(matcher_value, exc);
+ exc_matches = PyObject_CallOneArg(matcher_value, exc);
if (exc_matches == NULL) {
return -1;
}
- int is_true = PyObject_IsTrue(exc_matches);
+ is_true = PyObject_IsTrue(exc_matches);
Py_DECREF(exc_matches);
return is_true;
}
case EXCEPTION_GROUP_MATCH_INSTANCE_IDS: {
assert(PySet_Check(matcher_value));
if (!_PyBaseExceptionGroup_Check(exc)) {
- PyObject *exc_id = PyLong_FromVoidPtr(exc);
+ exc_id = PyLong_FromVoidPtr(exc);
if (exc_id == NULL) {
return -1;
}
- int res = PySet_Contains(matcher_value, exc_id);
+ res = PySet_Contains(matcher_value, exc_id);
Py_DECREF(exc_id);
return res;
}
@@ -1072,10 +1097,16 @@ exceptiongroup_split_recursive(PyObject *exc,
bool construct_rest,
_exceptiongroup_split_result *result)
{
+ int is_match, retval;
+ PyBaseExceptionGroupObject *eg;
+ Py_ssize_t num_excs, i;
+ PyObject *match_list, *rest_list, *e;
+ _exceptiongroup_split_result rec_result;
+
result->match = NULL;
result->rest = NULL;
- int is_match = exceptiongroup_split_check_match(
+ is_match = exceptiongroup_split_check_match(
exc, matcher_type, matcher_value);
if (is_match < 0) {
return -1;
@@ -1096,21 +1127,21 @@ exceptiongroup_split_recursive(PyObject *exc,
/* Partial match */
- PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc);
+ eg = _PyBaseExceptionGroupObject_cast(exc);
assert(PyTuple_CheckExact(eg->excs));
- Py_ssize_t num_excs = PyTuple_Size(eg->excs);
+ num_excs = PyTuple_Size(eg->excs);
if (num_excs < 0) {
return -1;
}
assert(num_excs > 0); /* checked in constructor, and excs is read-only */
- int retval = -1;
- PyObject *match_list = PyList_New(0);
+ retval = -1;
+ match_list = PyList_New(0);
if (!match_list) {
return -1;
}
- PyObject *rest_list = NULL;
+ rest_list = NULL;
if (construct_rest) {
rest_list = PyList_New(0);
if (!rest_list) {
@@ -1118,9 +1149,8 @@ exceptiongroup_split_recursive(PyObject *exc,
}
}
/* recursive calls */
- for (Py_ssize_t i = 0; i < num_excs; i++) {
- PyObject *e = PyTuple_GET_ITEM(eg->excs, i);
- _exceptiongroup_split_result rec_result;
+ for (i = 0; i < num_excs; i++) {
+ e = PyTuple_GET_ITEM(eg->excs, i);
if (_Py_EnterRecursiveCall(" in exceptiongroup_split_recursive")) {
goto done;
}
@@ -1179,25 +1209,27 @@ exceptiongroup_split_recursive(PyObject *exc,
static PyObject *
BaseExceptionGroup_split(PyObject *self, PyObject *args)
{
- PyObject *matcher_value = NULL;
+ PyObject *matcher_value = NULL, *result;
+ _exceptiongroup_split_matcher_type matcher_type;
+ _exceptiongroup_split_result split_result;
+ bool construct_rest;
+
if (!PyArg_UnpackTuple(args, "split", 1, 1, &matcher_value)) {
return NULL;
}
- _exceptiongroup_split_matcher_type matcher_type;
if (get_matcher_type(matcher_value, &matcher_type) < 0) {
return NULL;
}
- _exceptiongroup_split_result split_result;
- bool construct_rest = true;
+ construct_rest = true;
if (exceptiongroup_split_recursive(
self, matcher_type, matcher_value,
construct_rest, &split_result) < 0) {
return NULL;
}
- PyObject *result = PyTuple_Pack(
+ result = PyTuple_Pack(
2,
split_result.match ? split_result.match : Py_None,
split_result.rest ? split_result.rest : Py_None);
@@ -1210,25 +1242,27 @@ BaseExceptionGroup_split(PyObject *self, PyObject *args)
static PyObject *
BaseExceptionGroup_subgroup(PyObject *self, PyObject *args)
{
- PyObject *matcher_value = NULL;
+ PyObject *matcher_value = NULL, *result;
+ _exceptiongroup_split_matcher_type matcher_type;
+ _exceptiongroup_split_result split_result;
+ bool construct_rest;
+
if (!PyArg_UnpackTuple(args, "subgroup", 1, 1, &matcher_value)) {
return NULL;
}
- _exceptiongroup_split_matcher_type matcher_type;
if (get_matcher_type(matcher_value, &matcher_type) < 0) {
return NULL;
}
- _exceptiongroup_split_result split_result;
- bool construct_rest = false;
+ construct_rest = false;
if (exceptiongroup_split_recursive(
self, matcher_type, matcher_value,
construct_rest, &split_result) < 0) {
return NULL;
}
- PyObject *result = Py_NewRef(
+ result = Py_NewRef(
split_result.match ? split_result.match : Py_None);
Py_XDECREF(split_result.match);
@@ -1239,6 +1273,11 @@ BaseExceptionGroup_subgroup(PyObject *self, PyObject *args)
static int
collect_exception_group_leaf_ids(PyObject *exc, PyObject *leaf_ids)
{
+ PyObject *exc_id, *e;
+ PyBaseExceptionGroupObject *eg;
+ Py_ssize_t num_excs, i;
+ int res;
+
if (Py_IsNone(exc)) {
return 0;
}
@@ -1249,23 +1288,22 @@ collect_exception_group_leaf_ids(PyObject *exc, PyObject *leaf_ids)
/* Add IDs of all leaf exceptions in exc to the leaf_ids set */
if (!_PyBaseExceptionGroup_Check(exc)) {
- PyObject *exc_id = PyLong_FromVoidPtr(exc);
+ exc_id = PyLong_FromVoidPtr(exc);
if (exc_id == NULL) {
return -1;
}
- int res = PySet_Add(leaf_ids, exc_id);
+ res = PySet_Add(leaf_ids, exc_id);
Py_DECREF(exc_id);
return res;
}
- PyBaseExceptionGroupObject *eg = _PyBaseExceptionGroupObject_cast(exc);
- Py_ssize_t num_excs = PyTuple_GET_SIZE(eg->excs);
- /* recursive calls */
- for (Py_ssize_t i = 0; i < num_excs; i++) {
- PyObject *e = PyTuple_GET_ITEM(eg->excs, i);
+ eg = _PyBaseExceptionGroupObject_cast(exc);
+ num_excs = PyTuple_GET_SIZE(eg->excs);
+ for (i = 0; i < num_excs; i++) {
+ e = PyTuple_GET_ITEM(eg->excs, i);
if (_Py_EnterRecursiveCall(" in collect_exception_group_leaf_ids")) {
return -1;
}
- int res = collect_exception_group_leaf_ids(e, leaf_ids);
+ res = collect_exception_group_leaf_ids(e, leaf_ids);
_Py_LeaveRecursiveCall();
if (res < 0) {
return -1;
@@ -1283,17 +1321,23 @@ collect_exception_group_leaf_ids(PyObject *exc, PyObject *leaf_ids)
static PyObject *
exception_group_projection(PyObject *eg, PyObject *keep)
{
+ PyObject *leaf_ids, *e, *result;
+ Py_ssize_t n, i;
+ _exceptiongroup_split_result split_result;
+ bool construct_rest;
+ int err;
+
assert(_PyBaseExceptionGroup_Check(eg));
assert(PyList_CheckExact(keep));
- PyObject *leaf_ids = PySet_New(NULL);
+ leaf_ids = PySet_New(NULL);
if (!leaf_ids) {
return NULL;
}
- Py_ssize_t n = PyList_GET_SIZE(keep);
- for (Py_ssize_t i = 0; i < n; i++) {
- PyObject *e = PyList_GET_ITEM(keep, i);
+ n = PyList_GET_SIZE(keep);
+ for (i = 0; i < n; i++) {
+ e = PyList_GET_ITEM(keep, i);
assert(e != NULL);
assert(_PyBaseExceptionGroup_Check(e));
if (collect_exception_group_leaf_ids(e, leaf_ids) < 0) {
@@ -1302,9 +1346,8 @@ exception_group_projection(PyObject *eg, PyObject *keep)
}
}
- _exceptiongroup_split_result split_result;
- bool construct_rest = false;
- int err = exceptiongroup_split_recursive(
+ construct_rest = false;
+ err = exceptiongroup_split_recursive(
eg, EXCEPTION_GROUP_MATCH_INSTANCE_IDS, leaf_ids,
construct_rest, &split_result);
Py_DECREF(leaf_ids);
@@ -1312,7 +1355,7 @@ exception_group_projection(PyObject *eg, PyObject *keep)
return NULL;
}
- PyObject *result = split_result.match ?
+ result = split_result.match ?
split_result.match : Py_NewRef(Py_None);
assert(split_result.rest == NULL);
return result;
@@ -1321,11 +1364,13 @@ exception_group_projection(PyObject *eg, PyObject *keep)
static bool
is_same_exception_metadata(PyObject *exc1, PyObject *exc2)
{
+ PyBaseExceptionObject *e1, *e2;
+
assert(PyExceptionInstance_Check(exc1));
assert(PyExceptionInstance_Check(exc2));
- PyBaseExceptionObject *e1 = (PyBaseExceptionObject *)exc1;
- PyBaseExceptionObject *e2 = (PyBaseExceptionObject *)exc2;
+ e1 = (PyBaseExceptionObject *)exc1;
+ e2 = (PyBaseExceptionObject *)exc2;
return (e1->notes == e2->notes &&
e1->traceback == e2->traceback &&
@@ -1352,10 +1397,16 @@ is_same_exception_metadata(PyObject *exc1, PyObject *exc2)
PyObject *
_PyExc_PrepReraiseStar(PyObject *orig, PyObject *excs)
{
+ Py_ssize_t numexcs, i, num_raised;
+ PyObject *e, *raised_list, *reraised_list, *result, *append_list;
+ PyObject *reraised_eg;
+ bool is_reraise;
+ int res;
+
assert(PyExceptionInstance_Check(orig));
assert(PyList_Check(excs));
- Py_ssize_t numexcs = PyList_GET_SIZE(excs);
+ numexcs = PyList_GET_SIZE(excs);
if (numexcs == 0) {
return Py_NewRef(Py_None);
@@ -1368,16 +1419,16 @@ _PyExc_PrepReraiseStar(PyObject *orig, PyObject *excs)
assert(numexcs == 1 || (numexcs == 2 && PyList_GET_ITEM(excs, 1) == Py_None));
- PyObject *e = PyList_GET_ITEM(excs, 0);
+ e = PyList_GET_ITEM(excs, 0);
assert(e != NULL);
return Py_NewRef(e);
}
- PyObject *raised_list = PyList_New(0);
+ raised_list = PyList_New(0);
if (raised_list == NULL) {
return NULL;
}
- PyObject* reraised_list = PyList_New(0);
+ reraised_list = PyList_New(0);
if (reraised_list == NULL) {
Py_DECREF(raised_list);
return NULL;
@@ -1385,23 +1436,23 @@ _PyExc_PrepReraiseStar(PyObject *orig, PyObject *excs)
/* Now we are holding refs to raised_list and reraised_list */
- PyObject *result = NULL;
+ result = NULL;
/* Split excs into raised and reraised by comparing metadata with orig */
- for (Py_ssize_t i = 0; i < numexcs; i++) {
- PyObject *e = PyList_GET_ITEM(excs, i);
+ for (i = 0; i < numexcs; i++) {
+ e = PyList_GET_ITEM(excs, i);
assert(e != NULL);
if (Py_IsNone(e)) {
continue;
}
- bool is_reraise = is_same_exception_metadata(e, orig);
- PyObject *append_list = is_reraise ? reraised_list : raised_list;
+ is_reraise = is_same_exception_metadata(e, orig);
+ append_list = is_reraise ? reraised_list : raised_list;
if (PyList_Append(append_list, e) < 0) {
goto done;
}
}
- PyObject *reraised_eg = exception_group_projection(orig, reraised_list);
+ reraised_eg = exception_group_projection(orig, reraised_list);
if (reraised_eg == NULL) {
goto done;
}
@@ -1409,12 +1460,12 @@ _PyExc_PrepReraiseStar(PyObject *orig, PyObject *excs)
if (!Py_IsNone(reraised_eg)) {
assert(is_same_exception_metadata(reraised_eg, orig));
}
- Py_ssize_t num_raised = PyList_GET_SIZE(raised_list);
+ num_raised = PyList_GET_SIZE(raised_list);
if (num_raised == 0) {
result = reraised_eg;
}
else if (num_raised > 0) {
- int res = 0;
+ res = 0;
if (!Py_IsNone(reraised_eg)) {
res = PyList_Append(raised_list, reraised_eg);
}
@@ -1467,9 +1518,12 @@ ComplexExtendsException(PyExc_BaseException, BaseExceptionGroup,
*/
static PyObject*
create_exception_group_class(void) {
- struct _Py_exc_state *state = get_exc_state();
+ struct _Py_exc_state *state;
+ PyObject *bases;
+
+ state = get_exc_state();
- PyObject *bases = PyTuple_Pack(
+ bases = PyTuple_Pack(
2, PyExc_BaseExceptionGroup, PyExc_Exception);
if (bases == NULL) {
return NULL;
@@ -1820,6 +1874,7 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyOSErrorObject *self = NULL;
PyObject *myerrno = NULL, *strerror = NULL;
PyObject *filename = NULL, *filename2 = NULL;
+ struct _Py_exc_state *state;
#ifdef MS_WINDOWS
PyObject *winerror = NULL;
#endif
@@ -1838,7 +1893,7 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
))
goto error;
- struct _Py_exc_state *state = get_exc_state();
+ state = get_exc_state();
if (myerrno && PyLong_Check(myerrno) &&
state->errnomap && (PyObject *) type == PyExc_OSError) {
PyObject *newtype;
@@ -2062,6 +2117,8 @@ OSError_written_get(PyOSErrorObject *self, void *context)
static int
OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context)
{
+ Py_ssize_t n;
+
if (arg == NULL) {
if (self->written == -1) {
PyErr_SetString(PyExc_AttributeError, "characters_written");
@@ -2070,7 +2127,6 @@ OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context)
self->written = -1;
return 0;
}
- Py_ssize_t n;
n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
if (n == -1 && PyErr_Occurred())
return -1;
@@ -2181,12 +2237,13 @@ NameError_init(PyNameErrorObject *self, PyObject *args, PyObject *kwds)
{
static char *kwlist[] = {"name", NULL};
PyObject *name = NULL;
+ PyObject *empty_tuple;
if (BaseException_init((PyBaseExceptionObject *)self, args, NULL) == -1) {
return -1;
}
- PyObject *empty_tuple = PyTuple_New(0);
+ empty_tuple = PyTuple_New(0);
if (!empty_tuple) {
return -1;
}
@@ -2256,12 +2313,13 @@ AttributeError_init(PyAttributeErrorObject *self, PyObject *args, PyObject *kwds
static char *kwlist[] = {"name", "obj", NULL};
PyObject *name = NULL;
PyObject *obj = NULL;
+ PyObject *empty_tuple;
if (BaseException_init((PyBaseExceptionObject *)self, args, NULL) == -1) {
return -1;
}
- PyObject *empty_tuple = PyTuple_New(0);
+ empty_tuple = PyTuple_New(0);
if (!empty_tuple) {
return -1;
}
@@ -3238,6 +3296,7 @@ static PyObject *
MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyBaseExceptionObject *self;
+ struct _Py_exc_state *state;
/* If this is a subclass of MemoryError, don't use the freelist
* and just return a fresh object */
@@ -3245,7 +3304,7 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return BaseException_new(type, args, kwds);
}
- struct _Py_exc_state *state = get_exc_state();
+ state = get_exc_state();
if (state->memerrors_freelist == NULL) {
return BaseException_new(type, args, kwds);
}
@@ -3270,6 +3329,8 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
MemoryError_dealloc(PyBaseExceptionObject *self)
{
+ struct _Py_exc_state *state;
+
_PyObject_GC_UNTRACK(self);
BaseException_clear(self);
@@ -3281,7 +3342,7 @@ MemoryError_dealloc(PyBaseExceptionObject *self)
return;
}
- struct _Py_exc_state *state = get_exc_state();
+ state = get_exc_state();
if (state->memerrors_numfree >= MEMERRORS_SAVE) {
Py_TYPE(self)->tp_free((PyObject *)self);
}
@@ -3591,12 +3652,15 @@ static struct static_exception static_exceptions[] = {
int
_PyExc_InitTypes(PyInterpreterState *interp)
{
+ size_t i;
+ PyTypeObject *exc;
+
if (!_Py_IsMainInterpreter(interp)) {
return 0;
}
- for (size_t i=0; i < Py_ARRAY_LENGTH(static_exceptions); i++) {
- PyTypeObject *exc = static_exceptions[i].exc;
+ for (i = 0; i < Py_ARRAY_LENGTH(static_exceptions); i++) {
+ exc = static_exceptions[i].exc;
if (PyType_Ready(exc) < 0) {
return -1;
@@ -3609,12 +3673,15 @@ _PyExc_InitTypes(PyInterpreterState *interp)
static void
_PyExc_FiniTypes(PyInterpreterState *interp)
{
+ Py_ssize_t i;
+ PyTypeObject *exc;
+
if (!_Py_IsMainInterpreter(interp)) {
return;
}
- for (Py_ssize_t i=Py_ARRAY_LENGTH(static_exceptions) - 1; i >= 0; i--) {
- PyTypeObject *exc = static_exceptions[i].exc;
+ for (i = Py_ARRAY_LENGTH(static_exceptions) - 1; i >= 0; i--) {
+ exc = static_exceptions[i].exc;
_PyStaticType_Dealloc(exc);
}
}
@@ -3693,20 +3760,24 @@ _PyExc_InitState(PyInterpreterState *interp)
int
_PyBuiltins_AddExceptions(PyObject *bltinmod)
{
- PyObject *mod_dict = PyModule_GetDict(bltinmod);
+ PyObject *mod_dict, *PyExc_ExceptionGroup;
+ struct static_exception item;
+ size_t i;
+
+ mod_dict = PyModule_GetDict(bltinmod);
if (mod_dict == NULL) {
return -1;
}
- for (size_t i=0; i < Py_ARRAY_LENGTH(static_exceptions); i++) {
- struct static_exception item = static_exceptions[i];
+ for (i = 0; i < Py_ARRAY_LENGTH(static_exceptions); i++) {
+ item = static_exceptions[i];
if (PyDict_SetItemString(mod_dict, item.name, (PyObject*)item.exc)) {
return -1;
}
}
- PyObject *PyExc_ExceptionGroup = create_exception_group_class();
+ PyExc_ExceptionGroup = create_exception_group_class();
if (!PyExc_ExceptionGroup) {
return -1;
}
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index ffe55eb..7287abd 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -499,6 +499,7 @@ PyFile_SetOpenCodeHook(Py_OpenCodeHookFunction hook, void *userData) {
PyObject *
PyFile_OpenCodeObject(PyObject *path)
{
+ Py_OpenCodeHookFunction hook;
PyObject *iomod, *f = NULL;
if (!PyUnicode_Check(path)) {
@@ -507,7 +508,7 @@ PyFile_OpenCodeObject(PyObject *path)
return NULL;
}
- Py_OpenCodeHookFunction hook = _PyRuntime.open_code_hook;
+ hook = _PyRuntime.open_code_hook;
if (hook) {
f = hook(path, _PyRuntime.open_code_userdata);
} else {
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 29a74f2..4a7c392 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -254,10 +254,15 @@ PyFloat_FromString(PyObject *v)
void
_PyFloat_ExactDealloc(PyObject *obj)
{
+ PyFloatObject *op;
+#if PyFloat_MAXFREELIST > 0
+ struct _Py_float_state *state;
+#endif
+
assert(PyFloat_CheckExact(obj));
- PyFloatObject *op = (PyFloatObject *)obj;
+ op = (PyFloatObject *)obj;
#if PyFloat_MAXFREELIST > 0
- struct _Py_float_state *state = get_float_state();
+ state = get_float_state();
#ifdef Py_DEBUG
// float_dealloc() must not be called after _PyFloat_Fini()
assert(state->numfree != -1);
@@ -309,11 +314,11 @@ PyFloat_AsDouble(PyObject *op)
nb = Py_TYPE(op)->tp_as_number;
if (nb == NULL || nb->nb_float == NULL) {
if (nb && nb->nb_index) {
- PyObject *res = _PyNumber_Index(op);
+ res = _PyNumber_Index(op);
if (!res) {
return -1;
}
- double val = PyLong_AsDouble(res);
+ val = PyLong_AsDouble(res);
Py_DECREF(res);
return val;
}
@@ -1703,16 +1708,19 @@ static PyObject *
float_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
+ Py_ssize_t nargs;
+ PyObject *x;
+
if (!_PyArg_NoKwnames("float", kwnames)) {
return NULL;
}
- Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
+ nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("float", nargs, 0, 1)) {
return NULL;
}
- PyObject *x = nargs >= 1 ? args[0] : NULL;
+ x = nargs >= 1 ? args[0] : NULL;
return float_new_impl(_PyType_CAST(type), x);
}
@@ -1932,18 +1940,28 @@ PyTypeObject PyFloat_Type = {
0, /* tp_init */
0, /* tp_alloc */
float_new, /* tp_new */
- .tp_vectorcall = (vectorcallfunc)float_vectorcall,
+ 0, /* tp_free */
+ 0, /* tp_is_gc */
+ 0, /* tp_bases */
+ 0, /* tp_mro */
+ 0, /* tp_cache */
+ 0, /* tp_subclasses */
+ 0, /* tp_weaklist */
+ 0, /* tp_del */
+ 0, /* tp_version_tag */
+ 0, /* tp_finalize */
+ (vectorcallfunc)float_vectorcall, /* tp_vectorcall */
};
void
_PyFloat_InitState(PyInterpreterState *interp)
{
+ float_format_type detected_double_format, detected_float_format;
+
if (!_Py_IsMainInterpreter(interp)) {
return;
}
- float_format_type detected_double_format, detected_float_format;
-
/* We attempt to determine if this machine is using IEEE
floating point formats by peering at the bits of some
carefully chosen values. If it looks like we are on an
@@ -2256,13 +2274,13 @@ PyFloat_Pack4(double x, char *data, int le)
}
else {
+ unsigned char s[sizeof(float)];
float y = (float)x;
int i, incr = 1;
if (Py_IS_INFINITY(y) && !Py_IS_INFINITY(x))
goto Overflow;
- unsigned char s[sizeof(float)];
memcpy(s, &y, sizeof(float));
if ((float_format == ieee_little_endian_format && !le)
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index c95e871..5c2f86f 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -25,9 +25,11 @@ static PyMemberDef frame_memberlist[] = {
static PyObject *
frame_getlocals(PyFrameObject *f, void *closure)
{
+ PyObject *locals;
+
if (PyFrame_FastToLocalsWithError(f) < 0)
return NULL;
- PyObject *locals = f->f_frame->f_locals;
+ locals = f->f_frame->f_locals;
Py_INCREF(locals);
return locals;
}
@@ -161,7 +163,7 @@ compatible_kind(Kind from, Kind to) {
#define OVERFLOWED -1
#define MAX_STACK_ENTRIES (63/BITS_PER_BLOCK)
-#define WILL_OVERFLOW (1ULL<<((MAX_STACK_ENTRIES-1)*BITS_PER_BLOCK))
+#define WILL_OVERFLOW (PY_ULL(1)<<((MAX_STACK_ENTRIES-1)*BITS_PER_BLOCK))
#define EMPTY_STACK 0
@@ -200,22 +202,28 @@ peek(int64_t stack, int n)
static Kind
stack_swap(int64_t stack, int n)
{
+ Kind to_swap, top;
+ int shift;
+ int64_t replaced_low, replaced_top;
+
assert(n >= 1);
- Kind to_swap = peek(stack, n);
- Kind top = top_of_stack(stack);
- int shift = BITS_PER_BLOCK*(n-1);
- int64_t replaced_low = (stack & ~(MASK << shift)) | (top << shift);
- int64_t replaced_top = (replaced_low & ~MASK) | to_swap;
+ to_swap = peek(stack, n);
+ top = top_of_stack(stack);
+ shift = BITS_PER_BLOCK*(n-1);
+ replaced_low = (stack & ~(MASK << shift)) | (top << shift);
+ replaced_top = (replaced_low & ~MASK) | to_swap;
return replaced_top;
}
static int64_t
pop_to_level(int64_t stack, int level) {
+ int64_t max_item, level_max_stack;
+
if (level == 0) {
return EMPTY_STACK;
}
- int64_t max_item = (1<<BITS_PER_BLOCK) - 1;
- int64_t level_max_stack = max_item << ((level-1) * BITS_PER_BLOCK);
+ max_item = (1<<BITS_PER_BLOCK) - 1;
+ level_max_stack = max_item << ((level-1) * BITS_PER_BLOCK);
while (stack > level_max_stack) {
stack = pop_value(stack);
}
@@ -276,20 +284,29 @@ print_stacks(int64_t *stacks, int n) {
static int64_t *
mark_stacks(PyCodeObject *code_obj, int len)
{
- PyObject *co_code = _PyCode_GetCode(code_obj);
+ PyObject *co_code;
+ _Py_CODEUNIT *code;
+ int64_t *stacks;
+ int i, j, opcode, todo;
+ int64_t next_stack, target_stack;
+ int n, delta;
+ unsigned char *start, *end, *scan;
+ int start_offset, size, handler, depth_and_lasti, level, lasti;
+ uint64_t exception_target_stack;
+
+ co_code = _PyCode_GetCode(code_obj);
if (co_code == NULL) {
return NULL;
}
- _Py_CODEUNIT *code = (_Py_CODEUNIT *)PyBytes_AS_STRING(co_code);
- int64_t *stacks = PyMem_New(int64_t, len+1);
- int i, j, opcode;
+ code = (_Py_CODEUNIT *)PyBytes_AS_STRING(co_code);
+ stacks = PyMem_New(int64_t, len+1);
if (stacks == NULL) {
PyErr_NoMemory();
Py_DECREF(co_code);
return NULL;
}
- for (int i = 1; i <= len; i++) {
+ for (i = 1; i <= len; i++) {
stacks[i] = UNINITIALIZED;
}
stacks[0] = EMPTY_STACK;
@@ -298,12 +315,12 @@ mark_stacks(PyCodeObject *code_obj, int len)
// Generators get sent None while starting:
stacks[0] = push_value(stacks[0], Object);
}
- int todo = 1;
+ todo = 1;
while (todo) {
todo = 0;
/* Scan instructions */
for (i = 0; i < len; i++) {
- int64_t next_stack = stacks[i];
+ next_stack = stacks[i];
if (next_stack == UNINITIALIZED) {
continue;
}
@@ -320,8 +337,7 @@ mark_stacks(PyCodeObject *code_obj, int len)
case POP_JUMP_FORWARD_IF_NOT_NONE:
case POP_JUMP_BACKWARD_IF_NOT_NONE:
{
- int64_t target_stack;
- int j = get_arg(code, i);
+ j = get_arg(code, i);
if (opcode == POP_JUMP_FORWARD_IF_FALSE ||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == JUMP_IF_FALSE_OR_POP ||
@@ -388,7 +404,7 @@ mark_stacks(PyCodeObject *code_obj, int len)
break;
case FOR_ITER:
{
- int64_t target_stack = pop_value(next_stack);
+ target_stack = pop_value(next_stack);
stacks[i+1] = push_value(next_stack, Object);
j = get_arg(code, i) + i + 1;
assert(j < len);
@@ -446,21 +462,21 @@ mark_stacks(PyCodeObject *code_obj, int len)
}
case SWAP:
{
- int n = get_arg(code, i);
+ n = get_arg(code, i);
next_stack = stack_swap(next_stack, n);
stacks[i+1] = next_stack;
break;
}
case COPY:
{
- int n = get_arg(code, i);
+ n = get_arg(code, i);
next_stack = push_value(next_stack, peek(next_stack, n));
stacks[i+1] = next_stack;
break;
}
default:
{
- int delta = PyCompile_OpcodeStackEffect(opcode, get_arg(code, i));
+ delta = PyCompile_OpcodeStackEffect(opcode, get_arg(code, i));
assert(delta != PY_INVALID_STACK_EFFECT);
while (delta < 0) {
next_stack = pop_value(next_stack);
@@ -475,30 +491,28 @@ mark_stacks(PyCodeObject *code_obj, int len)
}
}
/* Scan exception table */
- unsigned char *start = (unsigned char *)PyBytes_AS_STRING(code_obj->co_exceptiontable);
- unsigned char *end = start + PyBytes_GET_SIZE(code_obj->co_exceptiontable);
- unsigned char *scan = start;
+ start = (unsigned char *)PyBytes_AS_STRING(code_obj->co_exceptiontable);
+ end = start + PyBytes_GET_SIZE(code_obj->co_exceptiontable);
+ scan = start;
while (scan < end) {
- int start_offset, size, handler;
scan = parse_varint(scan, &start_offset);
assert(start_offset >= 0 && start_offset < len);
scan = parse_varint(scan, &size);
assert(size >= 0 && start_offset+size <= len);
scan = parse_varint(scan, &handler);
assert(handler >= 0 && handler < len);
- int depth_and_lasti;
scan = parse_varint(scan, &depth_and_lasti);
- int level = depth_and_lasti >> 1;
- int lasti = depth_and_lasti & 1;
+ level = depth_and_lasti >> 1;
+ lasti = depth_and_lasti & 1;
if (stacks[start_offset] != UNINITIALIZED) {
if (stacks[handler] == UNINITIALIZED) {
todo = 1;
- uint64_t target_stack = pop_to_level(stacks[start_offset], level);
+ exception_target_stack = pop_to_level(stacks[start_offset], level);
if (lasti) {
- target_stack = push_value(target_stack, Lasti);
+ exception_target_stack = push_value(exception_target_stack, Lasti);
}
- target_stack = push_value(target_stack, Except);
- stacks[handler] = target_stack;
+ exception_target_stack = push_value(exception_target_stack, Except);
+ stacks[handler] = exception_target_stack;
}
}
}
@@ -531,6 +545,8 @@ compatible_stack(int64_t from_stack, int64_t to_stack)
static const char *
explain_incompatible_stack(int64_t to_stack)
{
+ Kind target_kind;
+
assert(to_stack != 0);
if (to_stack == OVERFLOWED) {
return "stack is too deep to analyze";
@@ -538,7 +554,7 @@ explain_incompatible_stack(int64_t to_stack)
if (to_stack == UNINITIALIZED) {
return "can't jump into an exception handler, or code may be unreachable";
}
- Kind target_kind = top_of_stack(to_stack);
+ target_kind = top_of_stack(to_stack);
switch(target_kind) {
case Except:
return "can't jump into an 'except' block as there's no exception";
@@ -558,15 +574,19 @@ static int *
marklines(PyCodeObject *code, int len)
{
PyCodeAddressRange bounds;
+ int last_line;
+ int *linestarts;
+ int i;
+
_PyCode_InitAddressRange(code, &bounds);
assert (bounds.ar_end == 0);
- int last_line = -1;
+ last_line = -1;
- int *linestarts = PyMem_New(int, len);
+ linestarts = PyMem_New(int, len);
if (linestarts == NULL) {
return NULL;
}
- for (int i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
linestarts[i] = -1;
}
@@ -583,8 +603,10 @@ marklines(PyCodeObject *code, int len)
static int
first_line_not_before(int *lines, int len, int line)
{
- int result = INT_MAX;
- for (int i = 0; i < len; i++) {
+ int result, i;
+
+ result = INT_MAX;
+ for (i = 0; i < len; i++) {
if (lines[i] < result && lines[i] >= line) {
result = lines[i];
}
@@ -648,6 +670,8 @@ _PyFrame_GetState(PyFrameObject *frame)
static int
frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignored))
{
+ int i;
+
if (p_new_lineno == NULL) {
PyErr_SetString(PyExc_AttributeError, "cannot delete attribute");
return -1;
@@ -748,7 +772,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno, void *Py_UNUSED(ignore
int64_t start_stack = stacks[_PyInterpreterFrame_LASTI(f->f_frame)];
int err = -1;
const char *msg = "cannot find bytecode for specified line";
- for (int i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
if (lines[i] == new_lineno) {
int64_t target_stack = stacks[i];
if (compatible_stack(start_stack, target_stack)) {
diff --git a/Objects/object.c b/Objects/object.c
index c4f2786..72ba7d5 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -30,6 +30,13 @@ extern "C" {
/* Defined in tracemalloc.c */
extern void _PyMem_DumpTraceback(int fd, const void *ptr);
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+extern void _PyClassObject_InitTypes(void);
+extern void _PyDesc_InitTypes(void);
+extern void _PyDict_InitTypes(void);
+extern void _PyEnum_InitTypes(void);
+#endif
+
int
_PyObject_CheckConsistency(PyObject *op, int check_content)
@@ -1980,6 +1987,13 @@ _PyTypes_InitTypes(PyInterpreterState *interp)
return _PyStatus_OK();
}
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
+ _PyClassObject_InitTypes();
+ _PyDesc_InitTypes();
+ _PyDict_InitTypes();
+ _PyEnum_InitTypes();
+#endif
+
// All other static types (unless initialized elsewhere)
for (size_t i=0; i < Py_ARRAY_LENGTH(static_types); i++) {
PyTypeObject *type = static_types[i];
diff --git a/Objects/stringlib/eq.h b/Objects/stringlib/eq.h
index 9c1058b..11ea17d 100644
--- a/Objects/stringlib/eq.h
+++ b/Objects/stringlib/eq.h
@@ -6,13 +6,16 @@
Py_LOCAL_INLINE(int)
unicode_eq(PyObject *aa, PyObject *bb)
{
+ PyUnicodeObject *a;
+ PyUnicodeObject *b;
+
assert(PyUnicode_Check(aa));
assert(PyUnicode_Check(bb));
assert(PyUnicode_IS_READY(aa));
assert(PyUnicode_IS_READY(bb));
- PyUnicodeObject *a = (PyUnicodeObject *)aa;
- PyUnicodeObject *b = (PyUnicodeObject *)bb;
+ a = (PyUnicodeObject *)aa;
+ b = (PyUnicodeObject *)bb;
if (PyUnicode_GET_LENGTH(a) != PyUnicode_GET_LENGTH(b))
return 0;
diff --git a/Objects/stringlib/fastsearch.h b/Objects/stringlib/fastsearch.h
index 7403d8a..9912f15 100644
--- a/Objects/stringlib/fastsearch.h
+++ b/Objects/stringlib/fastsearch.h
@@ -169,15 +169,15 @@ STRINGLIB(rfind_char)(const STRINGLIB_CHAR* s, Py_ssize_t n, STRINGLIB_CHAR ch)
/* Change to a 1 to see logging comments walk through the algorithm. */
#if 0 && STRINGLIB_SIZEOF_CHAR == 1
-# define LOG(...) printf(__VA_ARGS__)
+# define LOG(args) printf args
# define LOG_STRING(s, n) printf("\"%.*s\"", (int)(n), s)
# define LOG_LINEUP() do { \
- LOG("> "); LOG_STRING(haystack, len_haystack); LOG("\n> "); \
- LOG("%*s",(int)(window_last - haystack + 1 - len_needle), ""); \
- LOG_STRING(needle, len_needle); LOG("\n"); \
+ LOG(("> ")); LOG_STRING(haystack, len_haystack); LOG(("\n> ")); \
+ LOG(("%*s",(int)(window_last - haystack + 1 - len_needle), "")); \
+ LOG_STRING(needle, len_needle); LOG(("\n")); \
} while(0)
#else
-# define LOG(...)
+# define LOG(args) ((void)0)
# define LOG_STRING(s, n)
# define LOG_LINEUP()
#endif
@@ -285,9 +285,9 @@ STRINGLIB(_factorize)(const STRINGLIB_CHAR *needle,
cut = cut2;
}
- LOG("split: "); LOG_STRING(needle, cut);
- LOG(" + "); LOG_STRING(needle + cut, len_needle - cut);
- LOG("\n");
+ LOG(("split: ")); LOG_STRING(needle, cut);
+ LOG((" + ")); LOG_STRING(needle + cut, len_needle - cut);
+ LOG(("\n"));
*return_period = period;
return cut;
@@ -316,6 +316,10 @@ static void
STRINGLIB(_preprocess)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
STRINGLIB(prework) *p)
{
+ Py_ssize_t i;
+ STRINGLIB_CHAR last;
+ Py_ssize_t not_found_shift;
+
p->needle = needle;
p->len_needle = len_needle;
p->cut = STRINGLIB(_factorize)(needle, len_needle, &(p->period));
@@ -334,8 +338,8 @@ STRINGLIB(_preprocess)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
// The gap between the last character and the previous
// occurrence of an equivalent character (modulo TABLE_SIZE)
p->gap = len_needle;
- STRINGLIB_CHAR last = needle[len_needle - 1] & TABLE_MASK;
- for (Py_ssize_t i = len_needle - 2; i >= 0; i--) {
+ last = needle[len_needle - 1] & TABLE_MASK;
+ for (i = len_needle - 2; i >= 0; i--) {
STRINGLIB_CHAR x = needle[i] & TABLE_MASK;
if (x == last) {
p->gap = len_needle - 1 - i;
@@ -344,12 +348,12 @@ STRINGLIB(_preprocess)(const STRINGLIB_CHAR *needle, Py_ssize_t len_needle,
}
}
// Fill up a compressed Boyer-Moore "Bad Character" table
- Py_ssize_t not_found_shift = Py_MIN(len_needle, MAX_SHIFT);
- for (Py_ssize_t i = 0; i < (Py_ssize_t)TABLE_SIZE; i++) {
+ not_found_shift = Py_MIN(len_needle, MAX_SHIFT);
+ for (i = 0; i < (Py_ssize_t)TABLE_SIZE; i++) {
p->table[i] = Py_SAFE_DOWNCAST(not_found_shift,
Py_ssize_t, SHIFT_TYPE);
}
- for (Py_ssize_t i = len_needle - not_found_shift; i < len_needle; i++) {
+ for (i = len_needle - not_found_shift; i < len_needle; i++) {
SHIFT_TYPE shift = Py_SAFE_DOWNCAST(len_needle - 1 - i,
Py_ssize_t, SHIFT_TYPE);
p->table[needle[i] & TABLE_MASK] = shift;
@@ -370,17 +374,22 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
const STRINGLIB_CHAR *const haystack_end = haystack + len_haystack;
SHIFT_TYPE *table = p->table;
const STRINGLIB_CHAR *window;
- LOG("===== Two-way: \"%s\" in \"%s\". =====\n", needle, haystack);
+ Py_ssize_t memory;
+ Py_ssize_t i;
+ Py_ssize_t shift;
+ Py_ssize_t gap_jump_end;
+ Py_ssize_t mem_jump;
+ LOG(("===== Two-way: \"%s\" in \"%s\". =====\n", needle, haystack));
if (p->is_periodic) {
- LOG("Needle is periodic.\n");
- Py_ssize_t memory = 0;
+ LOG(("Needle is periodic.\n"));
+ memory = 0;
periodicwindowloop:
while (window_last < haystack_end) {
assert(memory == 0);
for (;;) {
LOG_LINEUP();
- Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
+ shift = table[(*window_last) & TABLE_MASK];
window_last += shift;
if (shift == 0) {
break;
@@ -388,16 +397,16 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
if (window_last >= haystack_end) {
return -1;
}
- LOG("Horspool skip");
+ LOG(("Horspool skip"));
}
no_shift:
window = window_last - len_needle + 1;
assert((window[len_needle - 1] & TABLE_MASK) ==
(needle[len_needle - 1] & TABLE_MASK));
- Py_ssize_t i = Py_MAX(cut, memory);
+ i = Py_MAX(cut, memory);
for (; i < len_needle; i++) {
if (needle[i] != window[i]) {
- LOG("Right half does not match.\n");
+ LOG(("Right half does not match.\n"));
window_last += i - cut + 1;
memory = 0;
goto periodicwindowloop;
@@ -405,20 +414,20 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
}
for (i = memory; i < cut; i++) {
if (needle[i] != window[i]) {
- LOG("Left half does not match.\n");
+ LOG(("Left half does not match.\n"));
window_last += period;
memory = len_needle - period;
if (window_last >= haystack_end) {
return -1;
}
- Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
+ shift = table[(*window_last) & TABLE_MASK];
if (shift) {
// A mismatch has been identified to the right
// of where i will next start, so we can jump
// at least as far as if the mismatch occurred
// on the first comparison.
- Py_ssize_t mem_jump = Py_MAX(cut, memory) - cut + 1;
- LOG("Skip with Memory.\n");
+ mem_jump = Py_MAX(cut, memory) - cut + 1;
+ LOG(("Skip with Memory.\n"));
memory = 0;
window_last += Py_MAX(shift, mem_jump);
goto periodicwindowloop;
@@ -426,20 +435,20 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
goto no_shift;
}
}
- LOG("Found a match!\n");
+ LOG(("Found a match!\n"));
return window - haystack;
}
}
else {
Py_ssize_t gap = p->gap;
period = Py_MAX(gap, period);
- LOG("Needle is not periodic.\n");
- Py_ssize_t gap_jump_end = Py_MIN(len_needle, cut + gap);
+ LOG(("Needle is not periodic.\n"));
+ gap_jump_end = Py_MIN(len_needle, cut + gap);
windowloop:
while (window_last < haystack_end) {
for (;;) {
LOG_LINEUP();
- Py_ssize_t shift = table[(*window_last) & TABLE_MASK];
+ shift = table[(*window_last) & TABLE_MASK];
window_last += shift;
if (shift == 0) {
break;
@@ -447,39 +456,39 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack, Py_ssize_t len_haystack,
if (window_last >= haystack_end) {
return -1;
}
- LOG("Horspool skip");
+ LOG(("Horspool skip"));
}
window = window_last - len_needle + 1;
assert((window[len_needle - 1] & TABLE_MASK) ==
(needle[len_needle - 1] & TABLE_MASK));
- for (Py_ssize_t i = cut; i < gap_jump_end; i++) {
+ for (i = cut; i < gap_jump_end; i++) {
if (needle[i] != window[i]) {
- LOG("Early right half mismatch: jump by gap.\n");
+ LOG(("Early right half mismatch: jump by gap.\n"));
assert(gap >= i - cut + 1);
window_last += gap;
goto windowloop;
}
}
- for (Py_ssize_t i = gap_jump_end; i < len_needle; i++) {
+ for (i = gap_jump_end; i < len_needle; i++) {
if (needle[i] != window[i]) {
- LOG("Late right half mismatch.\n");
+ LOG(("Late right half mismatch.\n"));
assert(i - cut + 1 > gap);
window_last += i - cut + 1;
goto windowloop;
}
}
- for (Py_ssize_t i = 0; i < cut; i++) {
+ for (i = 0; i < cut; i++) {
if (needle[i] != window[i]) {
- LOG("Left half does not match.\n");
+ LOG(("Left half does not match.\n"));
window_last += period;
goto windowloop;
}
}
- LOG("Found a match!\n");
+ LOG(("Found a match!\n"));
return window - haystack;
}
}
- LOG("Not found. Returning -1.\n");
+ LOG(("Not found. Returning -1.\n"));
return -1;
}
@@ -490,8 +499,9 @@ STRINGLIB(_two_way_find)(const STRINGLIB_CHAR *haystack,
const STRINGLIB_CHAR *needle,
Py_ssize_t len_needle)
{
- LOG("###### Finding \"%s\" in \"%s\".\n", needle, haystack);
STRINGLIB(prework) p;
+
+ LOG(("###### Finding \"%s\" in \"%s\".\n", needle, haystack));
STRINGLIB(_preprocess)(needle, len_needle, &p);
return STRINGLIB(_two_way)(haystack, len_haystack, &p);
}
@@ -504,10 +514,14 @@ STRINGLIB(_two_way_count)(const STRINGLIB_CHAR *haystack,
Py_ssize_t len_needle,
Py_ssize_t maxcount)
{
- LOG("###### Counting \"%s\" in \"%s\".\n", needle, haystack);
STRINGLIB(prework) p;
+ Py_ssize_t index;
+ Py_ssize_t count;
+
+ LOG(("###### Counting \"%s\" in \"%s\".\n", needle, haystack));
STRINGLIB(_preprocess)(needle, len_needle, &p);
- Py_ssize_t index = 0, count = 0;
+ index = 0;
+ count = 0;
while (1) {
Py_ssize_t result;
result = STRINGLIB(_two_way)(haystack + index,
@@ -543,11 +557,12 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
const Py_ssize_t w = n - m;
Py_ssize_t mlast = m - 1, count = 0;
Py_ssize_t gap = mlast;
+ Py_ssize_t i;
const STRINGLIB_CHAR last = p[mlast];
const STRINGLIB_CHAR *const ss = &s[mlast];
unsigned long mask = 0;
- for (Py_ssize_t i = 0; i < mlast; i++) {
+ for (i = 0; i < mlast; i++) {
STRINGLIB_BLOOM_ADD(mask, p[i]);
if (p[i] == last) {
gap = mlast - i - 1;
@@ -555,7 +570,7 @@ STRINGLIB(default_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
}
STRINGLIB_BLOOM_ADD(mask, last);
- for (Py_ssize_t i = 0; i <= w; i++) {
+ for (i = 0; i <= w; i++) {
if (ss[i] == last) {
/* candidate match */
Py_ssize_t j;
@@ -604,11 +619,12 @@ STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
Py_ssize_t mlast = m - 1, count = 0;
Py_ssize_t gap = mlast;
Py_ssize_t hits = 0, res;
+ Py_ssize_t i;
const STRINGLIB_CHAR last = p[mlast];
const STRINGLIB_CHAR *const ss = &s[mlast];
unsigned long mask = 0;
- for (Py_ssize_t i = 0; i < mlast; i++) {
+ for (i = 0; i < mlast; i++) {
STRINGLIB_BLOOM_ADD(mask, p[i]);
if (p[i] == last) {
gap = mlast - i - 1;
@@ -616,7 +632,7 @@ STRINGLIB(adaptive_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
}
STRINGLIB_BLOOM_ADD(mask, last);
- for (Py_ssize_t i = 0; i <= w; i++) {
+ for (i = 0; i <= w; i++) {
if (ss[i] == last) {
/* candidate match */
Py_ssize_t j;
diff --git a/Objects/stringlib/partition.h b/Objects/stringlib/partition.h
index bcc2176..d4ff95a 100644
--- a/Objects/stringlib/partition.h
+++ b/Objects/stringlib/partition.h
@@ -17,6 +17,9 @@ STRINGLIB(partition)(PyObject* str_obj,
{
PyObject* out;
Py_ssize_t pos;
+#if !STRINGLIB_MUTABLE
+ PyObject *empty;
+#endif
if (sep_len == 0) {
PyErr_SetString(PyExc_ValueError, "empty separator");
@@ -42,7 +45,7 @@ STRINGLIB(partition)(PyObject* str_obj,
#else
Py_INCREF(str_obj);
PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
- PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY();
+ empty = (PyObject*)STRINGLIB_GET_EMPTY();
assert(empty != NULL);
Py_INCREF(empty);
PyTuple_SET_ITEM(out, 1, empty);
@@ -74,6 +77,9 @@ STRINGLIB(rpartition)(PyObject* str_obj,
{
PyObject* out;
Py_ssize_t pos;
+#if !STRINGLIB_MUTABLE
+ PyObject *empty;
+#endif
if (sep_len == 0) {
PyErr_SetString(PyExc_ValueError, "empty separator");
@@ -97,7 +103,7 @@ STRINGLIB(rpartition)(PyObject* str_obj,
return NULL;
}
#else
- PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY();
+ empty = (PyObject*)STRINGLIB_GET_EMPTY();
assert(empty != NULL);
Py_INCREF(empty);
PyTuple_SET_ITEM(out, 0, empty);
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/dynload_win.c b/Python/dynload_win.c
index 5dc4095..e97a972 100644
--- a/Python/dynload_win.c
+++ b/Python/dynload_win.c
@@ -13,6 +13,7 @@
#include "importdl.h"
#include "patchlevel.h"
#include <windows.h>
+#include "pycore_win9x_loadlibrary.h" // SDK fallbacks for VC6
#ifdef _DEBUG
#define PYD_DEBUG_SUFFIX "_d"
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;