Skip to content

Commit a797883

Browse files
Group sharing-related code.
1 parent 52c9c2f commit a797883

File tree

1 file changed

+75
-75
lines changed

1 file changed

+75
-75
lines changed

Modules/_interpretersmodule.c

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _get_current(void)
1818
return tstate->interp;
1919
}
2020

21-
/* sharing-specific functions */
21+
/* sharing-specific functions and structs */
2222

2323
static int
2424
_PyObject_CheckShareable(PyObject *obj)
@@ -94,80 +94,6 @@ _PyCrossInterpreterData_NewObject(_PyCrossInterpreterData *data)
9494
return data->new_object(data);
9595
}
9696

97-
/* interpreter-specific functions */
98-
99-
static PyInterpreterState *
100-
_look_up_int64(PY_INT64_T requested_id)
101-
{
102-
if (requested_id < 0)
103-
goto error;
104-
105-
PyInterpreterState *interp = PyInterpreterState_Head();
106-
while (interp != NULL) {
107-
PY_INT64_T id = PyInterpreterState_GetID(interp);
108-
if (id < 0)
109-
return NULL;
110-
if (requested_id == id)
111-
return interp;
112-
interp = PyInterpreterState_Next(interp);
113-
}
114-
115-
error:
116-
PyErr_Format(PyExc_RuntimeError,
117-
"unrecognized interpreter ID %lld", requested_id);
118-
return NULL;
119-
}
120-
121-
static PyInterpreterState *
122-
_look_up(PyObject *requested_id)
123-
{
124-
long long id = PyLong_AsLongLong(requested_id);
125-
if (id == -1 && PyErr_Occurred() != NULL)
126-
return NULL;
127-
assert(id <= INT64_MAX);
128-
return _look_up_int64(id);
129-
}
130-
131-
static PyObject *
132-
_get_id(PyInterpreterState *interp)
133-
{
134-
PY_INT64_T id = PyInterpreterState_GetID(interp);
135-
if (id < 0)
136-
return NULL;
137-
return PyLong_FromLongLong(id);
138-
}
139-
140-
static int
141-
_is_running(PyInterpreterState *interp)
142-
{
143-
PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
144-
if (PyThreadState_Next(tstate) != NULL) {
145-
PyErr_SetString(PyExc_RuntimeError,
146-
"interpreter has more than one thread");
147-
return -1;
148-
}
149-
PyFrameObject *frame = _PyThreadState_GetFrame(tstate);
150-
if (frame == NULL) {
151-
if (PyErr_Occurred() != NULL)
152-
return -1;
153-
return 0;
154-
}
155-
return (int)(frame->f_executing);
156-
}
157-
158-
static int
159-
_ensure_not_running(PyInterpreterState *interp)
160-
{
161-
int is_running = _is_running(interp);
162-
if (is_running < 0)
163-
return -1;
164-
if (is_running) {
165-
PyErr_Format(PyExc_RuntimeError, "interpreter already running");
166-
return -1;
167-
}
168-
return 0;
169-
}
170-
17197
struct _shareditem {
17298
Py_UNICODE *name;
17399
Py_ssize_t namelen;
@@ -263,6 +189,80 @@ _apply_shared_exception(struct _shared_exception *exc)
263189

264190
}
265191

192+
/* interpreter-specific functions */
193+
194+
static PyInterpreterState *
195+
_look_up_int64(PY_INT64_T requested_id)
196+
{
197+
if (requested_id < 0)
198+
goto error;
199+
200+
PyInterpreterState *interp = PyInterpreterState_Head();
201+
while (interp != NULL) {
202+
PY_INT64_T id = PyInterpreterState_GetID(interp);
203+
if (id < 0)
204+
return NULL;
205+
if (requested_id == id)
206+
return interp;
207+
interp = PyInterpreterState_Next(interp);
208+
}
209+
210+
error:
211+
PyErr_Format(PyExc_RuntimeError,
212+
"unrecognized interpreter ID %lld", requested_id);
213+
return NULL;
214+
}
215+
216+
static PyInterpreterState *
217+
_look_up(PyObject *requested_id)
218+
{
219+
long long id = PyLong_AsLongLong(requested_id);
220+
if (id == -1 && PyErr_Occurred() != NULL)
221+
return NULL;
222+
assert(id <= INT64_MAX);
223+
return _look_up_int64(id);
224+
}
225+
226+
static PyObject *
227+
_get_id(PyInterpreterState *interp)
228+
{
229+
PY_INT64_T id = PyInterpreterState_GetID(interp);
230+
if (id < 0)
231+
return NULL;
232+
return PyLong_FromLongLong(id);
233+
}
234+
235+
static int
236+
_is_running(PyInterpreterState *interp)
237+
{
238+
PyThreadState *tstate = PyInterpreterState_ThreadHead(interp);
239+
if (PyThreadState_Next(tstate) != NULL) {
240+
PyErr_SetString(PyExc_RuntimeError,
241+
"interpreter has more than one thread");
242+
return -1;
243+
}
244+
PyFrameObject *frame = _PyThreadState_GetFrame(tstate);
245+
if (frame == NULL) {
246+
if (PyErr_Occurred() != NULL)
247+
return -1;
248+
return 0;
249+
}
250+
return (int)(frame->f_executing);
251+
}
252+
253+
static int
254+
_ensure_not_running(PyInterpreterState *interp)
255+
{
256+
int is_running = _is_running(interp);
257+
if (is_running < 0)
258+
return -1;
259+
if (is_running) {
260+
PyErr_Format(PyExc_RuntimeError, "interpreter already running");
261+
return -1;
262+
}
263+
return 0;
264+
}
265+
266266
static int
267267
_run_script(PyInterpreterState *interp, const char *codestr,
268268
struct _shareditem *shared, struct _shared_exception **exc)

0 commit comments

Comments
 (0)