4801 lines
193 KiB
Diff
4801 lines
193 KiB
Diff
diff --git a/Include/internal/pycore_atomic.h b/Include/internal/pycore_atomic.h
|
|
index 425d69f..748de28 100644
|
|
--- a/Include/internal/pycore_atomic.h
|
|
+++ b/Include/internal/pycore_atomic.h
|
|
@@ -16,7 +16,21 @@ extern "C" {
|
|
#endif
|
|
|
|
|
|
-#if defined(_MSC_VER)
|
|
+/* Visual C++ 6.0 (_MSC_VER 1200) predates <intrin.h> and the _Interlocked*
|
|
+ * compiler intrinsics (both introduced in Visual Studio 2005, _MSC_VER
|
|
+ * 1400) as well as <immintrin.h>. This port only targets 32-bit x86 under
|
|
+ * VC6, so gate the modern-MSVC include on that combination and give VC6/x86
|
|
+ * a project-local branch below (_Py_ATOMIC_VC6_X86) built on the Win32
|
|
+ * Interlocked* API instead. Every other compiler/version keeps the
|
|
+ * unmodified upstream behavior.
|
|
+ */
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300 && defined(_M_IX86)
|
|
+# define _Py_ATOMIC_VC6_X86 1
|
|
+ /* Declares InterlockedExchange()/InterlockedCompareExchange(), used by
|
|
+ * the _Py_ATOMIC_VC6_X86 branch below in place of the _Interlocked*
|
|
+ * intrinsics the modern-MSVC branch gets from <intrin.h>. */
|
|
+# include <windows.h>
|
|
+#elif defined(_MSC_VER)
|
|
#include <intrin.h>
|
|
#if defined(_M_IX86) || defined(_M_X64)
|
|
# include <immintrin.h>
|
|
@@ -238,7 +252,87 @@ _Py_ANNOTATE_MEMORY_ORDER(const volatile void *address, _Py_memory_order order)
|
|
This might affect performance but likely only in some very specific and
|
|
hard to measure scenario.
|
|
*/
|
|
-#if defined(_M_IX86) || defined(_M_X64)
|
|
+#if defined(_Py_ATOMIC_VC6_X86)
|
|
+/* VC6 / Windows 9x, 32-bit x86 only (_M_X64 is never defined by VC6).
|
|
+ VC6 has neither <intrin.h>/_Interlocked* compiler intrinsics (Visual
|
|
+ Studio 2005+) nor the _HLEAcquire/_HLERelease hardware-lock-elision
|
|
+ variants (Visual Studio 2013+) used by the modern-MSVC branch below.
|
|
+ Substitute the plain Win32 InterlockedExchange/InterlockedCompareExchange
|
|
+ functions, which are exported by KERNEL32.DLL on Windows 98 (this VC6
|
|
+ SDK's WINBASE.H declares them for _M_IX86 as compiler-intrinsic-backed
|
|
+ APIs, not the newer MRx000/Alpha-only intrinsic path above them in that
|
|
+ header). Like the modern-MSVC intrinsics, these give a full memory
|
|
+ barrier, so -- as with the HLE fallback described above -- every
|
|
+ _Py_memory_order maps to the same fully-fenced operation; there is no
|
|
+ separate acquire/release-only path to take.
|
|
+
|
|
+ _Py_atomic_address (uintptr_t) and _Py_atomic_int (int) are both 4
|
|
+ bytes on this 32-bit-only target, so the 64-bit store/load paths used
|
|
+ by the modern-MSVC branch below (guarded there by `sizeof(...) == 8`)
|
|
+ are unreachable here and are intentionally not implemented: this port
|
|
+ has no Win9x-era substitute for CMPXCHG8B-based 64-bit atomics. Fail
|
|
+ loudly at compile time rather than silently mishandling a 64-bit
|
|
+ target if this header is ever pulled into a VC6 build configured for
|
|
+ one (VC6 itself never defines _M_X64, so this should not trigger).
|
|
+*/
|
|
+#if defined(_M_X64)
|
|
+#error "VC6 64-bit atomics are not implemented; this port only targets 32-bit x86 (_M_IX86)."
|
|
+#endif
|
|
+
|
|
+typedef enum _Py_memory_order {
|
|
+ _Py_memory_order_relaxed,
|
|
+ _Py_memory_order_acquire,
|
|
+ _Py_memory_order_release,
|
|
+ _Py_memory_order_acq_rel,
|
|
+ _Py_memory_order_seq_cst
|
|
+} _Py_memory_order;
|
|
+
|
|
+typedef struct _Py_atomic_address {
|
|
+ volatile uintptr_t _value;
|
|
+} _Py_atomic_address;
|
|
+
|
|
+typedef struct _Py_atomic_int {
|
|
+ volatile int _value;
|
|
+} _Py_atomic_int;
|
|
+
|
|
+static __inline long
|
|
+_Py_vc6_InterlockedExchange(volatile long *target, long value)
|
|
+{
|
|
+ return InterlockedExchange((LPLONG)target, value);
|
|
+}
|
|
+
|
|
+static __inline long
|
|
+_Py_vc6_InterlockedCompareExchange(volatile long *destination, long exchange, long comperand)
|
|
+{
|
|
+ return (long)InterlockedCompareExchange(
|
|
+ (PVOID *)destination, (PVOID)exchange, (PVOID)comperand);
|
|
+}
|
|
+
|
|
+#define _Py_atomic_store_32bit(ATOMIC_VAL, NEW_VAL, ORDER) \
|
|
+ ((void)_Py_vc6_InterlockedExchange( \
|
|
+ (volatile long *)&((ATOMIC_VAL)->_value), (long)(NEW_VAL)))
|
|
+
|
|
+static __inline int
|
|
+_Py_atomic_load_32bit_impl(volatile int *value, int order)
|
|
+{
|
|
+ long old;
|
|
+ (void)order;
|
|
+ do {
|
|
+ old = *(volatile long *)value;
|
|
+ } while (_Py_vc6_InterlockedCompareExchange((volatile long *)value, old, old) != old);
|
|
+ return (int)old;
|
|
+}
|
|
+
|
|
+#define _Py_atomic_load_32bit(ATOMIC_VAL, ORDER) \
|
|
+ _Py_atomic_load_32bit_impl((volatile int *)&((ATOMIC_VAL)->_value), (ORDER))
|
|
+
|
|
+#define _Py_atomic_store_explicit(ATOMIC_VAL, NEW_VAL, ORDER) \
|
|
+ _Py_atomic_store_32bit((ATOMIC_VAL), (NEW_VAL), (ORDER))
|
|
+
|
|
+#define _Py_atomic_load_explicit(ATOMIC_VAL, ORDER) \
|
|
+ _Py_atomic_load_32bit((ATOMIC_VAL), (ORDER))
|
|
+
|
|
+#elif defined(_M_IX86) || defined(_M_X64)
|
|
typedef enum _Py_memory_order {
|
|
_Py_memory_order_relaxed,
|
|
_Py_memory_order_acquire,
|
|
diff --git a/Include/internal/pycore_call.h b/Include/internal/pycore_call.h
|
|
index 3ccacfa..3098e1e 100644
|
|
--- a/Include/internal/pycore_call.h
|
|
+++ b/Include/internal/pycore_call.h
|
|
@@ -38,18 +38,21 @@ extern PyObject * _PyObject_CallMethodFormat(
|
|
static inline vectorcallfunc
|
|
_PyVectorcall_FunctionInline(PyObject *callable)
|
|
{
|
|
+ PyTypeObject *tp;
|
|
+ Py_ssize_t offset;
|
|
+ vectorcallfunc ptr;
|
|
+
|
|
assert(callable != NULL);
|
|
|
|
- PyTypeObject *tp = Py_TYPE(callable);
|
|
+ tp = Py_TYPE(callable);
|
|
if (!PyType_HasFeature(tp, Py_TPFLAGS_HAVE_VECTORCALL)) {
|
|
return NULL;
|
|
}
|
|
assert(PyCallable_Check(callable));
|
|
|
|
- Py_ssize_t offset = tp->tp_vectorcall_offset;
|
|
+ offset = tp->tp_vectorcall_offset;
|
|
assert(offset > 0);
|
|
|
|
- vectorcallfunc ptr;
|
|
memcpy(&ptr, (char *) callable + offset, sizeof(ptr));
|
|
return ptr;
|
|
}
|
|
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
|
|
index 3a24a65..4db8abc 100644
|
|
--- a/Include/internal/pycore_code.h
|
|
+++ b/Include/internal/pycore_code.h
|
|
@@ -149,18 +149,20 @@ typedef unsigned char _PyLocals_Kind;
|
|
static inline _PyLocals_Kind
|
|
_PyLocals_GetKind(PyObject *kinds, int i)
|
|
{
|
|
+ char *ptr;
|
|
assert(PyBytes_Check(kinds));
|
|
assert(0 <= i && i < PyBytes_GET_SIZE(kinds));
|
|
- char *ptr = PyBytes_AS_STRING(kinds);
|
|
+ ptr = PyBytes_AS_STRING(kinds);
|
|
return (_PyLocals_Kind)(ptr[i]);
|
|
}
|
|
|
|
static inline void
|
|
_PyLocals_SetKind(PyObject *kinds, int i, _PyLocals_Kind kind)
|
|
{
|
|
+ char *ptr;
|
|
assert(PyBytes_Check(kinds));
|
|
assert(0 <= i && i < PyBytes_GET_SIZE(kinds));
|
|
- char *ptr = PyBytes_AS_STRING(kinds);
|
|
+ ptr = PyBytes_AS_STRING(kinds);
|
|
ptr[i] = (char) kind;
|
|
}
|
|
|
|
@@ -520,11 +522,12 @@ adaptive_counter_start(void) {
|
|
static inline uint16_t
|
|
adaptive_counter_backoff(uint16_t counter) {
|
|
unsigned int backoff = counter & ((1<<ADAPTIVE_BACKOFF_BITS)-1);
|
|
+ unsigned int value;
|
|
backoff++;
|
|
if (backoff > MAX_BACKOFF_VALUE) {
|
|
backoff = MAX_BACKOFF_VALUE;
|
|
}
|
|
- unsigned int value = (1 << backoff) - 1;
|
|
+ value = (1 << backoff) - 1;
|
|
return adaptive_counter_bits(value, backoff);
|
|
}
|
|
|
|
diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h
|
|
index dc308fe..16feaf3 100644
|
|
--- a/Include/internal/pycore_dict.h
|
|
+++ b/Include/internal/pycore_dict.h
|
|
@@ -163,9 +163,11 @@ extern PyObject *_PyDict_FromItems(
|
|
static inline void
|
|
_PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
|
|
{
|
|
+ uint8_t *size_ptr;
|
|
+ int size;
|
|
assert(ix < SHARED_KEYS_MAX_SIZE);
|
|
- uint8_t *size_ptr = ((uint8_t *)values)-2;
|
|
- int size = *size_ptr;
|
|
+ size_ptr = ((uint8_t *)values)-2;
|
|
+ size = *size_ptr;
|
|
assert(size+2 < ((uint8_t *)values)[-1]);
|
|
size++;
|
|
size_ptr[-size] = (uint8_t)ix;
|
|
diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h
|
|
index 4866ea2..17ca4f8 100644
|
|
--- a/Include/internal/pycore_frame.h
|
|
+++ b/Include/internal/pycore_frame.h
|
|
@@ -162,9 +162,10 @@ _PyFrame_MakeAndSetFrameObject(_PyInterpreterFrame *frame);
|
|
static inline PyFrameObject *
|
|
_PyFrame_GetFrameObject(_PyInterpreterFrame *frame)
|
|
{
|
|
+ PyFrameObject *res;
|
|
|
|
assert(!_PyFrame_IsIncomplete(frame));
|
|
- PyFrameObject *res = frame->frame_obj;
|
|
+ res = frame->frame_obj;
|
|
if (res != NULL) {
|
|
return res;
|
|
}
|
|
@@ -211,7 +212,9 @@ static inline _PyInterpreterFrame *
|
|
_PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
|
|
{
|
|
if (_PyThreadState_HasStackSpace(tstate, size)) {
|
|
- _PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->datastack_top;
|
|
+ _PyInterpreterFrame *res;
|
|
+
|
|
+ res = (_PyInterpreterFrame *)tstate->datastack_top;
|
|
tstate->datastack_top += size;
|
|
return res;
|
|
}
|
|
@@ -229,8 +232,10 @@ int _PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame);
|
|
static inline
|
|
PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame)
|
|
{
|
|
+ size_t offset_in_gen;
|
|
+
|
|
assert(frame->owner == FRAME_OWNED_BY_GENERATOR);
|
|
- size_t offset_in_gen = offsetof(PyGenObject, gi_iframe);
|
|
+ offset_in_gen = offsetof(PyGenObject, gi_iframe);
|
|
return (PyGenObject *)(((char *)frame) - offset_in_gen);
|
|
}
|
|
|
|
diff --git a/Include/internal/pycore_initconfig.h b/Include/internal/pycore_initconfig.h
|
|
index d765600..dcdd359 100644
|
|
--- a/Include/internal/pycore_initconfig.h
|
|
+++ b/Include/internal/pycore_initconfig.h
|
|
@@ -14,22 +14,56 @@ struct pyruntimestate;
|
|
/* --- PyStatus ----------------------------------------------- */
|
|
|
|
/* Almost all errors causing Python initialization to fail */
|
|
-#ifdef _MSC_VER
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+ /* VC6 has neither C99 __func__ nor later MSVC __FUNCTION__. */
|
|
+# define _PyStatus_GET_FUNC() NULL
|
|
+#elif defined(_MSC_VER)
|
|
/* Visual Studio 2015 doesn't implement C99 __func__ in C */
|
|
# define _PyStatus_GET_FUNC() __FUNCTION__
|
|
#else
|
|
# define _PyStatus_GET_FUNC() __func__
|
|
#endif
|
|
|
|
-#define _PyStatus_OK() \
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+/* VC6 cannot parse the C99 compound literals/designated initializers below.
|
|
+ Keep the helpers local to this internal header and construct the status
|
|
+ objects field-by-field so PyStatus_Ok() can safely return _PyStatus_OK()
|
|
+ without recursing back into itself. */
|
|
+static PyStatus
|
|
+_PyStatus_OK_VC6(void)
|
|
+{
|
|
+ PyStatus status;
|
|
+ status._type = _PyStatus_TYPE_OK;
|
|
+ status.func = NULL;
|
|
+ status.err_msg = NULL;
|
|
+ status.exitcode = 0;
|
|
+ return status;
|
|
+}
|
|
+
|
|
+static PyStatus
|
|
+_PyStatus_ERR_VC6(const char *err_msg)
|
|
+{
|
|
+ PyStatus status;
|
|
+ status._type = _PyStatus_TYPE_ERROR;
|
|
+ status.func = _PyStatus_GET_FUNC();
|
|
+ status.err_msg = err_msg;
|
|
+ status.exitcode = 0;
|
|
+ return status;
|
|
+}
|
|
+
|
|
+# define _PyStatus_OK() _PyStatus_OK_VC6()
|
|
+# define _PyStatus_ERR(ERR_MSG) _PyStatus_ERR_VC6(ERR_MSG)
|
|
+#else
|
|
+# define _PyStatus_OK() \
|
|
(PyStatus){._type = _PyStatus_TYPE_OK,}
|
|
/* other fields are set to 0 */
|
|
-#define _PyStatus_ERR(ERR_MSG) \
|
|
+# define _PyStatus_ERR(ERR_MSG) \
|
|
(PyStatus){ \
|
|
._type = _PyStatus_TYPE_ERROR, \
|
|
.func = _PyStatus_GET_FUNC(), \
|
|
.err_msg = (ERR_MSG)}
|
|
/* other fields are set to 0 */
|
|
+#endif
|
|
#define _PyStatus_NO_MEMORY() _PyStatus_ERR("memory allocation failed")
|
|
#define _PyStatus_EXIT(EXITCODE) \
|
|
(PyStatus){ \
|
|
diff --git a/Include/internal/pycore_list.h b/Include/internal/pycore_list.h
|
|
index 860dce1..da38ee6 100644
|
|
--- a/Include/internal/pycore_list.h
|
|
+++ b/Include/internal/pycore_list.h
|
|
@@ -43,10 +43,12 @@ _PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem);
|
|
static inline int
|
|
_PyList_AppendTakeRef(PyListObject *self, PyObject *newitem)
|
|
{
|
|
+ Py_ssize_t len;
|
|
+ Py_ssize_t allocated;
|
|
assert(self != NULL && newitem != NULL);
|
|
assert(PyList_Check(self));
|
|
- Py_ssize_t len = PyList_GET_SIZE(self);
|
|
- Py_ssize_t allocated = self->allocated;
|
|
+ len = PyList_GET_SIZE(self);
|
|
+ allocated = self->allocated;
|
|
assert((size_t)len + 1 < PY_SSIZE_T_MAX);
|
|
if (allocated > len) {
|
|
PyList_SET_ITEM(self, len, newitem);
|
|
diff --git a/Include/internal/pycore_moduleobject.h b/Include/internal/pycore_moduleobject.h
|
|
index 76361b8..2b9861b 100644
|
|
--- a/Include/internal/pycore_moduleobject.h
|
|
+++ b/Include/internal/pycore_moduleobject.h
|
|
@@ -29,8 +29,10 @@ static inline void* _PyModule_GetState(PyObject* mod) {
|
|
}
|
|
|
|
static inline PyObject* _PyModule_GetDict(PyObject *mod) {
|
|
+ PyObject *dict;
|
|
+
|
|
assert(PyModule_Check(mod));
|
|
- PyObject *dict = ((PyModuleObject *)mod) -> md_dict;
|
|
+ dict = ((PyModuleObject *)mod) -> md_dict;
|
|
// _PyModule_GetDict(mod) must not be used after calling module_clear(mod)
|
|
assert(dict != NULL);
|
|
return dict;
|
|
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
|
|
index f022f82..d1c55ae 100644
|
|
--- a/Include/internal/pycore_object.h
|
|
+++ b/Include/internal/pycore_object.h
|
|
@@ -14,6 +14,14 @@ extern "C" {
|
|
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
|
#include "pycore_runtime.h" // _PyRuntime
|
|
|
|
+/* Visual C++ 6.0 predates C99's __func__ predefined identifier. It also
|
|
+ lacks MSVC's later __FUNCTION__ extension, so provide a VC6-only fallback
|
|
+ for debug/fatal diagnostics in this header without changing any other
|
|
+ compiler's function-name reporting. */
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(__func__)
|
|
+# define __func__ "<unknown>"
|
|
+#endif
|
|
+
|
|
#define _PyObject_IMMORTAL_INIT(type) \
|
|
{ \
|
|
.ob_refcnt = 999999999, \
|
|
@@ -125,19 +133,24 @@ static inline void _PyObject_GC_TRACK(
|
|
#endif
|
|
PyObject *op)
|
|
{
|
|
+ PyGC_Head *gc;
|
|
+ PyInterpreterState *interp;
|
|
+ PyGC_Head *generation0;
|
|
+ PyGC_Head *last;
|
|
+
|
|
_PyObject_ASSERT_FROM(op, !_PyObject_GC_IS_TRACKED(op),
|
|
"object already tracked by the garbage collector",
|
|
filename, lineno, __func__);
|
|
|
|
- PyGC_Head *gc = _Py_AS_GC(op);
|
|
+ gc = _Py_AS_GC(op);
|
|
_PyObject_ASSERT_FROM(op,
|
|
(gc->_gc_prev & _PyGC_PREV_MASK_COLLECTING) == 0,
|
|
"object is in generation which is garbage collected",
|
|
filename, lineno, __func__);
|
|
|
|
- PyInterpreterState *interp = _PyInterpreterState_GET();
|
|
- PyGC_Head *generation0 = interp->gc.generation0;
|
|
- PyGC_Head *last = (PyGC_Head*)(generation0->_gc_prev);
|
|
+ interp = _PyInterpreterState_GET();
|
|
+ generation0 = interp->gc.generation0;
|
|
+ last = (PyGC_Head*)(generation0->_gc_prev);
|
|
_PyGCHead_SET_NEXT(last, gc);
|
|
_PyGCHead_SET_PREV(gc, last);
|
|
_PyGCHead_SET_NEXT(gc, generation0);
|
|
@@ -161,13 +174,17 @@ static inline void _PyObject_GC_UNTRACK(
|
|
#endif
|
|
PyObject *op)
|
|
{
|
|
+ PyGC_Head *gc;
|
|
+ PyGC_Head *prev;
|
|
+ PyGC_Head *next;
|
|
+
|
|
_PyObject_ASSERT_FROM(op, _PyObject_GC_IS_TRACKED(op),
|
|
"object not tracked by the garbage collector",
|
|
filename, lineno, __func__);
|
|
|
|
- PyGC_Head *gc = _Py_AS_GC(op);
|
|
- PyGC_Head *prev = _PyGCHead_PREV(gc);
|
|
- PyGC_Head *next = _PyGCHead_NEXT(gc);
|
|
+ gc = _Py_AS_GC(op);
|
|
+ prev = _PyGCHead_PREV(gc);
|
|
+ next = _PyGCHead_NEXT(gc);
|
|
_PyGCHead_SET_NEXT(prev, next);
|
|
_PyGCHead_SET_PREV(next, prev);
|
|
gc->_gc_next = 0;
|
|
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
|
|
index 13eae1e..91faff4 100644
|
|
--- a/Include/internal/pycore_runtime_init.h
|
|
+++ b/Include/internal/pycore_runtime_init.h
|
|
@@ -14,6 +14,11 @@ extern "C" {
|
|
/* The static initializers defined here should only be used
|
|
in the runtime init code (in pystate.c and pylifecycle.c). */
|
|
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+/* VC6 does not support the nested C99 designated initializers below.
|
|
+ pystate.c provides a field-by-field initializer for the same defaults. */
|
|
+extern void _PyRuntimeState_InitStaticDefaults(_PyRuntimeState *runtime);
|
|
+#else
|
|
|
|
#define _PyRuntimeState_INIT \
|
|
{ \
|
|
@@ -72,6 +77,8 @@ extern "C" {
|
|
.context_ver = 1, \
|
|
}
|
|
|
|
+#endif /* !(defined(_MSC_VER) && _MSC_VER < 1300) */
|
|
+
|
|
|
|
// global objects
|
|
|
|
diff --git a/Include/longobject.h b/Include/longobject.h
|
|
index 778cb62..d25edf7 100644
|
|
--- a/Include/longobject.h
|
|
+++ b/Include/longobject.h
|
|
@@ -81,12 +81,12 @@ PyAPI_FUNC(double) PyLong_AsDouble(PyObject *);
|
|
PyAPI_FUNC(PyObject *) PyLong_FromVoidPtr(void *);
|
|
PyAPI_FUNC(void *) PyLong_AsVoidPtr(PyObject *);
|
|
|
|
-PyAPI_FUNC(PyObject *) PyLong_FromLongLong(long long);
|
|
-PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned long long);
|
|
-PyAPI_FUNC(long long) PyLong_AsLongLong(PyObject *);
|
|
-PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLong(PyObject *);
|
|
-PyAPI_FUNC(unsigned long long) PyLong_AsUnsignedLongLongMask(PyObject *);
|
|
-PyAPI_FUNC(long long) PyLong_AsLongLongAndOverflow(PyObject *, int *);
|
|
+PyAPI_FUNC(PyObject *) PyLong_FromLongLong(PY_LONG_LONG);
|
|
+PyAPI_FUNC(PyObject *) PyLong_FromUnsignedLongLong(unsigned PY_LONG_LONG);
|
|
+PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLong(PyObject *);
|
|
+PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLong(PyObject *);
|
|
+PyAPI_FUNC(unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);
|
|
+PyAPI_FUNC(PY_LONG_LONG) PyLong_AsLongLongAndOverflow(PyObject *, int *);
|
|
|
|
PyAPI_FUNC(PyObject *) PyLong_FromString(const char *, char **, int);
|
|
|
|
diff --git a/Include/pyexpat.h b/Include/pyexpat.h
|
|
index a676e16..017e86d 100644
|
|
--- a/Include/pyexpat.h
|
|
+++ b/Include/pyexpat.h
|
|
@@ -54,12 +54,12 @@ struct PyExpat_CAPI
|
|
XML_Bool (*SetReparseDeferralEnabled)(XML_Parser parser, XML_Bool enabled);
|
|
/* might be NULL for expat < 2.7.2 */
|
|
XML_Bool (*SetAllocTrackerActivationThreshold)(
|
|
- XML_Parser parser, unsigned long long activationThresholdBytes);
|
|
+ XML_Parser parser, unsigned PY_LONG_LONG activationThresholdBytes);
|
|
XML_Bool (*SetAllocTrackerMaximumAmplification)(
|
|
XML_Parser parser, float maxAmplificationFactor);
|
|
/* might be NULL for expat < 2.4.0 */
|
|
XML_Bool (*SetBillionLaughsAttackProtectionActivationThreshold)(
|
|
- XML_Parser parser, unsigned long long activationThresholdBytes);
|
|
+ XML_Parser parser, unsigned PY_LONG_LONG activationThresholdBytes);
|
|
XML_Bool (*SetBillionLaughsAttackProtectionMaximumAmplification)(
|
|
XML_Parser parser, float maxAmplificationFactor);
|
|
/* might be NULL for expat < 2.8.0 */
|
|
diff --git a/Include/pyport.h b/Include/pyport.h
|
|
index b3b8b6f..ae930fc 100644
|
|
--- a/Include/pyport.h
|
|
+++ b/Include/pyport.h
|
|
@@ -97,6 +97,13 @@ Used in: Py_SAFE_DOWNCAST
|
|
#define PY_ULLONG_MAX ULLONG_MAX
|
|
#endif
|
|
|
|
+/* Spelling of 64 bit integer literal suffixes; see PC/pyconfig.h for the
|
|
+ compilers that need something other than the C99 LL/ULL suffixes. */
|
|
+#ifndef PY_LL
|
|
+#define PY_LL(x) x##LL
|
|
+#define PY_ULL(x) x##ULL
|
|
+#endif
|
|
+
|
|
#define PY_UINT32_T uint32_t
|
|
#define PY_UINT64_T uint64_t
|
|
|
|
@@ -334,9 +341,12 @@ extern "C" {
|
|
#if defined(__GNUC__) \
|
|
&& ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
|
|
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
|
|
-#elif defined(_MSC_VER)
|
|
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
|
|
#define Py_DEPRECATED(VERSION) __declspec(deprecated( \
|
|
"deprecated in " #VERSION))
|
|
+#elif defined(_MSC_VER)
|
|
+/* Visual C++ 6.0 has no supported deprecation declaration syntax. */
|
|
+#define Py_DEPRECATED(VERSION_UNUSED)
|
|
#else
|
|
#define Py_DEPRECATED(VERSION_UNUSED)
|
|
#endif
|
|
@@ -352,10 +362,14 @@ extern "C" {
|
|
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
|
|
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
|
|
#define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
|
|
-#elif defined(_MSC_VER)
|
|
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
|
|
#define _Py_COMP_DIAG_PUSH __pragma(warning(push))
|
|
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
|
|
#define _Py_COMP_DIAG_POP __pragma(warning(pop))
|
|
+#elif defined(_MSC_VER)
|
|
+#define _Py_COMP_DIAG_PUSH
|
|
+#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
|
|
+#define _Py_COMP_DIAG_POP
|
|
#else
|
|
#define _Py_COMP_DIAG_PUSH
|
|
#define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
|
|
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/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/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/getpath.c b/Modules/getpath.c
|
|
index 61d6540..e7489ee 100644
|
|
--- a/Modules/getpath.c
|
|
+++ b/Modules/getpath.c
|
|
@@ -12,6 +12,9 @@
|
|
#ifdef MS_WINDOWS
|
|
# include <windows.h> // GetFullPathNameW(), MAX_PATH
|
|
# include <pathcch.h>
|
|
+# if defined(_MSC_VER) && _MSC_VER < 1300 && !defined(INVALID_FILE_ATTRIBUTES)
|
|
+# define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
|
+# endif
|
|
#endif
|
|
|
|
#ifdef __APPLE__
|
|
@@ -60,10 +63,10 @@ getpath_abspath(PyObject *Py_UNUSED(self), PyObject *args)
|
|
PyObject *r = NULL;
|
|
PyObject *pathobj;
|
|
wchar_t *path;
|
|
+ Py_ssize_t len;
|
|
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
|
|
return NULL;
|
|
}
|
|
- Py_ssize_t len;
|
|
path = PyUnicode_AsWideCharString(pathobj, &len);
|
|
if (path) {
|
|
wchar_t *abs;
|
|
@@ -83,11 +86,13 @@ static PyObject *
|
|
getpath_basename(PyObject *Py_UNUSED(self), PyObject *args)
|
|
{
|
|
PyObject *path;
|
|
+ Py_ssize_t end;
|
|
+ Py_ssize_t pos;
|
|
if (!PyArg_ParseTuple(args, "U", &path)) {
|
|
return NULL;
|
|
}
|
|
- Py_ssize_t end = PyUnicode_GET_LENGTH(path);
|
|
- Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
|
|
+ end = PyUnicode_GET_LENGTH(path);
|
|
+ pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
|
|
if (pos < 0) {
|
|
return Py_NewRef(path);
|
|
}
|
|
@@ -99,11 +104,13 @@ static PyObject *
|
|
getpath_dirname(PyObject *Py_UNUSED(self), PyObject *args)
|
|
{
|
|
PyObject *path;
|
|
+ Py_ssize_t end;
|
|
+ Py_ssize_t pos;
|
|
if (!PyArg_ParseTuple(args, "U", &path)) {
|
|
return NULL;
|
|
}
|
|
- Py_ssize_t end = PyUnicode_GET_LENGTH(path);
|
|
- Py_ssize_t pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
|
|
+ end = PyUnicode_GET_LENGTH(path);
|
|
+ pos = PyUnicode_FindChar(path, SEP, 0, end, -1);
|
|
if (pos < 0) {
|
|
return PyUnicode_FromStringAndSize(NULL, 0);
|
|
}
|
|
@@ -138,10 +145,10 @@ getpath_hassuffix(PyObject *Py_UNUSED(self), PyObject *args)
|
|
PyObject *suffixobj;
|
|
const wchar_t *path;
|
|
const wchar_t *suffix;
|
|
+ Py_ssize_t len, suffixLen;
|
|
if (!PyArg_ParseTuple(args, "UU", &pathobj, &suffixobj)) {
|
|
return NULL;
|
|
}
|
|
- Py_ssize_t len, suffixLen;
|
|
path = PyUnicode_AsWideCharString(pathobj, &len);
|
|
if (path) {
|
|
suffix = PyUnicode_AsWideCharString(suffixobj, &suffixLen);
|
|
@@ -172,17 +179,21 @@ getpath_isdir(PyObject *Py_UNUSED(self), PyObject *args)
|
|
PyObject *r = NULL;
|
|
PyObject *pathobj;
|
|
const wchar_t *path;
|
|
+#ifdef MS_WINDOWS
|
|
+ DWORD attr;
|
|
+#else
|
|
+ struct stat st;
|
|
+#endif
|
|
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
|
|
return NULL;
|
|
}
|
|
path = PyUnicode_AsWideCharString(pathobj, NULL);
|
|
if (path) {
|
|
#ifdef MS_WINDOWS
|
|
- DWORD attr = GetFileAttributesW(path);
|
|
+ attr = GetFileAttributesW(path);
|
|
r = (attr != INVALID_FILE_ATTRIBUTES) &&
|
|
(attr & FILE_ATTRIBUTE_DIRECTORY) ? Py_True : Py_False;
|
|
#else
|
|
- struct stat st;
|
|
r = (_Py_wstat(path, &st) == 0) && S_ISDIR(st.st_mode) ? Py_True : Py_False;
|
|
#endif
|
|
PyMem_Free((void *)path);
|
|
@@ -198,17 +209,21 @@ getpath_isfile(PyObject *Py_UNUSED(self), PyObject *args)
|
|
PyObject *r = NULL;
|
|
PyObject *pathobj;
|
|
const wchar_t *path;
|
|
+#ifdef MS_WINDOWS
|
|
+ DWORD attr;
|
|
+#else
|
|
+ struct stat st;
|
|
+#endif
|
|
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
|
|
return NULL;
|
|
}
|
|
path = PyUnicode_AsWideCharString(pathobj, NULL);
|
|
if (path) {
|
|
#ifdef MS_WINDOWS
|
|
- DWORD attr = GetFileAttributesW(path);
|
|
+ attr = GetFileAttributesW(path);
|
|
r = (attr != INVALID_FILE_ATTRIBUTES) &&
|
|
!(attr & FILE_ATTRIBUTE_DIRECTORY) ? Py_True : Py_False;
|
|
#else
|
|
- struct stat st;
|
|
r = (_Py_wstat(path, &st) == 0) && S_ISREG(st.st_mode) ? Py_True : Py_False;
|
|
#endif
|
|
PyMem_Free((void *)path);
|
|
@@ -225,21 +240,25 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
|
|
PyObject *pathobj;
|
|
const wchar_t *path;
|
|
Py_ssize_t cchPath;
|
|
+#ifdef MS_WINDOWS
|
|
+ const wchar_t *ext;
|
|
+ DWORD attr;
|
|
+#else
|
|
+ struct stat st;
|
|
+#endif
|
|
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
|
|
return NULL;
|
|
}
|
|
path = PyUnicode_AsWideCharString(pathobj, &cchPath);
|
|
if (path) {
|
|
#ifdef MS_WINDOWS
|
|
- const wchar_t *ext;
|
|
- DWORD attr = GetFileAttributesW(path);
|
|
+ attr = GetFileAttributesW(path);
|
|
r = (attr != INVALID_FILE_ATTRIBUTES) &&
|
|
!(attr & FILE_ATTRIBUTE_DIRECTORY) &&
|
|
SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) &&
|
|
(CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL)
|
|
? Py_True : Py_False;
|
|
#else
|
|
- struct stat st;
|
|
r = (_Py_wstat(path, &st) == 0) &&
|
|
S_ISREG(st.st_mode) &&
|
|
(st.st_mode & 0111)
|
|
@@ -255,27 +274,35 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
|
|
static PyObject *
|
|
getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
|
|
{
|
|
+ Py_ssize_t n;
|
|
+ wchar_t **parts;
|
|
+ Py_ssize_t cchFinal;
|
|
+ Py_ssize_t first;
|
|
+ Py_ssize_t i;
|
|
+ PyObject *s;
|
|
+ Py_ssize_t cch;
|
|
+ wchar_t *final;
|
|
+ PyObject *r;
|
|
if (!PyTuple_Check(args)) {
|
|
PyErr_SetString(PyExc_TypeError, "requires tuple of arguments");
|
|
return NULL;
|
|
}
|
|
- Py_ssize_t n = PyTuple_GET_SIZE(args);
|
|
+ n = PyTuple_GET_SIZE(args);
|
|
if (n == 0) {
|
|
return PyUnicode_FromStringAndSize(NULL, 0);
|
|
}
|
|
/* Convert all parts to wchar and accumulate max final length */
|
|
- wchar_t **parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
|
|
+ parts = (wchar_t **)PyMem_Malloc(n * sizeof(wchar_t *));
|
|
if (parts == NULL) {
|
|
PyErr_NoMemory();
|
|
return NULL;
|
|
}
|
|
memset(parts, 0, n * sizeof(wchar_t *));
|
|
- Py_ssize_t cchFinal = 0;
|
|
- Py_ssize_t first = 0;
|
|
+ cchFinal = 0;
|
|
+ first = 0;
|
|
|
|
- for (Py_ssize_t i = 0; i < n; ++i) {
|
|
- PyObject *s = PyTuple_GET_ITEM(args, i);
|
|
- Py_ssize_t cch;
|
|
+ for (i = 0; i < n; ++i) {
|
|
+ s = PyTuple_GET_ITEM(args, i);
|
|
if (s == Py_None) {
|
|
cch = 0;
|
|
} else if (PyUnicode_Check(s)) {
|
|
@@ -295,9 +322,9 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
|
|
cchFinal += cch + 1;
|
|
}
|
|
|
|
- wchar_t *final = cchFinal > 0 ? (wchar_t *)PyMem_Malloc(cchFinal * sizeof(wchar_t)) : NULL;
|
|
+ final = cchFinal > 0 ? (wchar_t *)PyMem_Malloc(cchFinal * sizeof(wchar_t)) : NULL;
|
|
if (!final) {
|
|
- for (Py_ssize_t i = 0; i < n; ++i) {
|
|
+ for (i = 0; i < n; ++i) {
|
|
PyMem_Free(parts[i]);
|
|
}
|
|
PyMem_Free(parts);
|
|
@@ -310,7 +337,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
|
|
|
|
final[0] = '\0';
|
|
/* Now join all the paths. The final result should be shorter than the buffer */
|
|
- for (Py_ssize_t i = 0; i < n; ++i) {
|
|
+ for (i = 0; i < n; ++i) {
|
|
if (!parts[i]) {
|
|
continue;
|
|
}
|
|
@@ -331,7 +358,7 @@ getpath_joinpath(PyObject *Py_UNUSED(self), PyObject *args)
|
|
PyErr_SetString(PyExc_SystemError, "failed to join paths");
|
|
return NULL;
|
|
}
|
|
- PyObject *r = PyUnicode_FromWideChar(_Py_normpath(final, -1), -1);
|
|
+ r = PyUnicode_FromWideChar(_Py_normpath(final, -1), -1);
|
|
PyMem_Free(final);
|
|
return r;
|
|
}
|
|
@@ -343,6 +370,16 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
|
|
PyObject *r = NULL;
|
|
PyObject *pathobj;
|
|
const wchar_t *path;
|
|
+ FILE *fp;
|
|
+ const size_t MAX_FILE = 32 * 1024;
|
|
+ char *buffer;
|
|
+ size_t cb;
|
|
+ size_t len;
|
|
+ wchar_t *wbuffer;
|
|
+ wchar_t *p1;
|
|
+ wchar_t *p2;
|
|
+ Py_ssize_t line_len;
|
|
+ PyObject *u;
|
|
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
|
|
return NULL;
|
|
}
|
|
@@ -350,7 +387,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
|
|
if (!path) {
|
|
return NULL;
|
|
}
|
|
- FILE *fp = _Py_wfopen(path, L"rb");
|
|
+ fp = _Py_wfopen(path, L"rb");
|
|
if (!fp) {
|
|
PyErr_SetFromErrno(PyExc_OSError);
|
|
PyMem_Free((void *)path);
|
|
@@ -363,15 +400,14 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
|
|
fclose(fp);
|
|
return NULL;
|
|
}
|
|
- const size_t MAX_FILE = 32 * 1024;
|
|
- char *buffer = (char *)PyMem_Malloc(MAX_FILE);
|
|
+ buffer = (char *)PyMem_Malloc(MAX_FILE);
|
|
if (!buffer) {
|
|
Py_DECREF(r);
|
|
fclose(fp);
|
|
return NULL;
|
|
}
|
|
|
|
- size_t cb = fread(buffer, 1, MAX_FILE, fp);
|
|
+ cb = fread(buffer, 1, MAX_FILE, fp);
|
|
fclose(fp);
|
|
if (!cb) {
|
|
return r;
|
|
@@ -384,8 +420,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
|
|
}
|
|
buffer[cb] = '\0';
|
|
|
|
- size_t len;
|
|
- wchar_t *wbuffer = _Py_DecodeUTF8_surrogateescape(buffer, cb, &len);
|
|
+ wbuffer = _Py_DecodeUTF8_surrogateescape(buffer, cb, &len);
|
|
PyMem_Free((void *)buffer);
|
|
if (!wbuffer) {
|
|
Py_DECREF(r);
|
|
@@ -393,14 +428,14 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
|
|
return NULL;
|
|
}
|
|
|
|
- wchar_t *p1 = wbuffer;
|
|
- wchar_t *p2 = p1;
|
|
+ p1 = wbuffer;
|
|
+ p2 = p1;
|
|
while ((p2 = wcschr(p1, L'\n')) != NULL) {
|
|
- Py_ssize_t cb = p2 - p1;
|
|
- while (cb >= 0 && (p1[cb] == L'\n' || p1[cb] == L'\r')) {
|
|
- --cb;
|
|
+ line_len = p2 - p1;
|
|
+ while (line_len >= 0 && (p1[line_len] == L'\n' || p1[line_len] == L'\r')) {
|
|
+ --line_len;
|
|
}
|
|
- PyObject *u = PyUnicode_FromWideChar(p1, cb >= 0 ? cb + 1 : 0);
|
|
+ u = PyUnicode_FromWideChar(p1, line_len >= 0 ? line_len + 1 : 0);
|
|
if (!u || PyList_Append(r, u) < 0) {
|
|
Py_XDECREF(u);
|
|
Py_CLEAR(r);
|
|
@@ -410,7 +445,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args)
|
|
p1 = p2 + 1;
|
|
}
|
|
if (r && p1 && *p1) {
|
|
- PyObject *u = PyUnicode_FromWideChar(p1, -1);
|
|
+ u = PyUnicode_FromWideChar(p1, -1);
|
|
if (!u || PyList_Append(r, u) < 0) {
|
|
Py_CLEAR(r);
|
|
}
|
|
@@ -562,8 +597,11 @@ static PyMethodDef getpath_nowarn_method = {"warn", getpath_nowarn, METH_VARARGS
|
|
static int
|
|
funcs_to_dict(PyObject *dict, int warnings)
|
|
{
|
|
- for (PyMethodDef *m = getpath_methods; m->ml_name; ++m) {
|
|
- PyObject *f = PyCFunction_NewEx(m, NULL, NULL);
|
|
+ PyMethodDef *m;
|
|
+ PyMethodDef *m2;
|
|
+ PyObject *f;
|
|
+ for (m = getpath_methods; m->ml_name; ++m) {
|
|
+ f = PyCFunction_NewEx(m, NULL, NULL);
|
|
if (!f) {
|
|
return 0;
|
|
}
|
|
@@ -573,8 +611,8 @@ funcs_to_dict(PyObject *dict, int warnings)
|
|
}
|
|
Py_DECREF(f);
|
|
}
|
|
- PyMethodDef *m2 = warnings ? &getpath_warn_method : &getpath_nowarn_method;
|
|
- PyObject *f = PyCFunction_NewEx(m2, NULL, NULL);
|
|
+ m2 = warnings ? &getpath_warn_method : &getpath_nowarn_method;
|
|
+ f = PyCFunction_NewEx(m2, NULL, NULL);
|
|
if (!f) {
|
|
return 0;
|
|
}
|
|
@@ -614,9 +652,10 @@ decode_to_dict(PyObject *dict, const char *key, const char *s)
|
|
{
|
|
PyObject *u = NULL;
|
|
int r;
|
|
+ size_t len;
|
|
+ const wchar_t *w;
|
|
if (s && s[0]) {
|
|
- size_t len;
|
|
- const wchar_t *w = Py_DecodeLocale(s, &len);
|
|
+ w = Py_DecodeLocale(s, &len);
|
|
if (w) {
|
|
u = PyUnicode_FromWideChar(w, len);
|
|
PyMem_RawFree((void *)w);
|
|
@@ -639,18 +678,27 @@ env_to_dict(PyObject *dict, const char *key, int and_clear)
|
|
{
|
|
PyObject *u = NULL;
|
|
int r = 0;
|
|
+#ifdef MS_WINDOWS
|
|
+ wchar_t wkey[64];
|
|
+ wchar_t *wp;
|
|
+ const char *p;
|
|
+ const wchar_t *v;
|
|
+#else
|
|
+ const char *v;
|
|
+ size_t len;
|
|
+ const wchar_t *w;
|
|
+#endif
|
|
assert(strncmp(key, "ENV_", 4) == 0);
|
|
assert(strlen(key) < 64);
|
|
#ifdef MS_WINDOWS
|
|
- wchar_t wkey[64];
|
|
// Quick convert to wchar_t, since we know key is ASCII
|
|
- wchar_t *wp = wkey;
|
|
- for (const char *p = &key[4]; *p; ++p) {
|
|
+ wp = wkey;
|
|
+ for (p = &key[4]; *p; ++p) {
|
|
assert(*p < 128);
|
|
*wp++ = *p;
|
|
}
|
|
*wp = L'\0';
|
|
- const wchar_t *v = _wgetenv(wkey);
|
|
+ v = _wgetenv(wkey);
|
|
if (v) {
|
|
u = PyUnicode_FromWideChar(v, -1);
|
|
if (!u) {
|
|
@@ -658,10 +706,9 @@ env_to_dict(PyObject *dict, const char *key, int and_clear)
|
|
}
|
|
}
|
|
#else
|
|
- const char *v = getenv(&key[4]);
|
|
+ v = getenv(&key[4]);
|
|
if (v) {
|
|
- size_t len;
|
|
- const wchar_t *w = Py_DecodeLocale(v, &len);
|
|
+ w = Py_DecodeLocale(v, &len);
|
|
if (w) {
|
|
u = PyUnicode_FromWideChar(w, len);
|
|
if (!u) {
|
|
@@ -709,7 +756,9 @@ static int
|
|
winmodule_to_dict(PyObject *dict, const char *key, HMODULE mod)
|
|
{
|
|
wchar_t *buffer = NULL;
|
|
- for (DWORD cch = 256; buffer == NULL && cch < (1024 * 1024); cch *= 2) {
|
|
+ DWORD cch;
|
|
+ int r;
|
|
+ for (cch = 256; buffer == NULL && cch < (1024 * 1024); cch *= 2) {
|
|
buffer = (wchar_t*)PyMem_RawMalloc(cch * sizeof(wchar_t));
|
|
if (buffer) {
|
|
if (GetModuleFileNameW(mod, buffer, cch) == cch) {
|
|
@@ -718,7 +767,7 @@ winmodule_to_dict(PyObject *dict, const char *key, HMODULE mod)
|
|
}
|
|
}
|
|
}
|
|
- int r = wchar_to_dict(dict, key, buffer);
|
|
+ r = wchar_to_dict(dict, key, buffer);
|
|
PyMem_RawFree(buffer);
|
|
return r;
|
|
}
|
|
@@ -826,6 +875,13 @@ PyStatus
|
|
_PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
|
|
{
|
|
PyStatus status = _PyPathConfig_ReadGlobal(config);
|
|
+ PyObject *configDict;
|
|
+ PyObject *dict;
|
|
+ PyObject *co;
|
|
+#ifdef MS_WINDOWS
|
|
+ PyObject *winreg;
|
|
+#endif
|
|
+ PyObject *r;
|
|
|
|
if (_PyStatus_EXCEPTION(status) || !compute_path_config) {
|
|
return status;
|
|
@@ -835,13 +891,13 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
|
|
return PyStatus_Error("cannot calculate path configuration without GIL");
|
|
}
|
|
|
|
- PyObject *configDict = _PyConfig_AsDict(config);
|
|
+ configDict = _PyConfig_AsDict(config);
|
|
if (!configDict) {
|
|
PyErr_Clear();
|
|
return PyStatus_NoMemory();
|
|
}
|
|
|
|
- PyObject *dict = PyDict_New();
|
|
+ dict = PyDict_New();
|
|
if (!dict) {
|
|
PyErr_Clear();
|
|
Py_DECREF(configDict);
|
|
@@ -857,7 +913,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
|
|
/* reference now held by dict */
|
|
Py_DECREF(configDict);
|
|
|
|
- PyObject *co = _Py_Get_Getpath_CodeObject();
|
|
+ co = _Py_Get_Getpath_CodeObject();
|
|
if (!co || !PyCode_Check(co)) {
|
|
PyErr_Clear();
|
|
Py_XDECREF(co);
|
|
@@ -866,7 +922,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
|
|
}
|
|
|
|
#ifdef MS_WINDOWS
|
|
- PyObject *winreg = PyImport_ImportModule("winreg");
|
|
+ winreg = PyImport_ImportModule("winreg");
|
|
if (!winreg || PyDict_SetItemString(dict, "winreg", winreg) < 0) {
|
|
PyErr_Clear();
|
|
Py_XDECREF(winreg);
|
|
@@ -924,7 +980,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
|
|
return PyStatus_Error("error evaluating initial values");
|
|
}
|
|
|
|
- PyObject *r = PyEval_EvalCode(co, dict, dict);
|
|
+ r = PyEval_EvalCode(co, dict, dict);
|
|
Py_DECREF(co);
|
|
|
|
if (!r) {
|
|
diff --git a/Modules/main.c b/Modules/main.c
|
|
index f6dade1..011ae59 100644
|
|
--- a/Modules/main.c
|
|
+++ b/Modules/main.c
|
|
@@ -35,13 +35,14 @@ static PyStatus
|
|
pymain_init(const _PyArgv *args)
|
|
{
|
|
PyStatus status;
|
|
+ PyPreConfig preconfig;
|
|
+ PyConfig config;
|
|
|
|
status = _PyRuntime_Initialize();
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
|
|
- PyPreConfig preconfig;
|
|
PyPreConfig_InitPythonConfig(&preconfig);
|
|
|
|
status = _Py_PreInitializeFromPyArgv(&preconfig, args);
|
|
@@ -49,7 +50,6 @@ pymain_init(const _PyArgv *args)
|
|
return status;
|
|
}
|
|
|
|
- PyConfig config;
|
|
PyConfig_InitPythonConfig(&config);
|
|
|
|
/* pass NULL as the config: config is read from command line arguments,
|
|
@@ -68,7 +68,13 @@ pymain_init(const _PyArgv *args)
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
goto done;
|
|
}
|
|
- status = _PyStatus_OK();
|
|
+ /* VC6 (MSVC600) has no C99 compound literals, so _PyStatus_OK() (a
|
|
+ compound literal macro) cannot be used here; PyStatus_Ok() is the
|
|
+ public API function that returns the identical value
|
|
+ (Python/initconfig.c: `PyStatus PyStatus_Ok(void) { return
|
|
+ _PyStatus_OK(); }`), so this is not a behavior change for any
|
|
+ compiler. */
|
|
+ status = PyStatus_Ok();
|
|
|
|
done:
|
|
PyConfig_Clear(&config);
|
|
@@ -202,6 +208,8 @@ pymain_header(const PyConfig *config)
|
|
static void
|
|
pymain_import_readline(const PyConfig *config)
|
|
{
|
|
+ PyObject *mod;
|
|
+
|
|
if (config->isolated) {
|
|
return;
|
|
}
|
|
@@ -212,7 +220,7 @@ pymain_import_readline(const PyConfig *config)
|
|
return;
|
|
}
|
|
|
|
- PyObject *mod = PyImport_ImportModule("readline");
|
|
+ mod = PyImport_ImportModule("readline");
|
|
if (mod == NULL) {
|
|
PyErr_Clear();
|
|
}
|
|
@@ -234,6 +242,7 @@ pymain_run_command(wchar_t *command)
|
|
{
|
|
PyObject *unicode, *bytes;
|
|
int ret;
|
|
+ PyCompilerFlags cf;
|
|
|
|
unicode = PyUnicode_FromWideChar(command, -1);
|
|
if (unicode == NULL) {
|
|
@@ -250,7 +259,12 @@ pymain_run_command(wchar_t *command)
|
|
goto error;
|
|
}
|
|
|
|
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
|
+ /* VC6 has no C99 compound literals/designated initializers, so
|
|
+ _PyCompilerFlags_INIT (`(PyCompilerFlags){.cf_flags = 0,
|
|
+ .cf_feature_version = PY_MINOR_VERSION}`) cannot be used as an
|
|
+ initializer here; assign the same two fields explicitly instead. */
|
|
+ cf.cf_flags = 0;
|
|
+ cf.cf_feature_version = PY_MINOR_VERSION;
|
|
cf.cf_flags |= PyCF_IGNORE_COOKIE;
|
|
ret = PyRun_SimpleStringFlags(PyBytes_AsString(bytes), &cf);
|
|
Py_DECREF(bytes);
|
|
@@ -317,11 +331,16 @@ static int
|
|
pymain_run_file_obj(PyObject *program_name, PyObject *filename,
|
|
int skip_source_first_line)
|
|
{
|
|
+ FILE *fp;
|
|
+ struct _Py_stat_struct sb;
|
|
+ PyCompilerFlags cf;
|
|
+ int run;
|
|
+
|
|
if (PySys_Audit("cpython.run_file", "O", filename) < 0) {
|
|
return pymain_exit_err_print();
|
|
}
|
|
|
|
- FILE *fp = _Py_fopen_obj(filename, "rb");
|
|
+ fp = _Py_fopen_obj(filename, "rb");
|
|
if (fp == NULL) {
|
|
// Ignore the OSError
|
|
PyErr_Clear();
|
|
@@ -341,7 +360,6 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename,
|
|
}
|
|
}
|
|
|
|
- struct _Py_stat_struct sb;
|
|
if (_Py_fstat_noraise(fileno(fp), &sb) == 0 && S_ISDIR(sb.st_mode)) {
|
|
PySys_FormatStderr("%S: %R is a directory, cannot continue\n",
|
|
program_name, filename);
|
|
@@ -356,28 +374,35 @@ pymain_run_file_obj(PyObject *program_name, PyObject *filename,
|
|
}
|
|
|
|
/* PyRun_AnyFileExFlags(closeit=1) calls fclose(fp) before running code */
|
|
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
|
- int run = _PyRun_AnyFileObject(fp, filename, 1, &cf);
|
|
+ /* See pymain_run_command() above for why this is not
|
|
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
|
|
+ cf.cf_flags = 0;
|
|
+ cf.cf_feature_version = PY_MINOR_VERSION;
|
|
+ run = _PyRun_AnyFileObject(fp, filename, 1, &cf);
|
|
return (run != 0);
|
|
}
|
|
|
|
static int
|
|
pymain_run_file(const PyConfig *config)
|
|
{
|
|
- PyObject *filename = PyUnicode_FromWideChar(config->run_filename, -1);
|
|
+ PyObject *filename;
|
|
+ PyObject *program_name;
|
|
+ int res;
|
|
+
|
|
+ filename = PyUnicode_FromWideChar(config->run_filename, -1);
|
|
if (filename == NULL) {
|
|
PyErr_Print();
|
|
return -1;
|
|
}
|
|
- PyObject *program_name = PyUnicode_FromWideChar(config->program_name, -1);
|
|
+ program_name = PyUnicode_FromWideChar(config->program_name, -1);
|
|
if (program_name == NULL) {
|
|
Py_DECREF(filename);
|
|
PyErr_Print();
|
|
return -1;
|
|
}
|
|
|
|
- int res = pymain_run_file_obj(program_name, filename,
|
|
- config->skip_source_first_line);
|
|
+ res = pymain_run_file_obj(program_name, filename,
|
|
+ config->skip_source_first_line);
|
|
Py_DECREF(filename);
|
|
Py_DECREF(program_name);
|
|
return res;
|
|
@@ -388,12 +413,20 @@ static int
|
|
pymain_run_startup(PyConfig *config, int *exitcode)
|
|
{
|
|
int ret;
|
|
+ PyObject *startup = NULL;
|
|
+#ifdef MS_WINDOWS
|
|
+ const wchar_t *env;
|
|
+#else
|
|
+ const char *env;
|
|
+#endif
|
|
+ FILE *fp;
|
|
+ PyCompilerFlags cf;
|
|
+
|
|
if (!config->use_environment) {
|
|
return 0;
|
|
}
|
|
- PyObject *startup = NULL;
|
|
#ifdef MS_WINDOWS
|
|
- const wchar_t *env = _wgetenv(L"PYTHONSTARTUP");
|
|
+ env = _wgetenv(L"PYTHONSTARTUP");
|
|
if (env == NULL || env[0] == L'\0') {
|
|
return 0;
|
|
}
|
|
@@ -402,7 +435,7 @@ pymain_run_startup(PyConfig *config, int *exitcode)
|
|
goto error;
|
|
}
|
|
#else
|
|
- const char *env = _Py_GetEnv(config->use_environment, "PYTHONSTARTUP");
|
|
+ env = _Py_GetEnv(config->use_environment, "PYTHONSTARTUP");
|
|
if (env == NULL) {
|
|
return 0;
|
|
}
|
|
@@ -415,7 +448,7 @@ pymain_run_startup(PyConfig *config, int *exitcode)
|
|
goto error;
|
|
}
|
|
|
|
- FILE *fp = _Py_fopen_obj(startup, "r");
|
|
+ fp = _Py_fopen_obj(startup, "r");
|
|
if (fp == NULL) {
|
|
int save_errno = errno;
|
|
PyErr_Clear();
|
|
@@ -426,7 +459,10 @@ pymain_run_startup(PyConfig *config, int *exitcode)
|
|
goto error;
|
|
}
|
|
|
|
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
|
+ /* See pymain_run_command() above for why this is not
|
|
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
|
|
+ cf.cf_flags = 0;
|
|
+ cf.cf_feature_version = PY_MINOR_VERSION;
|
|
(void) _PyRun_SimpleFileObject(fp, startup, 0, &cf);
|
|
PyErr_Clear();
|
|
fclose(fp);
|
|
@@ -482,11 +518,15 @@ pymain_run_interactive_hook(int *exitcode)
|
|
static int
|
|
pymain_run_stdin(PyConfig *config)
|
|
{
|
|
+ PyCompilerFlags cf;
|
|
+ int run;
|
|
+
|
|
if (stdin_is_interactive(config)) {
|
|
+ int exitcode;
|
|
+
|
|
config->inspect = 0;
|
|
Py_InspectFlag = 0; /* do exit on SystemExit */
|
|
|
|
- int exitcode;
|
|
if (pymain_run_startup(config, &exitcode)) {
|
|
return exitcode;
|
|
}
|
|
@@ -505,8 +545,11 @@ pymain_run_stdin(PyConfig *config)
|
|
return pymain_exit_err_print();
|
|
}
|
|
|
|
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
|
- int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
|
|
+ /* See pymain_run_command() above for why this is not
|
|
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
|
|
+ cf.cf_flags = 0;
|
|
+ cf.cf_feature_version = PY_MINOR_VERSION;
|
|
+ run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
|
|
return (run != 0);
|
|
}
|
|
|
|
@@ -514,6 +557,9 @@ pymain_run_stdin(PyConfig *config)
|
|
static void
|
|
pymain_repl(PyConfig *config, int *exitcode)
|
|
{
|
|
+ PyCompilerFlags cf;
|
|
+ int res;
|
|
+
|
|
/* Check this environment variable at the end, to give programs the
|
|
opportunity to set it from Python. */
|
|
if (!config->inspect && _Py_GetEnv(config->use_environment, "PYTHONINSPECT")) {
|
|
@@ -535,8 +581,11 @@ pymain_repl(PyConfig *config, int *exitcode)
|
|
return;
|
|
}
|
|
|
|
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
|
|
- int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
|
|
+ /* See pymain_run_command() above for why this is not
|
|
+ _PyCompilerFlags_INIT (VC6 has no compound literals). */
|
|
+ cf.cf_flags = 0;
|
|
+ cf.cf_feature_version = PY_MINOR_VERSION;
|
|
+ res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
|
|
*exitcode = (res != 0);
|
|
}
|
|
|
|
@@ -718,11 +767,15 @@ pymain_main(_PyArgv *args)
|
|
int
|
|
Py_Main(int argc, wchar_t **argv)
|
|
{
|
|
- _PyArgv args = {
|
|
- .argc = argc,
|
|
- .use_bytes_argv = 0,
|
|
- .bytes_argv = NULL,
|
|
- .wchar_argv = argv};
|
|
+ /* VC6 has no C99 designated initializers, so the aggregate initializer
|
|
+ below cannot be used; assign each field explicitly instead (field
|
|
+ order does not matter for plain assignment, unlike the initializer
|
|
+ list it replaces). */
|
|
+ _PyArgv args;
|
|
+ args.argc = argc;
|
|
+ args.use_bytes_argv = 0;
|
|
+ args.bytes_argv = NULL;
|
|
+ args.wchar_argv = argv;
|
|
return pymain_main(&args);
|
|
}
|
|
|
|
@@ -730,11 +783,12 @@ Py_Main(int argc, wchar_t **argv)
|
|
int
|
|
Py_BytesMain(int argc, char **argv)
|
|
{
|
|
- _PyArgv args = {
|
|
- .argc = argc,
|
|
- .use_bytes_argv = 1,
|
|
- .bytes_argv = argv,
|
|
- .wchar_argv = NULL};
|
|
+ /* See Py_Main() above: VC6 has no C99 designated initializers. */
|
|
+ _PyArgv args;
|
|
+ args.argc = argc;
|
|
+ args.use_bytes_argv = 1;
|
|
+ args.bytes_argv = argv;
|
|
+ args.wchar_argv = NULL;
|
|
return pymain_main(&args);
|
|
}
|
|
|
|
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
|
|
index 959b851..6d8ce84 100644
|
|
--- a/PC/pyconfig.h
|
|
+++ b/PC/pyconfig.h
|
|
@@ -256,6 +256,19 @@ typedef int pid_t;
|
|
# define PY_ULLONG_MAX _UI64_MAX
|
|
#endif
|
|
|
|
+/* Spelling of 64 bit integer literal suffixes. MSVC before Visual C++ .NET
|
|
+ (_MSC_VER < 1300, i.e. Visual C++ 6.0 and earlier) rejects the C99 LL/ULL
|
|
+ suffixes and spells them i64/ui64 instead. */
|
|
+#ifndef PY_LL
|
|
+# if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+# define PY_LL(x) x##i64
|
|
+# define PY_ULL(x) x##ui64
|
|
+# else
|
|
+# define PY_LL(x) x##LL
|
|
+# define PY_ULL(x) x##ULL
|
|
+# endif
|
|
+#endif
|
|
+
|
|
/* For Windows the Python core is in a DLL by default. Test
|
|
Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
|
|
#if !defined(MS_NO_COREDLL) && !defined(Py_NO_ENABLE_SHARED)
|
|
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
|
|
index 9248e97..4abd5d4 100644
|
|
--- a/Python/pylifecycle.c
|
|
+++ b/Python/pylifecycle.c
|
|
@@ -88,8 +88,14 @@ _Py_COMP_DIAG_IGNORE_DEPR_DECLS
|
|
|
|
#if defined(MS_WINDOWS)
|
|
|
|
+# if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+/* VC6 does not support #pragma section plus __declspec(allocate()).
|
|
+ Use its older data_seg spelling for this initialized object instead. */
|
|
+# pragma data_seg("PyRuntime")
|
|
+# else
|
|
#pragma section("PyRuntime", read, write)
|
|
__declspec(allocate("PyRuntime"))
|
|
+# endif
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
@@ -103,10 +109,20 @@ _PyRuntimeState _PyRuntime
|
|
#if defined(__linux__) && (defined(__GNUC__) || defined(__clang__))
|
|
__attribute__ ((section (".PyRuntime")))
|
|
#endif
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+;
|
|
+#else
|
|
= _PyRuntimeState_INIT;
|
|
+#endif
|
|
+#if defined(MS_WINDOWS) && defined(_MSC_VER) && _MSC_VER < 1300
|
|
+# pragma data_seg()
|
|
+#endif
|
|
_Py_COMP_DIAG_POP
|
|
|
|
static int runtime_initialized = 0;
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+static int runtime_static_initialized = 0;
|
|
+#endif
|
|
|
|
PyStatus
|
|
_PyRuntime_Initialize(void)
|
|
@@ -117,6 +133,12 @@ _PyRuntime_Initialize(void)
|
|
every Py_Initialize() call, but doing so breaks the runtime.
|
|
This is because the runtime state is not properly finalized
|
|
currently. */
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+ if (!runtime_static_initialized) {
|
|
+ _PyRuntimeState_InitStaticDefaults(&_PyRuntime);
|
|
+ runtime_static_initialized = 1;
|
|
+ }
|
|
+#endif
|
|
if (runtime_initialized) {
|
|
return _PyStatus_OK();
|
|
}
|
|
@@ -175,10 +197,16 @@ Py_IsInitialized(void)
|
|
static int
|
|
init_importlib(PyThreadState *tstate, PyObject *sysmod)
|
|
{
|
|
+ PyInterpreterState *interp;
|
|
+ int verbose;
|
|
+ PyObject *importlib;
|
|
+ PyObject *imp_mod;
|
|
+ PyObject *value;
|
|
+
|
|
assert(!_PyErr_Occurred(tstate));
|
|
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
- int verbose = _PyInterpreterState_GetConfig(interp)->verbose;
|
|
+ interp = tstate->interp;
|
|
+ verbose = _PyInterpreterState_GetConfig(interp)->verbose;
|
|
|
|
// Import _importlib through its frozen version, _frozen_importlib.
|
|
if (verbose) {
|
|
@@ -187,7 +215,7 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
|
|
if (PyImport_ImportFrozenModule("_frozen_importlib") <= 0) {
|
|
return -1;
|
|
}
|
|
- PyObject *importlib = PyImport_AddModule("_frozen_importlib"); // borrowed
|
|
+ importlib = PyImport_AddModule("_frozen_importlib"); // borrowed
|
|
if (importlib == NULL) {
|
|
return -1;
|
|
}
|
|
@@ -197,7 +225,7 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
|
|
if (verbose) {
|
|
PySys_FormatStderr("import _imp # builtin\n");
|
|
}
|
|
- PyObject *imp_mod = _PyImport_BootstrapImp(tstate);
|
|
+ imp_mod = _PyImport_BootstrapImp(tstate);
|
|
if (imp_mod == NULL) {
|
|
return -1;
|
|
}
|
|
@@ -207,8 +235,8 @@ init_importlib(PyThreadState *tstate, PyObject *sysmod)
|
|
}
|
|
|
|
// Install importlib as the implementation of import
|
|
- PyObject *value = PyObject_CallMethod(importlib, "_install",
|
|
- "OO", sysmod, imp_mod);
|
|
+ value = PyObject_CallMethod(importlib, "_install",
|
|
+ "OO", sysmod, imp_mod);
|
|
Py_DECREF(imp_mod);
|
|
if (value == NULL) {
|
|
return -1;
|
|
@@ -464,9 +492,10 @@ static int
|
|
interpreter_update_config(PyThreadState *tstate, int only_update_path_config)
|
|
{
|
|
const PyConfig *config = &tstate->interp->config;
|
|
+ PyStatus status;
|
|
|
|
if (!only_update_path_config) {
|
|
- PyStatus status = _PyConfig_Write(config, tstate->interp->runtime);
|
|
+ status = _PyConfig_Write(config, tstate->interp->runtime);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
_PyErr_SetFromPyStatus(status);
|
|
return -1;
|
|
@@ -474,7 +503,7 @@ interpreter_update_config(PyThreadState *tstate, int only_update_path_config)
|
|
}
|
|
|
|
if (_Py_IsMainInterpreter(tstate->interp)) {
|
|
- PyStatus status = _PyPathConfig_UpdateGlobal(config);
|
|
+ status = _PyPathConfig_UpdateGlobal(config);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
_PyErr_SetFromPyStatus(status);
|
|
return -1;
|
|
@@ -494,10 +523,11 @@ _PyInterpreterState_SetConfig(const PyConfig *src_config)
|
|
{
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
|
int res = -1;
|
|
-
|
|
PyConfig config;
|
|
+ PyStatus status;
|
|
+
|
|
PyConfig_InitPythonConfig(&config);
|
|
- PyStatus status = _PyConfig_Copy(&config, src_config);
|
|
+ status = _PyConfig_Copy(&config, src_config);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
_PyErr_SetFromPyStatus(status);
|
|
goto done;
|
|
@@ -542,12 +572,13 @@ pyinit_core_reconfigure(_PyRuntimeState *runtime,
|
|
{
|
|
PyStatus status;
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
|
+ PyInterpreterState *interp;
|
|
if (!tstate) {
|
|
return _PyStatus_ERR("failed to read thread state");
|
|
}
|
|
*tstate_p = tstate;
|
|
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
+ interp = tstate->interp;
|
|
if (interp == NULL) {
|
|
return _PyStatus_ERR("can't make main interpreter");
|
|
}
|
|
@@ -577,11 +608,13 @@ static PyStatus
|
|
pycore_init_runtime(_PyRuntimeState *runtime,
|
|
const PyConfig *config)
|
|
{
|
|
+ PyStatus status;
|
|
+
|
|
if (runtime->initialized) {
|
|
return _PyStatus_ERR("main interpreter already initialized");
|
|
}
|
|
|
|
- PyStatus status = _PyConfig_Write(config, runtime);
|
|
+ status = _PyConfig_Write(config, runtime);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
@@ -640,13 +673,17 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
|
|
const PyConfig *config,
|
|
PyThreadState **tstate_p)
|
|
{
|
|
+ PyStatus status;
|
|
+ PyInterpreterState *interp;
|
|
+ PyThreadState *tstate;
|
|
+
|
|
/* Auto-thread-state API */
|
|
- PyStatus status = _PyGILState_Init(runtime);
|
|
+ status = _PyGILState_Init(runtime);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
|
|
- PyInterpreterState *interp = PyInterpreterState_New();
|
|
+ interp = PyInterpreterState_New();
|
|
if (interp == NULL) {
|
|
return _PyStatus_ERR("can't make main interpreter");
|
|
}
|
|
@@ -657,7 +694,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
|
|
return status;
|
|
}
|
|
|
|
- PyThreadState *tstate = PyThreadState_New(interp);
|
|
+ tstate = PyThreadState_New(interp);
|
|
if (tstate == NULL) {
|
|
return _PyStatus_ERR("can't make first thread");
|
|
}
|
|
@@ -762,8 +799,14 @@ static PyStatus
|
|
pycore_init_builtins(PyThreadState *tstate)
|
|
{
|
|
PyInterpreterState *interp = tstate->interp;
|
|
-
|
|
- PyObject *bimod = _PyBuiltin_Init(interp);
|
|
+ PyObject *bimod;
|
|
+ PyObject *builtins_dict;
|
|
+ PyObject *isinstance;
|
|
+ PyObject *len;
|
|
+ PyObject *list_append;
|
|
+ PyObject *import_func;
|
|
+
|
|
+ bimod = _PyBuiltin_Init(interp);
|
|
if (bimod == NULL) {
|
|
goto error;
|
|
}
|
|
@@ -772,20 +815,20 @@ pycore_init_builtins(PyThreadState *tstate)
|
|
goto error;
|
|
}
|
|
|
|
- PyObject *builtins_dict = PyModule_GetDict(bimod);
|
|
+ builtins_dict = PyModule_GetDict(bimod);
|
|
if (builtins_dict == NULL) {
|
|
goto error;
|
|
}
|
|
Py_INCREF(builtins_dict);
|
|
interp->builtins = builtins_dict;
|
|
|
|
- PyObject *isinstance = PyDict_GetItem(builtins_dict, &_Py_ID(isinstance));
|
|
+ isinstance = PyDict_GetItem(builtins_dict, &_Py_ID(isinstance));
|
|
assert(isinstance);
|
|
interp->callable_cache.isinstance = isinstance;
|
|
- PyObject *len = PyDict_GetItem(builtins_dict, &_Py_ID(len));
|
|
+ len = PyDict_GetItem(builtins_dict, &_Py_ID(len));
|
|
assert(len);
|
|
interp->callable_cache.len = len;
|
|
- PyObject *list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
|
|
+ list_append = _PyType_Lookup(&PyList_Type, &_Py_ID(append));
|
|
assert(list_append);
|
|
interp->callable_cache.list_append = list_append;
|
|
|
|
@@ -800,8 +843,8 @@ pycore_init_builtins(PyThreadState *tstate)
|
|
Py_DECREF(bimod);
|
|
|
|
// Get the __import__ function
|
|
- PyObject *import_func = _PyDict_GetItemStringWithError(interp->builtins,
|
|
- "__import__");
|
|
+ import_func = _PyDict_GetItemStringWithError(interp->builtins,
|
|
+ "__import__");
|
|
if (import_func == NULL) {
|
|
goto error;
|
|
}
|
|
@@ -822,6 +865,7 @@ pycore_interp_init(PyThreadState *tstate)
|
|
PyInterpreterState *interp = tstate->interp;
|
|
PyStatus status;
|
|
PyObject *sysmod = NULL;
|
|
+ const PyConfig *config;
|
|
|
|
// Create singletons before the first PyType_Ready() call, since
|
|
// PyType_Ready() uses singletons like the Unicode empty string (tp_doc)
|
|
@@ -866,7 +910,7 @@ pycore_interp_init(PyThreadState *tstate)
|
|
goto done;
|
|
}
|
|
|
|
- const PyConfig *config = _PyInterpreterState_GetConfig(interp);
|
|
+ config = _PyInterpreterState_GetConfig(interp);
|
|
if (config->_install_importlib) {
|
|
/* This call sets up builtin and frozen import support */
|
|
if (init_importlib(tstate, sysmod) < 0) {
|
|
@@ -886,12 +930,14 @@ pyinit_config(_PyRuntimeState *runtime,
|
|
PyThreadState **tstate_p,
|
|
const PyConfig *config)
|
|
{
|
|
- PyStatus status = pycore_init_runtime(runtime, config);
|
|
+ PyStatus status;
|
|
+ PyThreadState *tstate;
|
|
+
|
|
+ status = pycore_init_runtime(runtime, config);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
|
|
- PyThreadState *tstate;
|
|
status = pycore_create_interpreter(runtime, config, &tstate);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
@@ -913,6 +959,8 @@ PyStatus
|
|
_Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
|
|
{
|
|
PyStatus status;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyPreConfig config;
|
|
|
|
if (src_config == NULL) {
|
|
return _PyStatus_ERR("preinitialization config is NULL");
|
|
@@ -922,7 +970,7 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
+ runtime = &_PyRuntime;
|
|
|
|
if (runtime->preinitialized) {
|
|
/* If it's already configured: ignored the new configuration */
|
|
@@ -933,8 +981,6 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
|
|
at exit on success. */
|
|
runtime->preinitializing = 1;
|
|
|
|
- PyPreConfig config;
|
|
-
|
|
status = _PyPreConfig_InitFromPreConfig(&config, src_config);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
@@ -959,7 +1005,11 @@ _Py_PreInitializeFromPyArgv(const PyPreConfig *src_config, const _PyArgv *args)
|
|
PyStatus
|
|
Py_PreInitializeFromBytesArgs(const PyPreConfig *src_config, Py_ssize_t argc, char **argv)
|
|
{
|
|
- _PyArgv args = {.use_bytes_argv = 1, .argc = argc, .bytes_argv = argv};
|
|
+ _PyArgv args;
|
|
+
|
|
+ args.use_bytes_argv = 1;
|
|
+ args.argc = argc;
|
|
+ args.bytes_argv = argv;
|
|
return _Py_PreInitializeFromPyArgv(src_config, &args);
|
|
}
|
|
|
|
@@ -967,7 +1017,11 @@ Py_PreInitializeFromBytesArgs(const PyPreConfig *src_config, Py_ssize_t argc, ch
|
|
PyStatus
|
|
Py_PreInitializeFromArgs(const PyPreConfig *src_config, Py_ssize_t argc, wchar_t **argv)
|
|
{
|
|
- _PyArgv args = {.use_bytes_argv = 0, .argc = argc, .wchar_argv = argv};
|
|
+ _PyArgv args;
|
|
+
|
|
+ args.use_bytes_argv = 0;
|
|
+ args.argc = argc;
|
|
+ args.wchar_argv = argv;
|
|
return _Py_PreInitializeFromPyArgv(src_config, &args);
|
|
}
|
|
|
|
@@ -983,31 +1037,33 @@ PyStatus
|
|
_Py_PreInitializeFromConfig(const PyConfig *config,
|
|
const _PyArgv *args)
|
|
{
|
|
+ PyStatus status;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyPreConfig preconfig;
|
|
+ _PyArgv config_args;
|
|
+
|
|
assert(config != NULL);
|
|
|
|
- PyStatus status = _PyRuntime_Initialize();
|
|
+ status = _PyRuntime_Initialize();
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
+ runtime = &_PyRuntime;
|
|
|
|
if (runtime->preinitialized) {
|
|
/* Already initialized: do nothing */
|
|
return _PyStatus_OK();
|
|
}
|
|
|
|
- PyPreConfig preconfig;
|
|
-
|
|
_PyPreConfig_InitFromConfig(&preconfig, config);
|
|
|
|
if (!config->parse_argv) {
|
|
return Py_PreInitialize(&preconfig);
|
|
}
|
|
else if (args == NULL) {
|
|
- _PyArgv config_args = {
|
|
- .use_bytes_argv = 0,
|
|
- .argc = config->argv.length,
|
|
- .wchar_argv = config->argv.items};
|
|
+ config_args.use_bytes_argv = 0;
|
|
+ config_args.argc = config->argv.length;
|
|
+ config_args.wchar_argv = config->argv.items;
|
|
return _Py_PreInitializeFromPyArgv(&preconfig, &config_args);
|
|
}
|
|
else {
|
|
@@ -1039,13 +1095,13 @@ pyinit_core(_PyRuntimeState *runtime,
|
|
PyThreadState **tstate_p)
|
|
{
|
|
PyStatus status;
|
|
+ PyConfig config;
|
|
|
|
status = _Py_PreInitializeFromConfig(src_config, NULL);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
|
|
- PyConfig config;
|
|
PyConfig_InitPythonConfig(&config);
|
|
|
|
status = _PyConfig_Copy(&config, src_config);
|
|
@@ -1093,14 +1149,13 @@ static PyStatus
|
|
init_interp_main(PyThreadState *tstate)
|
|
{
|
|
extern void _PyThread_debug_deprecation(void);
|
|
-
|
|
- assert(!_PyErr_Occurred(tstate));
|
|
-
|
|
PyStatus status;
|
|
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
|
|
PyInterpreterState *interp = tstate->interp;
|
|
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
|
|
|
|
+ assert(!_PyErr_Occurred(tstate));
|
|
+
|
|
if (!config->_install_importlib) {
|
|
/* Special mode for freeze_importlib: run with no import system
|
|
*
|
|
@@ -1218,7 +1273,10 @@ init_interp_main(PyThreadState *tstate)
|
|
static PyStatus
|
|
pyinit_main(PyThreadState *tstate)
|
|
{
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
+ PyInterpreterState *interp;
|
|
+ PyStatus status;
|
|
+
|
|
+ interp = tstate->interp;
|
|
if (!interp->runtime->core_initialized) {
|
|
return _PyStatus_ERR("runtime core not initialized");
|
|
}
|
|
@@ -1227,7 +1285,7 @@ pyinit_main(PyThreadState *tstate)
|
|
return pyinit_main_reconfigure(tstate);
|
|
}
|
|
|
|
- PyStatus status = init_interp_main(tstate);
|
|
+ status = init_interp_main(tstate);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
@@ -1238,19 +1296,21 @@ pyinit_main(PyThreadState *tstate)
|
|
PyStatus
|
|
Py_InitializeFromConfig(const PyConfig *config)
|
|
{
|
|
+ PyStatus status;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyThreadState *tstate;
|
|
+
|
|
if (config == NULL) {
|
|
return _PyStatus_ERR("initialization config is NULL");
|
|
}
|
|
|
|
- PyStatus status;
|
|
-
|
|
status = _PyRuntime_Initialize();
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
+ runtime = &_PyRuntime;
|
|
|
|
- PyThreadState *tstate = NULL;
|
|
+ tstate = NULL;
|
|
status = pyinit_core(runtime, config, &tstate);
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
@@ -1272,19 +1332,20 @@ void
|
|
Py_InitializeEx(int install_sigs)
|
|
{
|
|
PyStatus status;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyConfig config;
|
|
|
|
status = _PyRuntime_Initialize();
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
Py_ExitStatusException(status);
|
|
}
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
+ runtime = &_PyRuntime;
|
|
|
|
if (runtime->initialized) {
|
|
/* bpo-33932: Calling Py_Initialize() twice does nothing. */
|
|
return;
|
|
}
|
|
|
|
- PyConfig config;
|
|
_PyConfig_InitCompatConfig(&config);
|
|
|
|
config.install_signal_handlers = install_sigs;
|
|
@@ -1302,20 +1363,24 @@ Py_Initialize(void)
|
|
Py_InitializeEx(1);
|
|
}
|
|
|
|
-
|
|
PyStatus
|
|
_Py_InitializeMain(void)
|
|
{
|
|
- PyStatus status = _PyRuntime_Initialize();
|
|
+ PyStatus status;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyThreadState *tstate;
|
|
+
|
|
+ status = _PyRuntime_Initialize();
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
|
+ runtime = &_PyRuntime;
|
|
+ tstate = _PyRuntimeState_GetThreadState(runtime);
|
|
return pyinit_main(tstate);
|
|
}
|
|
|
|
|
|
+
|
|
static void
|
|
finalize_modules_delete_special(PyThreadState *tstate, int verbose)
|
|
{
|
|
@@ -1336,6 +1401,9 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
|
|
};
|
|
|
|
PyInterpreterState *interp = tstate->interp;
|
|
+ const char * const *p;
|
|
+ PyObject *value;
|
|
+
|
|
if (verbose) {
|
|
PySys_WriteStderr("# clear builtins._\n");
|
|
}
|
|
@@ -1343,8 +1411,8 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
|
|
PyErr_WriteUnraisable(NULL);
|
|
}
|
|
|
|
- const char * const *p;
|
|
- for (p = sys_deletes; *p != NULL; p++) {
|
|
+ p = sys_deletes;
|
|
+ for (; *p != NULL; p++) {
|
|
if (verbose) {
|
|
PySys_WriteStderr("# clear sys.%s\n", *p);
|
|
}
|
|
@@ -1358,8 +1426,8 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
|
|
if (verbose) {
|
|
PySys_WriteStderr("# restore sys.%s\n", name);
|
|
}
|
|
- PyObject *value = _PyDict_GetItemStringWithError(interp->sysdict,
|
|
- orig_name);
|
|
+ value = _PyDict_GetItemStringWithError(interp->sysdict,
|
|
+ orig_name);
|
|
if (value == NULL) {
|
|
if (_PyErr_Occurred(tstate)) {
|
|
PyErr_WriteUnraisable(NULL);
|
|
@@ -1479,16 +1547,22 @@ static void
|
|
finalize_modules_clear_weaklist(PyInterpreterState *interp,
|
|
PyObject *weaklist, int verbose)
|
|
{
|
|
+ Py_ssize_t i;
|
|
+ PyObject *tup;
|
|
+ PyObject *name;
|
|
+ PyObject *mod;
|
|
+ PyObject *dict;
|
|
+
|
|
// First clear modules imported later
|
|
- for (Py_ssize_t i = PyList_GET_SIZE(weaklist) - 1; i >= 0; i--) {
|
|
- PyObject *tup = PyList_GET_ITEM(weaklist, i);
|
|
- PyObject *name = PyTuple_GET_ITEM(tup, 0);
|
|
- PyObject *mod = PyWeakref_GET_OBJECT(PyTuple_GET_ITEM(tup, 1));
|
|
+ for (i = PyList_GET_SIZE(weaklist) - 1; i >= 0; i--) {
|
|
+ tup = PyList_GET_ITEM(weaklist, i);
|
|
+ name = PyTuple_GET_ITEM(tup, 0);
|
|
+ mod = PyWeakref_GET_OBJECT(PyTuple_GET_ITEM(tup, 1));
|
|
if (mod == Py_None) {
|
|
continue;
|
|
}
|
|
assert(PyModule_Check(mod));
|
|
- PyObject *dict = PyModule_GetDict(mod);
|
|
+ dict = PyModule_GetDict(mod);
|
|
if (dict == interp->builtins || dict == interp->sysdict) {
|
|
continue;
|
|
}
|
|
@@ -1525,11 +1599,14 @@ finalize_modules(PyThreadState *tstate)
|
|
{
|
|
PyInterpreterState *interp = tstate->interp;
|
|
PyObject *modules = interp->modules;
|
|
+ int verbose;
|
|
+ PyObject *weaklist;
|
|
+
|
|
if (modules == NULL) {
|
|
// Already done
|
|
return;
|
|
}
|
|
- int verbose = _PyInterpreterState_GetConfig(interp)->verbose;
|
|
+ verbose = _PyInterpreterState_GetConfig(interp)->verbose;
|
|
|
|
// Delete some special builtins._ and sys attributes first. These are
|
|
// common places where user values hide and people complain when their
|
|
@@ -1547,7 +1624,7 @@ finalize_modules(PyThreadState *tstate)
|
|
// modules when they are removed from sys.modules. The name is used
|
|
// for diagnosis messages (in verbose mode), while the weakref helps
|
|
// detect those modules which have been held alive.
|
|
- PyObject *weaklist = finalize_remove_modules(modules, verbose);
|
|
+ weaklist = finalize_remove_modules(modules, verbose);
|
|
|
|
// Clear the modules dict
|
|
finalize_clear_modules_dict(modules);
|
|
@@ -1751,14 +1828,26 @@ int
|
|
Py_FinalizeEx(void)
|
|
{
|
|
int status = 0;
|
|
-
|
|
_PyRuntimeState *runtime = &_PyRuntime;
|
|
+ PyThreadState *tstate;
|
|
+#ifdef Py_REF_DEBUG
|
|
+ int show_ref_count;
|
|
+#endif
|
|
+#ifdef Py_TRACE_REFS
|
|
+ int dump_refs;
|
|
+ wchar_t *dump_refs_file;
|
|
+ FILE *dump_refs_fp;
|
|
+#endif
|
|
+#ifdef WITH_PYMALLOC
|
|
+ int malloc_stats;
|
|
+#endif
|
|
+
|
|
if (!runtime->initialized) {
|
|
return status;
|
|
}
|
|
|
|
/* Get current thread state and interpreter pointer */
|
|
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
|
+ tstate = _PyRuntimeState_GetThreadState(runtime);
|
|
|
|
// Wrap up existing "threading"-module-created, non-daemon threads.
|
|
wait_for_thread_shutdown(tstate);
|
|
@@ -1781,14 +1870,14 @@ Py_FinalizeEx(void)
|
|
/* Copy the core config, PyInterpreterState_Delete() free
|
|
the core config memory */
|
|
#ifdef Py_REF_DEBUG
|
|
- int show_ref_count = tstate->interp->config.show_ref_count;
|
|
+ show_ref_count = tstate->interp->config.show_ref_count;
|
|
#endif
|
|
#ifdef Py_TRACE_REFS
|
|
- int dump_refs = tstate->interp->config.dump_refs;
|
|
- wchar_t *dump_refs_file = tstate->interp->config.dump_refs_file;
|
|
+ dump_refs = tstate->interp->config.dump_refs;
|
|
+ dump_refs_file = tstate->interp->config.dump_refs_file;
|
|
#endif
|
|
#ifdef WITH_PYMALLOC
|
|
- int malloc_stats = tstate->interp->config.malloc_stats;
|
|
+ malloc_stats = tstate->interp->config.malloc_stats;
|
|
#endif
|
|
|
|
/* Remaining daemon threads will automatically exit
|
|
@@ -1879,7 +1968,7 @@ Py_FinalizeEx(void)
|
|
* up later.
|
|
*/
|
|
|
|
- FILE *dump_refs_fp = NULL;
|
|
+ dump_refs_fp = NULL;
|
|
if (dump_refs_file != NULL) {
|
|
dump_refs_fp = _Py_wfopen(dump_refs_file, L"w");
|
|
if (dump_refs_fp == NULL) {
|
|
@@ -1956,12 +2045,17 @@ static PyStatus
|
|
new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
|
|
{
|
|
PyStatus status;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyInterpreterState *interp;
|
|
+ PyThreadState *tstate;
|
|
+ PyThreadState *save_tstate;
|
|
+ const PyConfig *config;
|
|
|
|
status = _PyRuntime_Initialize();
|
|
if (_PyStatus_EXCEPTION(status)) {
|
|
return status;
|
|
}
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
+ runtime = &_PyRuntime;
|
|
|
|
if (!runtime->initialized) {
|
|
return _PyStatus_ERR("Py_Initialize must be called first");
|
|
@@ -1971,23 +2065,22 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter)
|
|
interpreters: disable PyGILState_Check(). */
|
|
runtime->gilstate.check_enabled = 0;
|
|
|
|
- PyInterpreterState *interp = PyInterpreterState_New();
|
|
+ interp = PyInterpreterState_New();
|
|
if (interp == NULL) {
|
|
*tstate_p = NULL;
|
|
return _PyStatus_OK();
|
|
}
|
|
|
|
- PyThreadState *tstate = PyThreadState_New(interp);
|
|
+ tstate = PyThreadState_New(interp);
|
|
if (tstate == NULL) {
|
|
PyInterpreterState_Delete(interp);
|
|
*tstate_p = NULL;
|
|
return _PyStatus_OK();
|
|
}
|
|
|
|
- PyThreadState *save_tstate = PyThreadState_Swap(tstate);
|
|
+ save_tstate = PyThreadState_Swap(tstate);
|
|
|
|
/* Copy the current interpreter config into the new interpreter */
|
|
- const PyConfig *config;
|
|
if (save_tstate != NULL) {
|
|
config = _PyInterpreterState_GetConfig(save_tstate->interp);
|
|
}
|
|
@@ -2099,7 +2192,7 @@ Py_EndInterpreter(PyThreadState *tstate)
|
|
static PyStatus
|
|
add_main_module(PyInterpreterState *interp)
|
|
{
|
|
- PyObject *m, *d, *loader, *ann_dict;
|
|
+ PyObject *m, *d, *loader, *ann_dict, *bimod, *loader_obj;
|
|
m = PyImport_AddModule("__main__");
|
|
if (m == NULL)
|
|
return _PyStatus_ERR("can't create __main__ module");
|
|
@@ -2116,7 +2209,7 @@ add_main_module(PyInterpreterState *interp)
|
|
if (PyErr_Occurred()) {
|
|
return _PyStatus_ERR("Failed to test __main__.__builtins__");
|
|
}
|
|
- PyObject *bimod = PyImport_ImportModule("builtins");
|
|
+ bimod = PyImport_ImportModule("builtins");
|
|
if (bimod == NULL) {
|
|
return _PyStatus_ERR("Failed to retrieve builtins module");
|
|
}
|
|
@@ -2137,15 +2230,15 @@ add_main_module(PyInterpreterState *interp)
|
|
if (PyErr_Occurred()) {
|
|
return _PyStatus_ERR("Failed to test __main__.__loader__");
|
|
}
|
|
- PyObject *loader = PyObject_GetAttrString(interp->importlib,
|
|
- "BuiltinImporter");
|
|
- if (loader == NULL) {
|
|
+ loader_obj = PyObject_GetAttrString(interp->importlib,
|
|
+ "BuiltinImporter");
|
|
+ if (loader_obj == NULL) {
|
|
return _PyStatus_ERR("Failed to retrieve BuiltinImporter");
|
|
}
|
|
- if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
|
|
+ if (PyDict_SetItemString(d, "__loader__", loader_obj) < 0) {
|
|
return _PyStatus_ERR("Failed to initialize __main__.__loader__");
|
|
}
|
|
- Py_DECREF(loader);
|
|
+ Py_DECREF(loader_obj);
|
|
}
|
|
return _PyStatus_OK();
|
|
}
|
|
@@ -2185,6 +2278,18 @@ is_valid_fd(int fd)
|
|
Only use dup() on Linux where dup() is enough to detect invalid FD
|
|
(bpo-32849).
|
|
*/
|
|
+#if defined(F_GETFD) && ( \
|
|
+ defined(__linux__) || \
|
|
+ defined(__APPLE__) || \
|
|
+ defined(__wasm__))
|
|
+#elif defined(__linux__)
|
|
+ int fd2;
|
|
+#elif defined(MS_WINDOWS)
|
|
+ HANDLE hfile;
|
|
+#else
|
|
+ struct stat st;
|
|
+#endif
|
|
+
|
|
if (fd < 0) {
|
|
return 0;
|
|
}
|
|
@@ -2194,20 +2299,18 @@ is_valid_fd(int fd)
|
|
defined(__wasm__))
|
|
return fcntl(fd, F_GETFD) >= 0;
|
|
#elif defined(__linux__)
|
|
- int fd2 = dup(fd);
|
|
+ fd2 = dup(fd);
|
|
if (fd2 >= 0) {
|
|
close(fd2);
|
|
}
|
|
return (fd2 >= 0);
|
|
#elif defined(MS_WINDOWS)
|
|
- HANDLE hfile;
|
|
_Py_BEGIN_SUPPRESS_IPH
|
|
hfile = (HANDLE)_get_osfhandle(fd);
|
|
_Py_END_SUPPRESS_IPH
|
|
return (hfile != INVALID_HANDLE_VALUE
|
|
&& GetFileType(hfile) != FILE_TYPE_UNKNOWN);
|
|
#else
|
|
- struct stat st;
|
|
return (fstat(fd, &st) == 0);
|
|
#endif
|
|
}
|
|
@@ -2219,6 +2322,7 @@ create_stdio(const PyConfig *config, PyObject* io,
|
|
const wchar_t* encoding, const wchar_t* errors)
|
|
{
|
|
PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res;
|
|
+ PyObject *encoding_str, *errors_str;
|
|
const char* mode;
|
|
const char* newline;
|
|
PyObject *line_buffering, *write_through;
|
|
@@ -2297,13 +2401,13 @@ create_stdio(const PyConfig *config, PyObject* io,
|
|
newline = "\n";
|
|
#endif
|
|
|
|
- PyObject *encoding_str = PyUnicode_FromWideChar(encoding, -1);
|
|
+ encoding_str = PyUnicode_FromWideChar(encoding, -1);
|
|
if (encoding_str == NULL) {
|
|
Py_CLEAR(buf);
|
|
goto error;
|
|
}
|
|
|
|
- PyObject *errors_str = PyUnicode_FromWideChar(errors, -1);
|
|
+ errors_str = PyUnicode_FromWideChar(errors, -1);
|
|
if (errors_str == NULL) {
|
|
Py_CLEAR(buf);
|
|
Py_CLEAR(encoding_str);
|
|
@@ -2590,8 +2694,10 @@ fatal_output_debug(const char *msg)
|
|
static void
|
|
fatal_error_dump_runtime(int fd, _PyRuntimeState *runtime)
|
|
{
|
|
+ PyThreadState *finalizing;
|
|
+
|
|
PUTS(fd, "Python runtime state: ");
|
|
- PyThreadState *finalizing = _PyRuntimeState_GetFinalizing(runtime);
|
|
+ finalizing = _PyRuntimeState_GetFinalizing(runtime);
|
|
if (finalizing) {
|
|
PUTS(fd, "finalizing (tstate=0x");
|
|
_Py_DumpHexadecimal(fd, (uintptr_t)finalizing, sizeof(finalizing) * 2);
|
|
@@ -2640,21 +2746,25 @@ fatal_error_exit(int status)
|
|
void
|
|
_Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
|
|
{
|
|
+ PyObject *modules;
|
|
+ Py_ssize_t pos;
|
|
+ PyObject *key, *value;
|
|
+ PyObject *stdlib_module_names;
|
|
+ int header;
|
|
+ Py_ssize_t count;
|
|
+
|
|
if (interp == NULL) {
|
|
return;
|
|
}
|
|
- PyObject *modules = interp->modules;
|
|
+ modules = interp->modules;
|
|
if (modules == NULL || !PyDict_Check(modules)) {
|
|
return;
|
|
}
|
|
|
|
- Py_ssize_t pos;
|
|
- PyObject *key, *value;
|
|
-
|
|
// Avoid PyDict_GetItemString() which calls PyUnicode_FromString(),
|
|
// memory cannot be allocated on the heap in a signal handler.
|
|
// Iterate on the dict instead.
|
|
- PyObject *stdlib_module_names = NULL;
|
|
+ stdlib_module_names = NULL;
|
|
if (interp->sysdict != NULL) {
|
|
pos = 0;
|
|
while (PyDict_Next(interp->sysdict, &pos, &key, &value)) {
|
|
@@ -2672,8 +2782,8 @@ _Py_DumpExtensionModules(int fd, PyInterpreterState *interp)
|
|
}
|
|
|
|
// List extensions
|
|
- int header = 1;
|
|
- Py_ssize_t count = 0;
|
|
+ header = 1;
|
|
+ count = 0;
|
|
pos = 0;
|
|
while (PyDict_Next(modules, &pos, &key, &value)) {
|
|
if (!PyUnicode_Check(key)) {
|
|
@@ -2730,6 +2840,11 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
|
|
int status)
|
|
{
|
|
static int reentrant = 0;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyThreadState *tstate;
|
|
+ PyInterpreterState *interp;
|
|
+ PyThreadState *tss_tstate;
|
|
+ int has_tstate_and_gil;
|
|
|
|
if (reentrant) {
|
|
/* Py_FatalError() caused a second fatal error.
|
|
@@ -2753,7 +2868,7 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
|
|
PUTS(fd, "\n");
|
|
}
|
|
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
+ runtime = &_PyRuntime;
|
|
fatal_error_dump_runtime(fd, runtime);
|
|
|
|
/* Check if the current thread has a Python thread state
|
|
@@ -2764,16 +2879,16 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,
|
|
|
|
tss_tstate != tstate if the current Python thread does not hold the GIL.
|
|
*/
|
|
- PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
|
- PyInterpreterState *interp = NULL;
|
|
- PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
|
|
+ tstate = _PyRuntimeState_GetThreadState(runtime);
|
|
+ interp = NULL;
|
|
+ tss_tstate = PyGILState_GetThisThreadState();
|
|
if (tstate != NULL) {
|
|
interp = tstate->interp;
|
|
}
|
|
else if (tss_tstate != NULL) {
|
|
interp = tss_tstate->interp;
|
|
}
|
|
- int has_tstate_and_gil = (tss_tstate != NULL && tss_tstate == tstate);
|
|
+ has_tstate_and_gil = (tss_tstate != NULL && tss_tstate == tstate);
|
|
|
|
if (has_tstate_and_gil) {
|
|
/* If an exception is set, print the exception with its traceback */
|
|
@@ -2828,21 +2943,24 @@ void _Py_NO_RETURN
|
|
_Py_FatalErrorFormat(const char *func, const char *format, ...)
|
|
{
|
|
static int reentrant = 0;
|
|
+ FILE *stream;
|
|
+ int fd;
|
|
+ va_list vargs;
|
|
+
|
|
if (reentrant) {
|
|
/* _Py_FatalErrorFormat() caused a second fatal error */
|
|
fatal_error_exit(-1);
|
|
}
|
|
reentrant = 1;
|
|
|
|
- FILE *stream = stderr;
|
|
- const int fd = fileno(stream);
|
|
+ stream = stderr;
|
|
+ fd = fileno(stream);
|
|
PUTS(fd, "Fatal Python error: ");
|
|
if (func) {
|
|
PUTS(fd, func);
|
|
PUTS(fd, ": ");
|
|
}
|
|
|
|
- va_list vargs;
|
|
#ifdef HAVE_STDARG_PROTOTYPES
|
|
va_start(vargs, format);
|
|
#else
|
|
@@ -2921,10 +3039,12 @@ int Py_AtExit(void (*func)(void))
|
|
static void
|
|
call_ll_exitfuncs(_PyRuntimeState *runtime)
|
|
{
|
|
+ void (*exitfunc)(void);
|
|
+
|
|
while (runtime->nexitfuncs > 0) {
|
|
/* pop last function from the list */
|
|
runtime->nexitfuncs--;
|
|
- void (*exitfunc)(void) = runtime->exitfuncs[runtime->nexitfuncs];
|
|
+ exitfunc = runtime->exitfuncs[runtime->nexitfuncs];
|
|
runtime->exitfuncs[runtime->nexitfuncs] = NULL;
|
|
|
|
exitfunc();
|
|
diff --git a/Python/pystate.c b/Python/pystate.c
|
|
index a451166..f26d2c2 100644
|
|
--- a/Python/pystate.c
|
|
+++ b/Python/pystate.c
|
|
@@ -50,9 +50,1127 @@ static void _PyThreadState_Delete(PyThreadState *tstate, int check_current);
|
|
/* Suppress deprecation warning for PyBytesObject.ob_shash */
|
|
_Py_COMP_DIAG_PUSH
|
|
_Py_COMP_DIAG_IGNORE_DEPR_DECLS
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+/* We use an explicit field-by-field initializer on VC6, which cannot parse
|
|
+ the C99 designated initializer used by _PyRuntimeState_INIT. */
|
|
+
|
|
+static void
|
|
+init_immortal_object(PyObject *op, PyTypeObject *type)
|
|
+{
|
|
+#ifdef Py_TRACE_REFS
|
|
+ op->_ob_next = NULL;
|
|
+ op->_ob_prev = NULL;
|
|
+#endif
|
|
+ op->ob_refcnt = 999999999;
|
|
+ op->ob_type = type;
|
|
+}
|
|
+
|
|
+static void
|
|
+init_immortal_varobject(PyVarObject *op, PyTypeObject *type, Py_ssize_t size)
|
|
+{
|
|
+ init_immortal_object(&op->ob_base, type);
|
|
+ op->ob_size = size;
|
|
+}
|
|
+
|
|
+static void
|
|
+init_ascii_object(PyASCIIObject *ascii, uint8_t *data,
|
|
+ const char *literal, int is_ascii)
|
|
+{
|
|
+ size_t len = strlen(literal);
|
|
+ init_immortal_object(&ascii->ob_base, &PyUnicode_Type);
|
|
+ ascii->length = (Py_ssize_t)len;
|
|
+ ascii->hash = -1;
|
|
+ ascii->state.interned = 0;
|
|
+ ascii->state.kind = 1;
|
|
+ ascii->state.compact = 1;
|
|
+ ascii->state.ascii = is_ascii;
|
|
+ ascii->state.ready = 1;
|
|
+ ascii->wstr = NULL;
|
|
+ memcpy(data, literal, len + 1);
|
|
+}
|
|
+
|
|
+static void
|
|
+init_latin1_object(PyCompactUnicodeObject *latin1, uint8_t *data,
|
|
+ unsigned char ch)
|
|
+{
|
|
+ char literal[2];
|
|
+ literal[0] = (char)ch;
|
|
+ literal[1] = '\0';
|
|
+ init_ascii_object(&latin1->_base, data, literal, 0);
|
|
+ latin1->utf8_length = 0;
|
|
+ latin1->utf8 = NULL;
|
|
+ latin1->wstr_length = 0;
|
|
+}
|
|
+
|
|
+static void
|
|
+init_static_threadstate(PyThreadState *tstate)
|
|
+{
|
|
+ tstate->_static = 1;
|
|
+ tstate->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
|
|
+ tstate->context_ver = 1;
|
|
+}
|
|
+
|
|
+static void
|
|
+init_static_interpreter(PyInterpreterState *interp)
|
|
+{
|
|
+ interp->_static = 1;
|
|
+ interp->id_refcount = -1;
|
|
+#ifdef HAVE_DLOPEN
|
|
+ interp->dlopenflags = _Py_DLOPEN_FLAGS;
|
|
+#endif
|
|
+ interp->ceval.recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
|
|
+ interp->gc.enabled = 1;
|
|
+ interp->gc.generations[0].threshold = 700;
|
|
+ interp->gc.generations[1].threshold = 10;
|
|
+ interp->gc.generations[2].threshold = 10;
|
|
+ init_static_threadstate(&interp->_initial_thread);
|
|
+}
|
|
+
|
|
+static void
|
|
+init_small_int(PyLongObject *op, int value)
|
|
+{
|
|
+ int size = 0;
|
|
+ int digit_value = value;
|
|
+ if (value < 0) {
|
|
+ size = -1;
|
|
+ digit_value = -value;
|
|
+ }
|
|
+ else if (value > 0) {
|
|
+ size = 1;
|
|
+ }
|
|
+ init_immortal_varobject(&op->ob_base, &PyLong_Type, size);
|
|
+ op->ob_digit[0] = (digit)digit_value;
|
|
+}
|
|
+
|
|
+static void
|
|
+init_static_global_objects(struct _Py_global_objects *objects)
|
|
+{
|
|
+ int i;
|
|
+
|
|
+ for (i = 0; i < _PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS; i++) {
|
|
+ init_small_int(&objects->singletons.small_ints[i],
|
|
+ i - _PY_NSMALLNEGINTS);
|
|
+ }
|
|
+
|
|
+ init_immortal_varobject(&objects->singletons.bytes_empty.ob_base,
|
|
+ &PyBytes_Type, 0);
|
|
+ objects->singletons.bytes_empty.ob_shash = -1;
|
|
+ objects->singletons.bytes_empty.ob_sval[0] = '\0';
|
|
+
|
|
+ for (i = 0; i < 256; i++) {
|
|
+ init_immortal_varobject(&objects->singletons.bytes_characters[i].ob.ob_base,
|
|
+ &PyBytes_Type, 1);
|
|
+ objects->singletons.bytes_characters[i].ob.ob_shash = -1;
|
|
+ objects->singletons.bytes_characters[i].ob.ob_sval[0] = (char)i;
|
|
+ objects->singletons.bytes_characters[i].eos = '\0';
|
|
+ }
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_dictcomp._ascii,
|
|
+ objects->singletons.strings.literals._anon_dictcomp._data,
|
|
+ "<dictcomp>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_genexpr._ascii,
|
|
+ objects->singletons.strings.literals._anon_genexpr._data,
|
|
+ "<genexpr>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_lambda._ascii,
|
|
+ objects->singletons.strings.literals._anon_lambda._data,
|
|
+ "<lambda>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_listcomp._ascii,
|
|
+ objects->singletons.strings.literals._anon_listcomp._data,
|
|
+ "<listcomp>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_module._ascii,
|
|
+ objects->singletons.strings.literals._anon_module._data,
|
|
+ "<module>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_setcomp._ascii,
|
|
+ objects->singletons.strings.literals._anon_setcomp._data,
|
|
+ "<setcomp>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_string._ascii,
|
|
+ objects->singletons.strings.literals._anon_string._data,
|
|
+ "<string>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._anon_unknown._ascii,
|
|
+ objects->singletons.strings.literals._anon_unknown._data,
|
|
+ "<unknown>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._close_br._ascii,
|
|
+ objects->singletons.strings.literals._close_br._data,
|
|
+ "}", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._comma_sep._ascii,
|
|
+ objects->singletons.strings.literals._comma_sep._data,
|
|
+ ", ", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._dbl_close_br._ascii,
|
|
+ objects->singletons.strings.literals._dbl_close_br._data,
|
|
+ "}}", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._dbl_open_br._ascii,
|
|
+ objects->singletons.strings.literals._dbl_open_br._data,
|
|
+ "{{", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._dbl_percent._ascii,
|
|
+ objects->singletons.strings.literals._dbl_percent._data,
|
|
+ "%%", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._dot._ascii,
|
|
+ objects->singletons.strings.literals._dot._data,
|
|
+ ".", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._dot_locals._ascii,
|
|
+ objects->singletons.strings.literals._dot_locals._data,
|
|
+ ".<locals>", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._empty._ascii,
|
|
+ objects->singletons.strings.literals._empty._data,
|
|
+ "", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._list_err._ascii,
|
|
+ objects->singletons.strings.literals._list_err._data,
|
|
+ "list index out of range", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._newline._ascii,
|
|
+ objects->singletons.strings.literals._newline._data,
|
|
+ "\n", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._open_br._ascii,
|
|
+ objects->singletons.strings.literals._open_br._data,
|
|
+ "{", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._percent._ascii,
|
|
+ objects->singletons.strings.literals._percent._data,
|
|
+ "%", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.literals._utf_8._ascii,
|
|
+ objects->singletons.strings.literals._utf_8._data,
|
|
+ "utf-8", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._False._ascii,
|
|
+ objects->singletons.strings.identifiers._False._data,
|
|
+ "False", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._Py_Repr._ascii,
|
|
+ objects->singletons.strings.identifiers._Py_Repr._data,
|
|
+ "Py_Repr", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._TextIOWrapper._ascii,
|
|
+ objects->singletons.strings.identifiers._TextIOWrapper._data,
|
|
+ "TextIOWrapper", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._True._ascii,
|
|
+ objects->singletons.strings.identifiers._True._data,
|
|
+ "True", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._WarningMessage._ascii,
|
|
+ objects->singletons.strings.identifiers._WarningMessage._data,
|
|
+ "WarningMessage", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__._ascii,
|
|
+ objects->singletons.strings.identifiers.__._data,
|
|
+ "_", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___IOBase_closed._ascii,
|
|
+ objects->singletons.strings.identifiers.___IOBase_closed._data,
|
|
+ "__IOBase_closed", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___abc_tpflags__._ascii,
|
|
+ objects->singletons.strings.identifiers.___abc_tpflags__._data,
|
|
+ "__abc_tpflags__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___abs__._ascii,
|
|
+ objects->singletons.strings.identifiers.___abs__._data,
|
|
+ "__abs__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___abstractmethods__._ascii,
|
|
+ objects->singletons.strings.identifiers.___abstractmethods__._data,
|
|
+ "__abstractmethods__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___add__._ascii,
|
|
+ objects->singletons.strings.identifiers.___add__._data,
|
|
+ "__add__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___aenter__._ascii,
|
|
+ objects->singletons.strings.identifiers.___aenter__._data,
|
|
+ "__aenter__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___aexit__._ascii,
|
|
+ objects->singletons.strings.identifiers.___aexit__._data,
|
|
+ "__aexit__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___aiter__._ascii,
|
|
+ objects->singletons.strings.identifiers.___aiter__._data,
|
|
+ "__aiter__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___all__._ascii,
|
|
+ objects->singletons.strings.identifiers.___all__._data,
|
|
+ "__all__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___and__._ascii,
|
|
+ objects->singletons.strings.identifiers.___and__._data,
|
|
+ "__and__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___anext__._ascii,
|
|
+ objects->singletons.strings.identifiers.___anext__._data,
|
|
+ "__anext__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___annotations__._ascii,
|
|
+ objects->singletons.strings.identifiers.___annotations__._data,
|
|
+ "__annotations__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___args__._ascii,
|
|
+ objects->singletons.strings.identifiers.___args__._data,
|
|
+ "__args__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___await__._ascii,
|
|
+ objects->singletons.strings.identifiers.___await__._data,
|
|
+ "__await__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___bases__._ascii,
|
|
+ objects->singletons.strings.identifiers.___bases__._data,
|
|
+ "__bases__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___bool__._ascii,
|
|
+ objects->singletons.strings.identifiers.___bool__._data,
|
|
+ "__bool__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___build_class__._ascii,
|
|
+ objects->singletons.strings.identifiers.___build_class__._data,
|
|
+ "__build_class__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___builtins__._ascii,
|
|
+ objects->singletons.strings.identifiers.___builtins__._data,
|
|
+ "__builtins__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___bytes__._ascii,
|
|
+ objects->singletons.strings.identifiers.___bytes__._data,
|
|
+ "__bytes__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___call__._ascii,
|
|
+ objects->singletons.strings.identifiers.___call__._data,
|
|
+ "__call__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___cantrace__._ascii,
|
|
+ objects->singletons.strings.identifiers.___cantrace__._data,
|
|
+ "__cantrace__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___class__._ascii,
|
|
+ objects->singletons.strings.identifiers.___class__._data,
|
|
+ "__class__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___class_getitem__._ascii,
|
|
+ objects->singletons.strings.identifiers.___class_getitem__._data,
|
|
+ "__class_getitem__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___classcell__._ascii,
|
|
+ objects->singletons.strings.identifiers.___classcell__._data,
|
|
+ "__classcell__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___complex__._ascii,
|
|
+ objects->singletons.strings.identifiers.___complex__._data,
|
|
+ "__complex__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___contains__._ascii,
|
|
+ objects->singletons.strings.identifiers.___contains__._data,
|
|
+ "__contains__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___copy__._ascii,
|
|
+ objects->singletons.strings.identifiers.___copy__._data,
|
|
+ "__copy__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___del__._ascii,
|
|
+ objects->singletons.strings.identifiers.___del__._data,
|
|
+ "__del__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___delattr__._ascii,
|
|
+ objects->singletons.strings.identifiers.___delattr__._data,
|
|
+ "__delattr__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___delete__._ascii,
|
|
+ objects->singletons.strings.identifiers.___delete__._data,
|
|
+ "__delete__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___delitem__._ascii,
|
|
+ objects->singletons.strings.identifiers.___delitem__._data,
|
|
+ "__delitem__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___dict__._ascii,
|
|
+ objects->singletons.strings.identifiers.___dict__._data,
|
|
+ "__dict__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___dir__._ascii,
|
|
+ objects->singletons.strings.identifiers.___dir__._data,
|
|
+ "__dir__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___divmod__._ascii,
|
|
+ objects->singletons.strings.identifiers.___divmod__._data,
|
|
+ "__divmod__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___doc__._ascii,
|
|
+ objects->singletons.strings.identifiers.___doc__._data,
|
|
+ "__doc__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___enter__._ascii,
|
|
+ objects->singletons.strings.identifiers.___enter__._data,
|
|
+ "__enter__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___eq__._ascii,
|
|
+ objects->singletons.strings.identifiers.___eq__._data,
|
|
+ "__eq__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___exit__._ascii,
|
|
+ objects->singletons.strings.identifiers.___exit__._data,
|
|
+ "__exit__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___file__._ascii,
|
|
+ objects->singletons.strings.identifiers.___file__._data,
|
|
+ "__file__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___float__._ascii,
|
|
+ objects->singletons.strings.identifiers.___float__._data,
|
|
+ "__float__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___floordiv__._ascii,
|
|
+ objects->singletons.strings.identifiers.___floordiv__._data,
|
|
+ "__floordiv__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___format__._ascii,
|
|
+ objects->singletons.strings.identifiers.___format__._data,
|
|
+ "__format__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___fspath__._ascii,
|
|
+ objects->singletons.strings.identifiers.___fspath__._data,
|
|
+ "__fspath__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ge__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ge__._data,
|
|
+ "__ge__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___get__._ascii,
|
|
+ objects->singletons.strings.identifiers.___get__._data,
|
|
+ "__get__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___getattr__._ascii,
|
|
+ objects->singletons.strings.identifiers.___getattr__._data,
|
|
+ "__getattr__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___getattribute__._ascii,
|
|
+ objects->singletons.strings.identifiers.___getattribute__._data,
|
|
+ "__getattribute__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___getinitargs__._ascii,
|
|
+ objects->singletons.strings.identifiers.___getinitargs__._data,
|
|
+ "__getinitargs__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___getitem__._ascii,
|
|
+ objects->singletons.strings.identifiers.___getitem__._data,
|
|
+ "__getitem__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___getnewargs__._ascii,
|
|
+ objects->singletons.strings.identifiers.___getnewargs__._data,
|
|
+ "__getnewargs__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___getnewargs_ex__._ascii,
|
|
+ objects->singletons.strings.identifiers.___getnewargs_ex__._data,
|
|
+ "__getnewargs_ex__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___getstate__._ascii,
|
|
+ objects->singletons.strings.identifiers.___getstate__._data,
|
|
+ "__getstate__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___gt__._ascii,
|
|
+ objects->singletons.strings.identifiers.___gt__._data,
|
|
+ "__gt__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___hash__._ascii,
|
|
+ objects->singletons.strings.identifiers.___hash__._data,
|
|
+ "__hash__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___iadd__._ascii,
|
|
+ objects->singletons.strings.identifiers.___iadd__._data,
|
|
+ "__iadd__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___iand__._ascii,
|
|
+ objects->singletons.strings.identifiers.___iand__._data,
|
|
+ "__iand__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ifloordiv__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ifloordiv__._data,
|
|
+ "__ifloordiv__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ilshift__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ilshift__._data,
|
|
+ "__ilshift__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___imatmul__._ascii,
|
|
+ objects->singletons.strings.identifiers.___imatmul__._data,
|
|
+ "__imatmul__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___imod__._ascii,
|
|
+ objects->singletons.strings.identifiers.___imod__._data,
|
|
+ "__imod__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___import__._ascii,
|
|
+ objects->singletons.strings.identifiers.___import__._data,
|
|
+ "__import__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___imul__._ascii,
|
|
+ objects->singletons.strings.identifiers.___imul__._data,
|
|
+ "__imul__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___index__._ascii,
|
|
+ objects->singletons.strings.identifiers.___index__._data,
|
|
+ "__index__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___init__._ascii,
|
|
+ objects->singletons.strings.identifiers.___init__._data,
|
|
+ "__init__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___init_subclass__._ascii,
|
|
+ objects->singletons.strings.identifiers.___init_subclass__._data,
|
|
+ "__init_subclass__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___instancecheck__._ascii,
|
|
+ objects->singletons.strings.identifiers.___instancecheck__._data,
|
|
+ "__instancecheck__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___int__._ascii,
|
|
+ objects->singletons.strings.identifiers.___int__._data,
|
|
+ "__int__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___invert__._ascii,
|
|
+ objects->singletons.strings.identifiers.___invert__._data,
|
|
+ "__invert__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ior__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ior__._data,
|
|
+ "__ior__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ipow__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ipow__._data,
|
|
+ "__ipow__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___irshift__._ascii,
|
|
+ objects->singletons.strings.identifiers.___irshift__._data,
|
|
+ "__irshift__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___isabstractmethod__._ascii,
|
|
+ objects->singletons.strings.identifiers.___isabstractmethod__._data,
|
|
+ "__isabstractmethod__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___isub__._ascii,
|
|
+ objects->singletons.strings.identifiers.___isub__._data,
|
|
+ "__isub__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___iter__._ascii,
|
|
+ objects->singletons.strings.identifiers.___iter__._data,
|
|
+ "__iter__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___itruediv__._ascii,
|
|
+ objects->singletons.strings.identifiers.___itruediv__._data,
|
|
+ "__itruediv__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ixor__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ixor__._data,
|
|
+ "__ixor__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___le__._ascii,
|
|
+ objects->singletons.strings.identifiers.___le__._data,
|
|
+ "__le__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___len__._ascii,
|
|
+ objects->singletons.strings.identifiers.___len__._data,
|
|
+ "__len__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___length_hint__._ascii,
|
|
+ objects->singletons.strings.identifiers.___length_hint__._data,
|
|
+ "__length_hint__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___lltrace__._ascii,
|
|
+ objects->singletons.strings.identifiers.___lltrace__._data,
|
|
+ "__lltrace__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___loader__._ascii,
|
|
+ objects->singletons.strings.identifiers.___loader__._data,
|
|
+ "__loader__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___lshift__._ascii,
|
|
+ objects->singletons.strings.identifiers.___lshift__._data,
|
|
+ "__lshift__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___lt__._ascii,
|
|
+ objects->singletons.strings.identifiers.___lt__._data,
|
|
+ "__lt__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___main__._ascii,
|
|
+ objects->singletons.strings.identifiers.___main__._data,
|
|
+ "__main__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___matmul__._ascii,
|
|
+ objects->singletons.strings.identifiers.___matmul__._data,
|
|
+ "__matmul__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___missing__._ascii,
|
|
+ objects->singletons.strings.identifiers.___missing__._data,
|
|
+ "__missing__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___mod__._ascii,
|
|
+ objects->singletons.strings.identifiers.___mod__._data,
|
|
+ "__mod__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___module__._ascii,
|
|
+ objects->singletons.strings.identifiers.___module__._data,
|
|
+ "__module__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___mro_entries__._ascii,
|
|
+ objects->singletons.strings.identifiers.___mro_entries__._data,
|
|
+ "__mro_entries__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___mul__._ascii,
|
|
+ objects->singletons.strings.identifiers.___mul__._data,
|
|
+ "__mul__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___name__._ascii,
|
|
+ objects->singletons.strings.identifiers.___name__._data,
|
|
+ "__name__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ne__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ne__._data,
|
|
+ "__ne__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___neg__._ascii,
|
|
+ objects->singletons.strings.identifiers.___neg__._data,
|
|
+ "__neg__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___new__._ascii,
|
|
+ objects->singletons.strings.identifiers.___new__._data,
|
|
+ "__new__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___newobj__._ascii,
|
|
+ objects->singletons.strings.identifiers.___newobj__._data,
|
|
+ "__newobj__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___newobj_ex__._ascii,
|
|
+ objects->singletons.strings.identifiers.___newobj_ex__._data,
|
|
+ "__newobj_ex__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___next__._ascii,
|
|
+ objects->singletons.strings.identifiers.___next__._data,
|
|
+ "__next__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___notes__._ascii,
|
|
+ objects->singletons.strings.identifiers.___notes__._data,
|
|
+ "__notes__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___or__._ascii,
|
|
+ objects->singletons.strings.identifiers.___or__._data,
|
|
+ "__or__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___orig_class__._ascii,
|
|
+ objects->singletons.strings.identifiers.___orig_class__._data,
|
|
+ "__orig_class__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___origin__._ascii,
|
|
+ objects->singletons.strings.identifiers.___origin__._data,
|
|
+ "__origin__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___package__._ascii,
|
|
+ objects->singletons.strings.identifiers.___package__._data,
|
|
+ "__package__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___parameters__._ascii,
|
|
+ objects->singletons.strings.identifiers.___parameters__._data,
|
|
+ "__parameters__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___path__._ascii,
|
|
+ objects->singletons.strings.identifiers.___path__._data,
|
|
+ "__path__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___pos__._ascii,
|
|
+ objects->singletons.strings.identifiers.___pos__._data,
|
|
+ "__pos__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___pow__._ascii,
|
|
+ objects->singletons.strings.identifiers.___pow__._data,
|
|
+ "__pow__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___prepare__._ascii,
|
|
+ objects->singletons.strings.identifiers.___prepare__._data,
|
|
+ "__prepare__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___qualname__._ascii,
|
|
+ objects->singletons.strings.identifiers.___qualname__._data,
|
|
+ "__qualname__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___radd__._ascii,
|
|
+ objects->singletons.strings.identifiers.___radd__._data,
|
|
+ "__radd__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rand__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rand__._data,
|
|
+ "__rand__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rdivmod__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rdivmod__._data,
|
|
+ "__rdivmod__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___reduce__._ascii,
|
|
+ objects->singletons.strings.identifiers.___reduce__._data,
|
|
+ "__reduce__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___reduce_ex__._ascii,
|
|
+ objects->singletons.strings.identifiers.___reduce_ex__._data,
|
|
+ "__reduce_ex__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___repr__._ascii,
|
|
+ objects->singletons.strings.identifiers.___repr__._data,
|
|
+ "__repr__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___reversed__._ascii,
|
|
+ objects->singletons.strings.identifiers.___reversed__._data,
|
|
+ "__reversed__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rfloordiv__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rfloordiv__._data,
|
|
+ "__rfloordiv__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rlshift__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rlshift__._data,
|
|
+ "__rlshift__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rmatmul__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rmatmul__._data,
|
|
+ "__rmatmul__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rmod__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rmod__._data,
|
|
+ "__rmod__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rmul__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rmul__._data,
|
|
+ "__rmul__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___ror__._ascii,
|
|
+ objects->singletons.strings.identifiers.___ror__._data,
|
|
+ "__ror__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___round__._ascii,
|
|
+ objects->singletons.strings.identifiers.___round__._data,
|
|
+ "__round__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rpow__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rpow__._data,
|
|
+ "__rpow__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rrshift__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rrshift__._data,
|
|
+ "__rrshift__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rshift__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rshift__._data,
|
|
+ "__rshift__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rsub__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rsub__._data,
|
|
+ "__rsub__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rtruediv__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rtruediv__._data,
|
|
+ "__rtruediv__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___rxor__._ascii,
|
|
+ objects->singletons.strings.identifiers.___rxor__._data,
|
|
+ "__rxor__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___set__._ascii,
|
|
+ objects->singletons.strings.identifiers.___set__._data,
|
|
+ "__set__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___set_name__._ascii,
|
|
+ objects->singletons.strings.identifiers.___set_name__._data,
|
|
+ "__set_name__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___setattr__._ascii,
|
|
+ objects->singletons.strings.identifiers.___setattr__._data,
|
|
+ "__setattr__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___setitem__._ascii,
|
|
+ objects->singletons.strings.identifiers.___setitem__._data,
|
|
+ "__setitem__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___setstate__._ascii,
|
|
+ objects->singletons.strings.identifiers.___setstate__._data,
|
|
+ "__setstate__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___sizeof__._ascii,
|
|
+ objects->singletons.strings.identifiers.___sizeof__._data,
|
|
+ "__sizeof__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___slotnames__._ascii,
|
|
+ objects->singletons.strings.identifiers.___slotnames__._data,
|
|
+ "__slotnames__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___slots__._ascii,
|
|
+ objects->singletons.strings.identifiers.___slots__._data,
|
|
+ "__slots__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___spec__._ascii,
|
|
+ objects->singletons.strings.identifiers.___spec__._data,
|
|
+ "__spec__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___str__._ascii,
|
|
+ objects->singletons.strings.identifiers.___str__._data,
|
|
+ "__str__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___sub__._ascii,
|
|
+ objects->singletons.strings.identifiers.___sub__._data,
|
|
+ "__sub__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___subclasscheck__._ascii,
|
|
+ objects->singletons.strings.identifiers.___subclasscheck__._data,
|
|
+ "__subclasscheck__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___subclasshook__._ascii,
|
|
+ objects->singletons.strings.identifiers.___subclasshook__._data,
|
|
+ "__subclasshook__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___truediv__._ascii,
|
|
+ objects->singletons.strings.identifiers.___truediv__._data,
|
|
+ "__truediv__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___trunc__._ascii,
|
|
+ objects->singletons.strings.identifiers.___trunc__._data,
|
|
+ "__trunc__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_is_unpacked_typevartuple__._ascii,
|
|
+ objects->singletons.strings.identifiers.___typing_is_unpacked_typevartuple__._data,
|
|
+ "__typing_is_unpacked_typevartuple__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_prepare_subst__._ascii,
|
|
+ objects->singletons.strings.identifiers.___typing_prepare_subst__._data,
|
|
+ "__typing_prepare_subst__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_subst__._ascii,
|
|
+ objects->singletons.strings.identifiers.___typing_subst__._data,
|
|
+ "__typing_subst__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___typing_unpacked_tuple_args__._ascii,
|
|
+ objects->singletons.strings.identifiers.___typing_unpacked_tuple_args__._data,
|
|
+ "__typing_unpacked_tuple_args__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___warningregistry__._ascii,
|
|
+ objects->singletons.strings.identifiers.___warningregistry__._data,
|
|
+ "__warningregistry__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___weakref__._ascii,
|
|
+ objects->singletons.strings.identifiers.___weakref__._data,
|
|
+ "__weakref__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.___xor__._ascii,
|
|
+ objects->singletons.strings.identifiers.___xor__._data,
|
|
+ "__xor__", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__abc_impl._ascii,
|
|
+ objects->singletons.strings.identifiers.__abc_impl._data,
|
|
+ "_abc_impl", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__annotation._ascii,
|
|
+ objects->singletons.strings.identifiers.__annotation._data,
|
|
+ "_annotation", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__blksize._ascii,
|
|
+ objects->singletons.strings.identifiers.__blksize._data,
|
|
+ "_blksize", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__bootstrap._ascii,
|
|
+ objects->singletons.strings.identifiers.__bootstrap._data,
|
|
+ "_bootstrap", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__dealloc_warn._ascii,
|
|
+ objects->singletons.strings.identifiers.__dealloc_warn._data,
|
|
+ "_dealloc_warn", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__finalizing._ascii,
|
|
+ objects->singletons.strings.identifiers.__finalizing._data,
|
|
+ "_finalizing", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__find_and_load._ascii,
|
|
+ objects->singletons.strings.identifiers.__find_and_load._data,
|
|
+ "_find_and_load", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__fix_up_module._ascii,
|
|
+ objects->singletons.strings.identifiers.__fix_up_module._data,
|
|
+ "_fix_up_module", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__get_sourcefile._ascii,
|
|
+ objects->singletons.strings.identifiers.__get_sourcefile._data,
|
|
+ "_get_sourcefile", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__handle_fromlist._ascii,
|
|
+ objects->singletons.strings.identifiers.__handle_fromlist._data,
|
|
+ "_handle_fromlist", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__initializing._ascii,
|
|
+ objects->singletons.strings.identifiers.__initializing._data,
|
|
+ "_initializing", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__is_text_encoding._ascii,
|
|
+ objects->singletons.strings.identifiers.__is_text_encoding._data,
|
|
+ "_is_text_encoding", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__lock_unlock_module._ascii,
|
|
+ objects->singletons.strings.identifiers.__lock_unlock_module._data,
|
|
+ "_lock_unlock_module", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__showwarnmsg._ascii,
|
|
+ objects->singletons.strings.identifiers.__showwarnmsg._data,
|
|
+ "_showwarnmsg", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__shutdown._ascii,
|
|
+ objects->singletons.strings.identifiers.__shutdown._data,
|
|
+ "_shutdown", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__slotnames._ascii,
|
|
+ objects->singletons.strings.identifiers.__slotnames._data,
|
|
+ "_slotnames", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__strptime_time._ascii,
|
|
+ objects->singletons.strings.identifiers.__strptime_time._data,
|
|
+ "_strptime_time", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__uninitialized_submodules._ascii,
|
|
+ objects->singletons.strings.identifiers.__uninitialized_submodules._data,
|
|
+ "_uninitialized_submodules", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__warn_unawaited_coroutine._ascii,
|
|
+ objects->singletons.strings.identifiers.__warn_unawaited_coroutine._data,
|
|
+ "_warn_unawaited_coroutine", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers.__xoptions._ascii,
|
|
+ objects->singletons.strings.identifiers.__xoptions._data,
|
|
+ "_xoptions", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._add._ascii,
|
|
+ objects->singletons.strings.identifiers._add._data,
|
|
+ "add", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._append._ascii,
|
|
+ objects->singletons.strings.identifiers._append._data,
|
|
+ "append", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._big._ascii,
|
|
+ objects->singletons.strings.identifiers._big._data,
|
|
+ "big", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._buffer._ascii,
|
|
+ objects->singletons.strings.identifiers._buffer._data,
|
|
+ "buffer", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._builtins._ascii,
|
|
+ objects->singletons.strings.identifiers._builtins._data,
|
|
+ "builtins", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._c_call._ascii,
|
|
+ objects->singletons.strings.identifiers._c_call._data,
|
|
+ "c_call", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._c_exception._ascii,
|
|
+ objects->singletons.strings.identifiers._c_exception._data,
|
|
+ "c_exception", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._c_return._ascii,
|
|
+ objects->singletons.strings.identifiers._c_return._data,
|
|
+ "c_return", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._call._ascii,
|
|
+ objects->singletons.strings.identifiers._call._data,
|
|
+ "call", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._clear._ascii,
|
|
+ objects->singletons.strings.identifiers._clear._data,
|
|
+ "clear", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._close._ascii,
|
|
+ objects->singletons.strings.identifiers._close._data,
|
|
+ "close", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._closed._ascii,
|
|
+ objects->singletons.strings.identifiers._closed._data,
|
|
+ "closed", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._code._ascii,
|
|
+ objects->singletons.strings.identifiers._code._data,
|
|
+ "code", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._copy._ascii,
|
|
+ objects->singletons.strings.identifiers._copy._data,
|
|
+ "copy", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._copyreg._ascii,
|
|
+ objects->singletons.strings.identifiers._copyreg._data,
|
|
+ "copyreg", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._decode._ascii,
|
|
+ objects->singletons.strings.identifiers._decode._data,
|
|
+ "decode", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._default._ascii,
|
|
+ objects->singletons.strings.identifiers._default._data,
|
|
+ "default", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._defaultaction._ascii,
|
|
+ objects->singletons.strings.identifiers._defaultaction._data,
|
|
+ "defaultaction", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._dictcomp._ascii,
|
|
+ objects->singletons.strings.identifiers._dictcomp._data,
|
|
+ "dictcomp", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._difference_update._ascii,
|
|
+ objects->singletons.strings.identifiers._difference_update._data,
|
|
+ "difference_update", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._dispatch_table._ascii,
|
|
+ objects->singletons.strings.identifiers._dispatch_table._data,
|
|
+ "dispatch_table", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._displayhook._ascii,
|
|
+ objects->singletons.strings.identifiers._displayhook._data,
|
|
+ "displayhook", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._enable._ascii,
|
|
+ objects->singletons.strings.identifiers._enable._data,
|
|
+ "enable", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._encode._ascii,
|
|
+ objects->singletons.strings.identifiers._encode._data,
|
|
+ "encode", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._encoding._ascii,
|
|
+ objects->singletons.strings.identifiers._encoding._data,
|
|
+ "encoding", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._end_lineno._ascii,
|
|
+ objects->singletons.strings.identifiers._end_lineno._data,
|
|
+ "end_lineno", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._end_offset._ascii,
|
|
+ objects->singletons.strings.identifiers._end_offset._data,
|
|
+ "end_offset", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._errors._ascii,
|
|
+ objects->singletons.strings.identifiers._errors._data,
|
|
+ "errors", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._excepthook._ascii,
|
|
+ objects->singletons.strings.identifiers._excepthook._data,
|
|
+ "excepthook", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._exception._ascii,
|
|
+ objects->singletons.strings.identifiers._exception._data,
|
|
+ "exception", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._extend._ascii,
|
|
+ objects->singletons.strings.identifiers._extend._data,
|
|
+ "extend", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._filename._ascii,
|
|
+ objects->singletons.strings.identifiers._filename._data,
|
|
+ "filename", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._fileno._ascii,
|
|
+ objects->singletons.strings.identifiers._fileno._data,
|
|
+ "fileno", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._fillvalue._ascii,
|
|
+ objects->singletons.strings.identifiers._fillvalue._data,
|
|
+ "fillvalue", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._filters._ascii,
|
|
+ objects->singletons.strings.identifiers._filters._data,
|
|
+ "filters", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._find_class._ascii,
|
|
+ objects->singletons.strings.identifiers._find_class._data,
|
|
+ "find_class", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._flush._ascii,
|
|
+ objects->singletons.strings.identifiers._flush._data,
|
|
+ "flush", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._genexpr._ascii,
|
|
+ objects->singletons.strings.identifiers._genexpr._data,
|
|
+ "genexpr", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._get._ascii,
|
|
+ objects->singletons.strings.identifiers._get._data,
|
|
+ "get", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._get_source._ascii,
|
|
+ objects->singletons.strings.identifiers._get_source._data,
|
|
+ "get_source", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._getattr._ascii,
|
|
+ objects->singletons.strings.identifiers._getattr._data,
|
|
+ "getattr", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._getstate._ascii,
|
|
+ objects->singletons.strings.identifiers._getstate._data,
|
|
+ "getstate", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._ignore._ascii,
|
|
+ objects->singletons.strings.identifiers._ignore._data,
|
|
+ "ignore", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._importlib._ascii,
|
|
+ objects->singletons.strings.identifiers._importlib._data,
|
|
+ "importlib", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._inf._ascii,
|
|
+ objects->singletons.strings.identifiers._inf._data,
|
|
+ "inf", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._intersection._ascii,
|
|
+ objects->singletons.strings.identifiers._intersection._data,
|
|
+ "intersection", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._isatty._ascii,
|
|
+ objects->singletons.strings.identifiers._isatty._data,
|
|
+ "isatty", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._isinstance._ascii,
|
|
+ objects->singletons.strings.identifiers._isinstance._data,
|
|
+ "isinstance", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._items._ascii,
|
|
+ objects->singletons.strings.identifiers._items._data,
|
|
+ "items", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._iter._ascii,
|
|
+ objects->singletons.strings.identifiers._iter._data,
|
|
+ "iter", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._join._ascii,
|
|
+ objects->singletons.strings.identifiers._join._data,
|
|
+ "join", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._keys._ascii,
|
|
+ objects->singletons.strings.identifiers._keys._data,
|
|
+ "keys", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._lambda._ascii,
|
|
+ objects->singletons.strings.identifiers._lambda._data,
|
|
+ "lambda", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._last_traceback._ascii,
|
|
+ objects->singletons.strings.identifiers._last_traceback._data,
|
|
+ "last_traceback", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._last_type._ascii,
|
|
+ objects->singletons.strings.identifiers._last_type._data,
|
|
+ "last_type", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._last_value._ascii,
|
|
+ objects->singletons.strings.identifiers._last_value._data,
|
|
+ "last_value", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._latin1._ascii,
|
|
+ objects->singletons.strings.identifiers._latin1._data,
|
|
+ "latin1", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._len._ascii,
|
|
+ objects->singletons.strings.identifiers._len._data,
|
|
+ "len", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._line._ascii,
|
|
+ objects->singletons.strings.identifiers._line._data,
|
|
+ "line", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._lineno._ascii,
|
|
+ objects->singletons.strings.identifiers._lineno._data,
|
|
+ "lineno", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._listcomp._ascii,
|
|
+ objects->singletons.strings.identifiers._listcomp._data,
|
|
+ "listcomp", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._little._ascii,
|
|
+ objects->singletons.strings.identifiers._little._data,
|
|
+ "little", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._locale._ascii,
|
|
+ objects->singletons.strings.identifiers._locale._data,
|
|
+ "locale", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._match._ascii,
|
|
+ objects->singletons.strings.identifiers._match._data,
|
|
+ "match", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._metaclass._ascii,
|
|
+ objects->singletons.strings.identifiers._metaclass._data,
|
|
+ "metaclass", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._mode._ascii,
|
|
+ objects->singletons.strings.identifiers._mode._data,
|
|
+ "mode", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._modules._ascii,
|
|
+ objects->singletons.strings.identifiers._modules._data,
|
|
+ "modules", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._mro._ascii,
|
|
+ objects->singletons.strings.identifiers._mro._data,
|
|
+ "mro", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._msg._ascii,
|
|
+ objects->singletons.strings.identifiers._msg._data,
|
|
+ "msg", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._n_fields._ascii,
|
|
+ objects->singletons.strings.identifiers._n_fields._data,
|
|
+ "n_fields", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._n_sequence_fields._ascii,
|
|
+ objects->singletons.strings.identifiers._n_sequence_fields._data,
|
|
+ "n_sequence_fields", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._n_unnamed_fields._ascii,
|
|
+ objects->singletons.strings.identifiers._n_unnamed_fields._data,
|
|
+ "n_unnamed_fields", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._name._ascii,
|
|
+ objects->singletons.strings.identifiers._name._data,
|
|
+ "name", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._newlines._ascii,
|
|
+ objects->singletons.strings.identifiers._newlines._data,
|
|
+ "newlines", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._next._ascii,
|
|
+ objects->singletons.strings.identifiers._next._data,
|
|
+ "next", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._obj._ascii,
|
|
+ objects->singletons.strings.identifiers._obj._data,
|
|
+ "obj", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._offset._ascii,
|
|
+ objects->singletons.strings.identifiers._offset._data,
|
|
+ "offset", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._onceregistry._ascii,
|
|
+ objects->singletons.strings.identifiers._onceregistry._data,
|
|
+ "onceregistry", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._opcode._ascii,
|
|
+ objects->singletons.strings.identifiers._opcode._data,
|
|
+ "opcode", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._open._ascii,
|
|
+ objects->singletons.strings.identifiers._open._data,
|
|
+ "open", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._parent._ascii,
|
|
+ objects->singletons.strings.identifiers._parent._data,
|
|
+ "parent", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._partial._ascii,
|
|
+ objects->singletons.strings.identifiers._partial._data,
|
|
+ "partial", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._path._ascii,
|
|
+ objects->singletons.strings.identifiers._path._data,
|
|
+ "path", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._peek._ascii,
|
|
+ objects->singletons.strings.identifiers._peek._data,
|
|
+ "peek", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._persistent_id._ascii,
|
|
+ objects->singletons.strings.identifiers._persistent_id._data,
|
|
+ "persistent_id", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._persistent_load._ascii,
|
|
+ objects->singletons.strings.identifiers._persistent_load._data,
|
|
+ "persistent_load", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._print_file_and_line._ascii,
|
|
+ objects->singletons.strings.identifiers._print_file_and_line._data,
|
|
+ "print_file_and_line", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._ps1._ascii,
|
|
+ objects->singletons.strings.identifiers._ps1._data,
|
|
+ "ps1", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._ps2._ascii,
|
|
+ objects->singletons.strings.identifiers._ps2._data,
|
|
+ "ps2", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._raw._ascii,
|
|
+ objects->singletons.strings.identifiers._raw._data,
|
|
+ "raw", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._read._ascii,
|
|
+ objects->singletons.strings.identifiers._read._data,
|
|
+ "read", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._read1._ascii,
|
|
+ objects->singletons.strings.identifiers._read1._data,
|
|
+ "read1", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._readable._ascii,
|
|
+ objects->singletons.strings.identifiers._readable._data,
|
|
+ "readable", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._readall._ascii,
|
|
+ objects->singletons.strings.identifiers._readall._data,
|
|
+ "readall", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._readinto._ascii,
|
|
+ objects->singletons.strings.identifiers._readinto._data,
|
|
+ "readinto", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._readinto1._ascii,
|
|
+ objects->singletons.strings.identifiers._readinto1._data,
|
|
+ "readinto1", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._readline._ascii,
|
|
+ objects->singletons.strings.identifiers._readline._data,
|
|
+ "readline", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._reducer_override._ascii,
|
|
+ objects->singletons.strings.identifiers._reducer_override._data,
|
|
+ "reducer_override", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._reload._ascii,
|
|
+ objects->singletons.strings.identifiers._reload._data,
|
|
+ "reload", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._replace._ascii,
|
|
+ objects->singletons.strings.identifiers._replace._data,
|
|
+ "replace", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._reset._ascii,
|
|
+ objects->singletons.strings.identifiers._reset._data,
|
|
+ "reset", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._return._ascii,
|
|
+ objects->singletons.strings.identifiers._return._data,
|
|
+ "return", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._reversed._ascii,
|
|
+ objects->singletons.strings.identifiers._reversed._data,
|
|
+ "reversed", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._seek._ascii,
|
|
+ objects->singletons.strings.identifiers._seek._data,
|
|
+ "seek", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._seekable._ascii,
|
|
+ objects->singletons.strings.identifiers._seekable._data,
|
|
+ "seekable", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._send._ascii,
|
|
+ objects->singletons.strings.identifiers._send._data,
|
|
+ "send", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._setcomp._ascii,
|
|
+ objects->singletons.strings.identifiers._setcomp._data,
|
|
+ "setcomp", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._setstate._ascii,
|
|
+ objects->singletons.strings.identifiers._setstate._data,
|
|
+ "setstate", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._sort._ascii,
|
|
+ objects->singletons.strings.identifiers._sort._data,
|
|
+ "sort", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._stderr._ascii,
|
|
+ objects->singletons.strings.identifiers._stderr._data,
|
|
+ "stderr", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._stdin._ascii,
|
|
+ objects->singletons.strings.identifiers._stdin._data,
|
|
+ "stdin", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._stdout._ascii,
|
|
+ objects->singletons.strings.identifiers._stdout._data,
|
|
+ "stdout", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._strict._ascii,
|
|
+ objects->singletons.strings.identifiers._strict._data,
|
|
+ "strict", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._symmetric_difference_update._ascii,
|
|
+ objects->singletons.strings.identifiers._symmetric_difference_update._data,
|
|
+ "symmetric_difference_update", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._tell._ascii,
|
|
+ objects->singletons.strings.identifiers._tell._data,
|
|
+ "tell", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._text._ascii,
|
|
+ objects->singletons.strings.identifiers._text._data,
|
|
+ "text", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._threading._ascii,
|
|
+ objects->singletons.strings.identifiers._threading._data,
|
|
+ "threading", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._throw._ascii,
|
|
+ objects->singletons.strings.identifiers._throw._data,
|
|
+ "throw", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._top._ascii,
|
|
+ objects->singletons.strings.identifiers._top._data,
|
|
+ "top", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._truncate._ascii,
|
|
+ objects->singletons.strings.identifiers._truncate._data,
|
|
+ "truncate", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._unraisablehook._ascii,
|
|
+ objects->singletons.strings.identifiers._unraisablehook._data,
|
|
+ "unraisablehook", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._values._ascii,
|
|
+ objects->singletons.strings.identifiers._values._data,
|
|
+ "values", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._version._ascii,
|
|
+ objects->singletons.strings.identifiers._version._data,
|
|
+ "version", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._warnings._ascii,
|
|
+ objects->singletons.strings.identifiers._warnings._data,
|
|
+ "warnings", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._warnoptions._ascii,
|
|
+ objects->singletons.strings.identifiers._warnoptions._data,
|
|
+ "warnoptions", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._writable._ascii,
|
|
+ objects->singletons.strings.identifiers._writable._data,
|
|
+ "writable", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._write._ascii,
|
|
+ objects->singletons.strings.identifiers._write._data,
|
|
+ "write", 1);
|
|
+ init_ascii_object(&objects->singletons.strings.identifiers._zipimporter._ascii,
|
|
+ objects->singletons.strings.identifiers._zipimporter._data,
|
|
+ "zipimporter", 1);
|
|
+
|
|
+ for (i = 0; i < 128; i++) {
|
|
+ char literal[2];
|
|
+ literal[0] = (char)i;
|
|
+ literal[1] = '\0';
|
|
+ init_ascii_object(&objects->singletons.strings.ascii[i]._ascii,
|
|
+ objects->singletons.strings.ascii[i]._data,
|
|
+ literal, 1);
|
|
+ init_latin1_object(&objects->singletons.strings.latin1[i]._latin1,
|
|
+ objects->singletons.strings.latin1[i]._data,
|
|
+ (unsigned char)(i + 128));
|
|
+ }
|
|
+
|
|
+ init_immortal_varobject(&objects->singletons.tuple_empty.ob_base,
|
|
+ &PyTuple_Type, 0);
|
|
+}
|
|
+
|
|
+void
|
|
+_PyRuntimeState_InitStaticDefaults(_PyRuntimeState *runtime)
|
|
+{
|
|
+ memset(runtime, 0, sizeof(*runtime));
|
|
+ runtime->gilstate.check_enabled = 1;
|
|
+ runtime->interpreters.next_id = -1;
|
|
+ init_static_global_objects(&runtime->global_objects);
|
|
+ init_static_interpreter(&runtime->_main_interpreter);
|
|
+}
|
|
+
|
|
+#else
|
|
/* We use "initial" if the runtime gets re-used
|
|
(e.g. Py_Finalize() followed by Py_Initialize(). */
|
|
static const _PyRuntimeState initial = _PyRuntimeState_INIT;
|
|
+#endif
|
|
_Py_COMP_DIAG_POP
|
|
|
|
static int
|
|
@@ -62,20 +1180,23 @@ alloc_for_runtime(PyThread_type_lock *plock1, PyThread_type_lock *plock2,
|
|
/* Force default allocator, since _PyRuntimeState_Fini() must
|
|
use the same allocator than this function. */
|
|
PyMemAllocatorEx old_alloc;
|
|
+ PyThread_type_lock lock1;
|
|
+ PyThread_type_lock lock2;
|
|
+ PyThread_type_lock lock3;
|
|
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
|
|
|
|
- PyThread_type_lock lock1 = PyThread_allocate_lock();
|
|
+ lock1 = PyThread_allocate_lock();
|
|
if (lock1 == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
- PyThread_type_lock lock2 = PyThread_allocate_lock();
|
|
+ lock2 = PyThread_allocate_lock();
|
|
if (lock2 == NULL) {
|
|
PyThread_free_lock(lock1);
|
|
return -1;
|
|
}
|
|
|
|
- PyThread_type_lock lock3 = PyThread_allocate_lock();
|
|
+ lock3 = PyThread_allocate_lock();
|
|
if (lock3 == NULL) {
|
|
PyThread_free_lock(lock1);
|
|
PyThread_free_lock(lock2);
|
|
@@ -149,7 +1270,11 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime)
|
|
if (runtime->_initialized) {
|
|
// Py_Initialize() must be running again.
|
|
// Reset to _PyRuntimeState_INIT.
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+ _PyRuntimeState_InitStaticDefaults(runtime);
|
|
+#else
|
|
memcpy(runtime, &initial, sizeof(*runtime));
|
|
+#endif
|
|
}
|
|
init_runtime(runtime, open_code_hook, open_code_userdata, audit_hook_head,
|
|
unicode_next_index, lock1, lock2, lock3);
|
|
@@ -302,15 +1427,21 @@ PyInterpreterState *
|
|
PyInterpreterState_New(void)
|
|
{
|
|
PyInterpreterState *interp;
|
|
- PyThreadState *tstate = _PyThreadState_GET();
|
|
+ PyThreadState *tstate;
|
|
+ PyThread_type_lock pending_lock;
|
|
+ _PyRuntimeState *runtime;
|
|
+ struct pyinterpreters *interpreters;
|
|
+ int64_t id;
|
|
+ PyInterpreterState *old_head;
|
|
|
|
/* tstate is NULL when Py_InitializeFromConfig() calls
|
|
PyInterpreterState_New() to create the main interpreter. */
|
|
+ tstate = _PyThreadState_GET();
|
|
if (_PySys_Audit(tstate, "cpython.PyInterpreterState_New", NULL) < 0) {
|
|
return NULL;
|
|
}
|
|
|
|
- PyThread_type_lock pending_lock = PyThread_allocate_lock();
|
|
+ pending_lock = PyThread_allocate_lock();
|
|
if (pending_lock == NULL) {
|
|
if (tstate != NULL) {
|
|
_PyErr_NoMemory(tstate);
|
|
@@ -319,8 +1450,8 @@ PyInterpreterState_New(void)
|
|
}
|
|
|
|
/* Don't get runtime from tstate since tstate can be NULL. */
|
|
- _PyRuntimeState *runtime = &_PyRuntime;
|
|
- struct pyinterpreters *interpreters = &runtime->interpreters;
|
|
+ runtime = &_PyRuntime;
|
|
+ interpreters = &runtime->interpreters;
|
|
|
|
/* We completely serialize creation of multiple interpreters, since
|
|
it simplifies things here and blocking concurrent calls isn't a problem.
|
|
@@ -328,11 +1459,11 @@ PyInterpreterState_New(void)
|
|
after the main interpreter is created. */
|
|
HEAD_LOCK(runtime);
|
|
|
|
- int64_t id = interpreters->next_id;
|
|
+ id = interpreters->next_id;
|
|
interpreters->next_id += 1;
|
|
|
|
// Allocate the interpreter and add it to the runtime state.
|
|
- PyInterpreterState *old_head = interpreters->head;
|
|
+ old_head = interpreters->head;
|
|
if (old_head == NULL) {
|
|
// We are creating the main interpreter.
|
|
assert(interpreters->main == NULL);
|
|
@@ -354,8 +1485,13 @@ PyInterpreterState_New(void)
|
|
goto error;
|
|
}
|
|
// Set to _PyInterpreterState_INIT.
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+ memset(interp, 0, sizeof(*interp));
|
|
+ init_static_interpreter(interp);
|
|
+#else
|
|
memcpy(interp, &initial._main_interpreter,
|
|
sizeof(*interp));
|
|
+#endif
|
|
// We need to adjust any fields that are different from the initial
|
|
// interpreter (as defined in _PyInterpreterState_INIT):
|
|
interp->_static = false;
|
|
@@ -391,6 +1527,7 @@ static void
|
|
interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
|
|
{
|
|
_PyRuntimeState *runtime = interp->runtime;
|
|
+ PyThreadState *p;
|
|
|
|
if (_PySys_Audit(tstate, "cpython.PyInterpreterState_Clear", NULL) < 0) {
|
|
_PyErr_Clear(tstate);
|
|
@@ -398,7 +1535,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
|
|
|
|
// Clear the current/main thread state last.
|
|
HEAD_LOCK(runtime);
|
|
- PyThreadState *p = interp->threads.head;
|
|
+ p = interp->threads.head;
|
|
HEAD_UNLOCK(runtime);
|
|
while (p != NULL) {
|
|
// See https://github.com/python/cpython/issues/102126
|
|
@@ -490,6 +1627,7 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
|
|
{
|
|
_PyRuntimeState *runtime = interp->runtime;
|
|
struct pyinterpreters *interpreters = &runtime->interpreters;
|
|
+ PyInterpreterState **p;
|
|
zapthreads(interp, 0);
|
|
|
|
_PyEval_FiniState(&interp->ceval);
|
|
@@ -498,7 +1636,6 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
|
|
_PyThreadState_Swap(&runtime->gilstate, NULL);
|
|
|
|
HEAD_LOCK(runtime);
|
|
- PyInterpreterState **p;
|
|
for (p = &interpreters->head; ; p = &(*p)->next) {
|
|
if (*p == NULL) {
|
|
Py_FatalError("NULL interpreter");
|
|
@@ -577,9 +1714,12 @@ _PyInterpreterState_DeleteExceptMain(_PyRuntimeState *runtime)
|
|
PyInterpreterState *
|
|
PyInterpreterState_Get(void)
|
|
{
|
|
- PyThreadState *tstate = _PyThreadState_GET();
|
|
+ PyThreadState *tstate;
|
|
+ PyInterpreterState *interp;
|
|
+
|
|
+ tstate = _PyThreadState_GET();
|
|
_Py_EnsureTstateNotNULL(tstate);
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
+ interp = tstate->interp;
|
|
if (interp == NULL) {
|
|
Py_FatalError("no current interpreter");
|
|
}
|
|
@@ -667,20 +1807,25 @@ _PyInterpreterState_IDIncref(PyInterpreterState *interp)
|
|
void
|
|
_PyInterpreterState_IDDecref(PyInterpreterState *interp)
|
|
{
|
|
+ struct _gilstate_runtime_state *gilstate;
|
|
+ int64_t refcount;
|
|
+ PyThreadState *tstate;
|
|
+ PyThreadState *save_tstate;
|
|
+
|
|
assert(interp->id_mutex != NULL);
|
|
|
|
- struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
|
|
+ gilstate = &_PyRuntime.gilstate;
|
|
PyThread_acquire_lock(interp->id_mutex, WAIT_LOCK);
|
|
assert(interp->id_refcount != 0);
|
|
interp->id_refcount -= 1;
|
|
- int64_t refcount = interp->id_refcount;
|
|
+ refcount = interp->id_refcount;
|
|
PyThread_release_lock(interp->id_mutex);
|
|
|
|
if (refcount == 0 && interp->requires_idref) {
|
|
// XXX Using the "head" thread isn't strictly correct.
|
|
- PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
|
|
+ tstate = PyInterpreterState_ThreadHead(interp);
|
|
// XXX Possible GILState issues?
|
|
- PyThreadState *save_tstate = _PyThreadState_Swap(gilstate, tstate);
|
|
+ save_tstate = _PyThreadState_Swap(gilstate, tstate);
|
|
Py_EndInterpreter(tstate);
|
|
_PyThreadState_Swap(gilstate, save_tstate);
|
|
}
|
|
@@ -727,8 +1872,10 @@ PyInterpreterState_GetDict(PyInterpreterState *interp)
|
|
static _PyStackChunk*
|
|
allocate_chunk(int size_in_bytes, _PyStackChunk* previous)
|
|
{
|
|
+ _PyStackChunk *res;
|
|
+
|
|
assert(size_in_bytes % sizeof(PyObject **) == 0);
|
|
- _PyStackChunk *res = _PyObject_VirtualAlloc(size_in_bytes);
|
|
+ res = _PyObject_VirtualAlloc(size_in_bytes);
|
|
if (res == NULL) {
|
|
return NULL;
|
|
}
|
|
@@ -807,12 +1954,15 @@ new_threadstate(PyInterpreterState *interp)
|
|
{
|
|
PyThreadState *tstate;
|
|
_PyRuntimeState *runtime = interp->runtime;
|
|
+ PyThreadState *new_tstate;
|
|
+ int used_newtstate;
|
|
+ uint64_t id;
|
|
+ PyThreadState *old_head;
|
|
// We don't need to allocate a thread state for the main interpreter
|
|
// (the common case), but doing it later for the other case revealed a
|
|
// reentrancy problem (deadlock). So for now we always allocate before
|
|
// taking the interpreters lock. See GH-96071.
|
|
- PyThreadState *new_tstate = alloc_threadstate();
|
|
- int used_newtstate;
|
|
+ new_tstate = alloc_threadstate();
|
|
if (new_tstate == NULL) {
|
|
return NULL;
|
|
}
|
|
@@ -820,10 +1970,10 @@ new_threadstate(PyInterpreterState *interp)
|
|
HEAD_LOCK(runtime);
|
|
|
|
interp->threads.next_unique_id += 1;
|
|
- uint64_t id = interp->threads.next_unique_id;
|
|
+ id = interp->threads.next_unique_id;
|
|
|
|
// Allocate the thread state and add it to the interpreter.
|
|
- PyThreadState *old_head = interp->threads.head;
|
|
+ old_head = interp->threads.head;
|
|
if (old_head == NULL) {
|
|
// It's the interpreter's initial thread state.
|
|
assert(id == 1);
|
|
@@ -838,9 +1988,14 @@ new_threadstate(PyInterpreterState *interp)
|
|
used_newtstate = 1;
|
|
tstate = new_tstate;
|
|
// Set to _PyThreadState_INIT.
|
|
+#if defined(_MSC_VER) && _MSC_VER < 1300
|
|
+ memset(tstate, 0, sizeof(*tstate));
|
|
+ init_static_threadstate(tstate);
|
|
+#else
|
|
memcpy(tstate,
|
|
&initial._main_interpreter._initial_thread,
|
|
sizeof(*tstate));
|
|
+#endif
|
|
// We need to adjust any fields that are different from the initial
|
|
// thread (as defined in _PyThreadState_INIT):
|
|
tstate->_static = false;
|
|
@@ -911,6 +2066,8 @@ PyState_FindModule(PyModuleDef* module)
|
|
int
|
|
_PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
|
|
{
|
|
+ PyInterpreterState *interp;
|
|
+
|
|
if (!def) {
|
|
assert(_PyErr_Occurred(tstate));
|
|
return -1;
|
|
@@ -922,7 +2079,7 @@ _PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
|
|
return -1;
|
|
}
|
|
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
+ interp = tstate->interp;
|
|
if (!interp->modules_by_index) {
|
|
interp->modules_by_index = PyList_New(0);
|
|
if (!interp->modules_by_index) {
|
|
@@ -944,14 +2101,18 @@ _PyState_AddModule(PyThreadState *tstate, PyObject* module, PyModuleDef* def)
|
|
int
|
|
PyState_AddModule(PyObject* module, PyModuleDef* def)
|
|
{
|
|
+ PyThreadState *tstate;
|
|
+ PyInterpreterState *interp;
|
|
+ Py_ssize_t index;
|
|
+
|
|
if (!def) {
|
|
Py_FatalError("module definition is NULL");
|
|
return -1;
|
|
}
|
|
|
|
- PyThreadState *tstate = _PyThreadState_GET();
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
- Py_ssize_t index = def->m_base.m_index;
|
|
+ tstate = _PyThreadState_GET();
|
|
+ interp = tstate->interp;
|
|
+ index = def->m_base.m_index;
|
|
if (interp->modules_by_index &&
|
|
index < PyList_GET_SIZE(interp->modules_by_index) &&
|
|
module == PyList_GET_ITEM(interp->modules_by_index, index))
|
|
@@ -965,8 +2126,12 @@ PyState_AddModule(PyObject* module, PyModuleDef* def)
|
|
int
|
|
PyState_RemoveModule(PyModuleDef* def)
|
|
{
|
|
- PyThreadState *tstate = _PyThreadState_GET();
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
+ PyThreadState *tstate;
|
|
+ PyInterpreterState *interp;
|
|
+ Py_ssize_t index;
|
|
+
|
|
+ tstate = _PyThreadState_GET();
|
|
+ interp = tstate->interp;
|
|
|
|
if (def->m_slots) {
|
|
_PyErr_SetString(tstate,
|
|
@@ -975,7 +2140,7 @@ PyState_RemoveModule(PyModuleDef* def)
|
|
return -1;
|
|
}
|
|
|
|
- Py_ssize_t index = def->m_base.m_index;
|
|
+ index = def->m_base.m_index;
|
|
if (index == 0) {
|
|
Py_FatalError("invalid module index");
|
|
}
|
|
@@ -994,16 +2159,18 @@ PyState_RemoveModule(PyModuleDef* def)
|
|
void
|
|
_PyInterpreterState_ClearModules(PyInterpreterState *interp)
|
|
{
|
|
+ Py_ssize_t i;
|
|
+
|
|
if (!interp->modules_by_index) {
|
|
return;
|
|
}
|
|
|
|
- Py_ssize_t i;
|
|
for (i = 0; i < PyList_GET_SIZE(interp->modules_by_index); i++) {
|
|
PyObject *m = PyList_GET_ITEM(interp->modules_by_index, i);
|
|
if (PyModule_Check(m)) {
|
|
+ PyModuleDef *md;
|
|
/* cleanup the saved copy of module dicts */
|
|
- PyModuleDef *md = PyModule_GetDef(m);
|
|
+ md = PyModule_GetDef(m);
|
|
if (md) {
|
|
Py_CLEAR(md->m_base.m_copy);
|
|
}
|
|
@@ -1074,12 +2241,16 @@ static void
|
|
tstate_delete_common(PyThreadState *tstate,
|
|
struct _gilstate_runtime_state *gilstate)
|
|
{
|
|
+ PyInterpreterState *interp;
|
|
+ _PyRuntimeState *runtime;
|
|
+ _PyStackChunk *chunk;
|
|
+
|
|
_Py_EnsureTstateNotNULL(tstate);
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
+ interp = tstate->interp;
|
|
if (interp == NULL) {
|
|
Py_FatalError("NULL interpreter");
|
|
}
|
|
- _PyRuntimeState *runtime = interp->runtime;
|
|
+ runtime = interp->runtime;
|
|
|
|
HEAD_LOCK(runtime);
|
|
if (tstate->prev) {
|
|
@@ -1098,7 +2269,7 @@ tstate_delete_common(PyThreadState *tstate,
|
|
{
|
|
PyThread_tss_set(&gilstate->autoTSSkey, NULL);
|
|
}
|
|
- _PyStackChunk *chunk = tstate->datastack_chunk;
|
|
+ chunk = tstate->datastack_chunk;
|
|
tstate->datastack_chunk = NULL;
|
|
while (chunk != NULL) {
|
|
_PyStackChunk *prev = chunk->previous;
|
|
@@ -1131,8 +2302,10 @@ PyThreadState_Delete(PyThreadState *tstate)
|
|
void
|
|
_PyThreadState_DeleteCurrent(PyThreadState *tstate)
|
|
{
|
|
+ struct _gilstate_runtime_state *gilstate;
|
|
+
|
|
_Py_EnsureTstateNotNULL(tstate);
|
|
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
|
|
+ gilstate = &tstate->interp->runtime->gilstate;
|
|
tstate_delete_common(tstate, gilstate);
|
|
_PyRuntimeGILState_SetThreadState(gilstate, NULL);
|
|
_PyEval_ReleaseLock(tstate);
|
|
@@ -1159,12 +2332,14 @@ void
|
|
_PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate)
|
|
{
|
|
PyInterpreterState *interp = tstate->interp;
|
|
+ PyThreadState *list;
|
|
+ PyThreadState *p, *next;
|
|
|
|
HEAD_LOCK(runtime);
|
|
/* Remove all thread states, except tstate, from the linked list of
|
|
thread states. This will allow calling PyThreadState_Clear()
|
|
without holding the lock. */
|
|
- PyThreadState *list = interp->threads.head;
|
|
+ list = interp->threads.head;
|
|
if (list == tstate) {
|
|
list = tstate->next;
|
|
}
|
|
@@ -1181,7 +2356,6 @@ _PyThreadState_DeleteExcept(_PyRuntimeState *runtime, PyThreadState *tstate)
|
|
/* Clear and deallocate all stale thread states. Even if this
|
|
executes Python code, we should be safe since it executes
|
|
in the current thread, not one of the stale threads. */
|
|
- PyThreadState *p, *next;
|
|
for (p = list; p; p = next) {
|
|
next = p->next;
|
|
PyThreadState_Clear(p);
|
|
@@ -1279,15 +2453,18 @@ PyThreadState_GetInterpreter(PyThreadState *tstate)
|
|
PyFrameObject*
|
|
PyThreadState_GetFrame(PyThreadState *tstate)
|
|
{
|
|
+ _PyInterpreterFrame *f;
|
|
+ PyFrameObject *frame;
|
|
+
|
|
assert(tstate != NULL);
|
|
- _PyInterpreterFrame *f = tstate->cframe->current_frame;
|
|
+ f = tstate->cframe->current_frame;
|
|
while (f && _PyFrame_IsIncomplete(f)) {
|
|
f = f->previous;
|
|
}
|
|
if (f == NULL) {
|
|
return NULL;
|
|
}
|
|
- PyFrameObject *frame = _PyFrame_GetFrameObject(f);
|
|
+ frame = _PyFrame_GetFrameObject(f);
|
|
if (frame == NULL) {
|
|
PyErr_Clear();
|
|
}
|
|
@@ -1317,6 +2494,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
|
|
{
|
|
_PyRuntimeState *runtime = &_PyRuntime;
|
|
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
|
|
+ PyThreadState *tstate;
|
|
|
|
/* Although the GIL is held, a few C API functions can be called
|
|
* without the GIL held, and in particular some that create and
|
|
@@ -1325,7 +2503,9 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
|
|
* head_mutex for the duration.
|
|
*/
|
|
HEAD_LOCK(runtime);
|
|
- for (PyThreadState *tstate = interp->threads.head; tstate != NULL; tstate = tstate->next) {
|
|
+ for (tstate = interp->threads.head; tstate != NULL; tstate = tstate->next) {
|
|
+ PyObject *old_exc;
|
|
+
|
|
if (tstate->thread_id != id) {
|
|
continue;
|
|
}
|
|
@@ -1337,7 +2517,7 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
|
|
* deadlock, we need to release head_mutex before
|
|
* the decref.
|
|
*/
|
|
- PyObject *old_exc = tstate->async_exc;
|
|
+ old_exc = tstate->async_exc;
|
|
Py_XINCREF(exc);
|
|
tstate->async_exc = exc;
|
|
HEAD_UNLOCK(runtime);
|
|
@@ -1389,17 +2569,22 @@ PyObject *
|
|
_PyThread_CurrentFrames(void)
|
|
{
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
|
+ PyObject *result;
|
|
+ int gc_was_enabled;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyInterpreterState *i;
|
|
+
|
|
if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) {
|
|
return NULL;
|
|
}
|
|
|
|
- PyObject *result = PyDict_New();
|
|
+ result = PyDict_New();
|
|
if (result == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
// gh-106883: Disable the GC as this can cause the interpreter to deadlock
|
|
- int gc_was_enabled = PyGC_Disable();
|
|
+ gc_was_enabled = PyGC_Disable();
|
|
|
|
/* for i in all interpreters:
|
|
* for t in all of i's thread states:
|
|
@@ -1407,29 +2592,33 @@ _PyThread_CurrentFrames(void)
|
|
* Because these lists can mutate even when the GIL is held, we
|
|
* need to grab head_mutex for the duration.
|
|
*/
|
|
- _PyRuntimeState *runtime = tstate->interp->runtime;
|
|
+ runtime = tstate->interp->runtime;
|
|
HEAD_LOCK(runtime);
|
|
- PyInterpreterState *i;
|
|
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
|
|
PyThreadState *t;
|
|
for (t = i->threads.head; t != NULL; t = t->next) {
|
|
- _PyInterpreterFrame *frame = t->cframe->current_frame;
|
|
+ _PyInterpreterFrame *frame;
|
|
+ PyObject *id;
|
|
+ PyObject *frameobj;
|
|
+ int stat;
|
|
+
|
|
+ frame = t->cframe->current_frame;
|
|
while (frame && _PyFrame_IsIncomplete(frame)) {
|
|
frame = frame->previous;
|
|
}
|
|
if (frame == NULL) {
|
|
continue;
|
|
}
|
|
- PyObject *id = PyLong_FromUnsignedLong(t->thread_id);
|
|
+ id = PyLong_FromUnsignedLong(t->thread_id);
|
|
if (id == NULL) {
|
|
goto fail;
|
|
}
|
|
- PyObject *frameobj = (PyObject *)_PyFrame_GetFrameObject(frame);
|
|
+ frameobj = (PyObject *)_PyFrame_GetFrameObject(frame);
|
|
if (frameobj == NULL) {
|
|
Py_DECREF(id);
|
|
goto fail;
|
|
}
|
|
- int stat = PyDict_SetItem(result, id, frameobj);
|
|
+ stat = PyDict_SetItem(result, id, frameobj);
|
|
Py_DECREF(id);
|
|
if (stat < 0) {
|
|
goto fail;
|
|
@@ -1456,6 +2645,10 @@ PyObject *
|
|
_PyThread_CurrentExceptions(void)
|
|
{
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
|
+ PyObject *result;
|
|
+ int gc_was_enabled;
|
|
+ _PyRuntimeState *runtime;
|
|
+ PyInterpreterState *i;
|
|
|
|
_Py_EnsureTstateNotNULL(tstate);
|
|
|
|
@@ -1463,13 +2656,13 @@ _PyThread_CurrentExceptions(void)
|
|
return NULL;
|
|
}
|
|
|
|
- PyObject *result = PyDict_New();
|
|
+ result = PyDict_New();
|
|
if (result == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
// gh-106883: Disable the GC as this can cause the interpreter to deadlock
|
|
- int gc_was_enabled = PyGC_Disable();
|
|
+ gc_was_enabled = PyGC_Disable();
|
|
|
|
/* for i in all interpreters:
|
|
* for t in all of i's thread states:
|
|
@@ -1477,26 +2670,30 @@ _PyThread_CurrentExceptions(void)
|
|
* Because these lists can mutate even when the GIL is held, we
|
|
* need to grab head_mutex for the duration.
|
|
*/
|
|
- _PyRuntimeState *runtime = tstate->interp->runtime;
|
|
+ runtime = tstate->interp->runtime;
|
|
HEAD_LOCK(runtime);
|
|
- PyInterpreterState *i;
|
|
for (i = runtime->interpreters.head; i != NULL; i = i->next) {
|
|
PyThreadState *t;
|
|
for (t = i->threads.head; t != NULL; t = t->next) {
|
|
- _PyErr_StackItem *err_info = _PyErr_GetTopmostException(t);
|
|
+ _PyErr_StackItem *err_info;
|
|
+ PyObject *id;
|
|
+ PyObject *exc_info;
|
|
+ int stat;
|
|
+
|
|
+ err_info = _PyErr_GetTopmostException(t);
|
|
if (err_info == NULL) {
|
|
continue;
|
|
}
|
|
- PyObject *id = PyLong_FromUnsignedLong(t->thread_id);
|
|
+ id = PyLong_FromUnsignedLong(t->thread_id);
|
|
if (id == NULL) {
|
|
goto fail;
|
|
}
|
|
- PyObject *exc_info = _PyErr_StackItemToExcInfoTuple(err_info);
|
|
+ exc_info = _PyErr_StackItemToExcInfoTuple(err_info);
|
|
if (exc_info == NULL) {
|
|
Py_DECREF(id);
|
|
goto fail;
|
|
}
|
|
- int stat = PyDict_SetItem(result, id, exc_info);
|
|
+ stat = PyDict_SetItem(result, id, exc_info);
|
|
Py_DECREF(id);
|
|
Py_DECREF(exc_info);
|
|
if (stat < 0) {
|
|
@@ -1559,6 +2756,8 @@ _PyGILState_Init(_PyRuntimeState *runtime)
|
|
PyStatus
|
|
_PyGILState_SetTstate(PyThreadState *tstate)
|
|
{
|
|
+ struct _gilstate_runtime_state *gilstate;
|
|
+
|
|
if (!_Py_IsMainInterpreter(tstate->interp)) {
|
|
/* Currently, PyGILState is shared by all interpreters. The main
|
|
* interpreter is responsible to initialize it. */
|
|
@@ -1569,7 +2768,7 @@ _PyGILState_SetTstate(PyThreadState *tstate)
|
|
assert(tstate != NULL);
|
|
assert(tstate->interp != NULL);
|
|
|
|
- struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
|
|
+ gilstate = &tstate->interp->runtime->gilstate;
|
|
|
|
gilstate->autoInterpreterState = tstate->interp;
|
|
assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL);
|
|
@@ -1676,6 +2875,7 @@ int
|
|
PyGILState_Check(void)
|
|
{
|
|
struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
|
|
+ PyThreadState *tstate;
|
|
if (!gilstate->check_enabled) {
|
|
return 1;
|
|
}
|
|
@@ -1684,7 +2884,7 @@ PyGILState_Check(void)
|
|
return 1;
|
|
}
|
|
|
|
- PyThreadState *tstate = _PyRuntimeGILState_GetThreadState(gilstate);
|
|
+ tstate = _PyRuntimeGILState_GetThreadState(gilstate);
|
|
if (tstate == NULL) {
|
|
return 0;
|
|
}
|
|
@@ -1697,6 +2897,8 @@ PyGILState_Ensure(void)
|
|
{
|
|
_PyRuntimeState *runtime = &_PyRuntime;
|
|
struct _gilstate_runtime_state *gilstate = &runtime->gilstate;
|
|
+ PyThreadState *tcur;
|
|
+ int current;
|
|
|
|
/* Note that we do not auto-init Python here - apart from
|
|
potential races with 2 threads auto-initializing, pep-311
|
|
@@ -1708,8 +2910,7 @@ PyGILState_Ensure(void)
|
|
assert(_PyEval_ThreadsInitialized(runtime));
|
|
assert(gilstate->autoInterpreterState);
|
|
|
|
- PyThreadState *tcur = (PyThreadState *)PyThread_tss_get(&gilstate->autoTSSkey);
|
|
- int current;
|
|
+ tcur = (PyThreadState *)PyThread_tss_get(&gilstate->autoTSSkey);
|
|
if (tcur == NULL) {
|
|
/* Create a new Python thread state for this thread */
|
|
tcur = PyThreadState_New(gilstate->autoInterpreterState);
|
|
@@ -1841,24 +3042,27 @@ int
|
|
_PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data)
|
|
{
|
|
PyThreadState *tstate = _PyThreadState_GET();
|
|
+ PyInterpreterState *interp;
|
|
+ crossinterpdatafunc getdata;
|
|
+ int res;
|
|
#ifdef Py_DEBUG
|
|
// The caller must hold the GIL
|
|
_Py_EnsureTstateNotNULL(tstate);
|
|
#endif
|
|
- PyInterpreterState *interp = tstate->interp;
|
|
+ interp = tstate->interp;
|
|
|
|
// Reset data before re-populating.
|
|
- *data = (_PyCrossInterpreterData){0};
|
|
+ memset(data, 0, sizeof(*data));
|
|
data->free = PyMem_RawFree; // Set a default that may be overridden.
|
|
|
|
// Call the "getdata" func for the object.
|
|
Py_INCREF(obj);
|
|
- crossinterpdatafunc getdata = _lookup_getdata(obj);
|
|
+ getdata = _lookup_getdata(obj);
|
|
if (getdata == NULL) {
|
|
Py_DECREF(obj);
|
|
return -1;
|
|
}
|
|
- int res = getdata(obj, data);
|
|
+ res = getdata(obj, data);
|
|
Py_DECREF(obj);
|
|
if (res != 0) {
|
|
return -1;
|
|
@@ -1912,13 +3116,16 @@ _call_in_interpreter(struct _gilstate_runtime_state *gilstate,
|
|
void
|
|
_PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
|
|
{
|
|
+ PyInterpreterState *interp;
|
|
+ struct _gilstate_runtime_state *gilstate;
|
|
+
|
|
if (data->data == NULL && data->obj == NULL) {
|
|
// Nothing to release!
|
|
return;
|
|
}
|
|
|
|
// Switch to the original interpreter.
|
|
- PyInterpreterState *interp = _PyInterpreterState_LookUpID(data->interp);
|
|
+ interp = _PyInterpreterState_LookUpID(data->interp);
|
|
if (interp == NULL) {
|
|
// The interpreter was already destroyed.
|
|
if (data->free != NULL) {
|
|
@@ -1928,7 +3135,7 @@ _PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
|
|
}
|
|
|
|
// "Release" the data and/or the object.
|
|
- struct _gilstate_runtime_state *gilstate = &_PyRuntime.gilstate;
|
|
+ gilstate = &_PyRuntime.gilstate;
|
|
_call_in_interpreter(gilstate, interp, _release_xidata, data);
|
|
}
|
|
|
|
@@ -1966,6 +3173,9 @@ int
|
|
_PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
|
|
crossinterpdatafunc getdata)
|
|
{
|
|
+ struct _xidregistry *xidregistry;
|
|
+ int res;
|
|
+
|
|
if (!PyType_Check(cls)) {
|
|
PyErr_Format(PyExc_ValueError, "only classes may be registered");
|
|
return -1;
|
|
@@ -1978,12 +3188,12 @@ _PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
|
|
// Make sure the class isn't ever deallocated.
|
|
Py_INCREF((PyObject *)cls);
|
|
|
|
- struct _xidregistry *xidregistry = &_PyRuntime.xidregistry ;
|
|
+ xidregistry = &_PyRuntime.xidregistry;
|
|
PyThread_acquire_lock(xidregistry->mutex, WAIT_LOCK);
|
|
if (xidregistry->head == NULL) {
|
|
_register_builtins_for_crossinterpreter_data(xidregistry);
|
|
}
|
|
- int res = _register_xidata(xidregistry, cls, getdata);
|
|
+ res = _register_xidata(xidregistry, cls, getdata);
|
|
PyThread_release_lock(xidregistry->mutex);
|
|
return res;
|
|
}
|
|
@@ -1995,11 +3205,13 @@ _PyCrossInterpreterData_RegisterClass(PyTypeObject *cls,
|
|
crossinterpdatafunc
|
|
_PyCrossInterpreterData_Lookup(PyObject *obj)
|
|
{
|
|
- struct _xidregistry *xidregistry = &_PyRuntime.xidregistry ;
|
|
+ struct _xidregistry *xidregistry = &_PyRuntime.xidregistry;
|
|
PyObject *cls = PyObject_Type(obj);
|
|
crossinterpdatafunc getdata = NULL;
|
|
+ struct _xidregitem *cur;
|
|
+
|
|
PyThread_acquire_lock(xidregistry->mutex, WAIT_LOCK);
|
|
- struct _xidregitem *cur = xidregistry->head;
|
|
+ cur = xidregistry->head;
|
|
if (cur == NULL) {
|
|
_register_builtins_for_crossinterpreter_data(xidregistry);
|
|
cur = xidregistry->head;
|
|
@@ -2189,8 +3401,10 @@ _PyInterpreterState_GetConfigCopy(PyConfig *config)
|
|
const PyConfig*
|
|
_Py_GetConfig(void)
|
|
{
|
|
+ PyThreadState *tstate;
|
|
+
|
|
assert(PyGILState_Check());
|
|
- PyThreadState *tstate = _PyThreadState_GET();
|
|
+ tstate = _PyThreadState_GET();
|
|
return _PyInterpreterState_GetConfig(tstate->interp);
|
|
}
|
|
|
|
@@ -2200,10 +3414,13 @@ static PyObject **
|
|
push_chunk(PyThreadState *tstate, int size)
|
|
{
|
|
int allocate_size = DATA_STACK_CHUNK_SIZE;
|
|
+ _PyStackChunk *new;
|
|
+ PyObject **res;
|
|
+
|
|
while (allocate_size < (int)sizeof(PyObject*)*(size + MINIMUM_OVERHEAD)) {
|
|
allocate_size *= 2;
|
|
}
|
|
- _PyStackChunk *new = allocate_chunk(allocate_size, tstate->datastack_chunk);
|
|
+ new = allocate_chunk(allocate_size, tstate->datastack_chunk);
|
|
if (new == NULL) {
|
|
return NULL;
|
|
}
|
|
@@ -2216,7 +3433,7 @@ push_chunk(PyThreadState *tstate, int size)
|
|
// When new is the "root" chunk (i.e. new->previous == NULL), we can keep
|
|
// _PyThreadState_PopFrame from freeing it later by "skipping" over the
|
|
// first element:
|
|
- PyObject **res = &new->data[new->previous == NULL];
|
|
+ res = &new->data[new->previous == NULL];
|
|
tstate->datastack_top = res + size;
|
|
return res;
|
|
}
|
|
@@ -2239,8 +3456,10 @@ _PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size)
|
|
void
|
|
_PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * frame)
|
|
{
|
|
+ PyObject **base;
|
|
+
|
|
assert(tstate->datastack_chunk);
|
|
- PyObject **base = (PyObject **)frame;
|
|
+ base = (PyObject **)frame;
|
|
if (base == &tstate->datastack_chunk->data[0]) {
|
|
_PyStackChunk *chunk = tstate->datastack_chunk;
|
|
_PyStackChunk *previous = chunk->previous;
|