Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use int_fast64_t for the interpreter ID.
  • Loading branch information
ericsnowcurrently committed May 22, 2017
commit 5caac3dcbd74d99c3ca558e304ce816d4c77019a
18 changes: 8 additions & 10 deletions Include/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,28 @@ removed (with effort). */

/* State shared between threads */

#ifndef Py_LIMITED_API
/* This is initialized to 1 in Py_Initialize(). An interpreter
ID of 0 is reserved for errors. The main interpreter will always
have an ID of 1. Overflow results in a RuntimeError. If that
becomes a problem later then we can adjust, e.g. by using a 64-bit
int or even a Python int. */
PyAPI_DATA(unsigned long) _PyInterpreterState_next_id;
#endif

struct _ts; /* Forward */
struct _is; /* Forward */
struct _frame; /* Forward declaration for PyFrameObject. */

#ifdef Py_LIMITED_API
typedef struct _is PyInterpreterState;
#else
/* This is initialized to 0 in Py_Initialize(). A negative interpreter
ID indicates an error occurred. The main interpreter will always
have an ID of 0. Overflow results in a RuntimeError. If that
becomes a problem later then we can adjust, e.g. by using a Python
int. */
PyAPI_DATA(int_fast64_t) _PyInterpreterState_next_id;

typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);

typedef struct _is {

struct _is *next;
struct _ts *tstate_head;

unsigned long id;
int_fast64_t id;

PyObject *modules;
PyObject *modules_by_index;
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_capi.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def test_subinterps(self):
print(line)
lastmain = main
main = None
mainid = 1
mainid = 0
numloops += 1
numinner = 0
continue
Expand Down
2 changes: 1 addition & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)

_PyRandom_Init();

_PyInterpreterState_next_id = 1;
_PyInterpreterState_next_id = 0;
interp = PyInterpreterState_New();
if (interp == NULL)
Py_FatalError("Py_Initialize: can't make first interpreter");
Expand Down
6 changes: 3 additions & 3 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ static void _PyGILState_NoteThreadState(PyThreadState* tstate);
#endif


/* We initialize this to 0 so that the pre-Py_Initialize() value
/* We initialize this to -1 so that the pre-Py_Initialize() value
results in an error. */
unsigned long _PyInterpreterState_next_id = 0;
int_fast64_t _PyInterpreterState_next_id = -1;

PyInterpreterState *
PyInterpreterState_New(void)
Expand Down Expand Up @@ -107,7 +107,7 @@ PyInterpreterState_New(void)
HEAD_LOCK();
interp->next = interp_head;
interp_head = interp;
if (_PyInterpreterState_next_id == 0) {
if (_PyInterpreterState_next_id < 0) {
/* overflow or Py_Initialize() not called! */
PyErr_SetString(PyExc_RuntimeError,
"failed to get an interpreter ID");
Expand Down