@@ -1214,6 +1214,40 @@ _PyObject_GetCrossInterpreterData(PyObject *obj, _PyCrossInterpreterData *data)
1214
1214
return 0 ;
1215
1215
}
1216
1216
1217
+ static void
1218
+ _release_xidata (void * arg )
1219
+ {
1220
+ _PyCrossInterpreterData * data = (_PyCrossInterpreterData * )arg ;
1221
+ if (data -> free != NULL ) {
1222
+ data -> free (data -> data );
1223
+ }
1224
+ Py_XDECREF (data -> obj );
1225
+ }
1226
+
1227
+ static void
1228
+ _call_in_interpreter (PyInterpreterState * interp ,
1229
+ void (* func )(void * ), void * arg )
1230
+ {
1231
+ /* We would use Py_AddPendingCall() if it weren't specific to the
1232
+ * main interpreter (see bpo-33608). In the meantime we take a
1233
+ * naive approach.
1234
+ */
1235
+ PyThreadState * save_tstate = NULL ;
1236
+ if (interp != PyThreadState_Get ()-> interp ) {
1237
+ // XXX Using the "head" thread isn't strictly correct.
1238
+ PyThreadState * tstate = PyInterpreterState_ThreadHead (interp );
1239
+ // XXX Possible GILState issues?
1240
+ save_tstate = PyThreadState_Swap (tstate );
1241
+ }
1242
+
1243
+ func (arg );
1244
+
1245
+ // Switch back.
1246
+ if (save_tstate != NULL ) {
1247
+ PyThreadState_Swap (save_tstate );
1248
+ }
1249
+ }
1250
+
1217
1251
void
1218
1252
_PyCrossInterpreterData_Release (_PyCrossInterpreterData * data )
1219
1253
{
@@ -1232,24 +1266,8 @@ _PyCrossInterpreterData_Release(_PyCrossInterpreterData *data)
1232
1266
return ;
1233
1267
}
1234
1268
1235
- PyThreadState * save_tstate = NULL ;
1236
- if (interp != PyThreadState_Get ()-> interp ) {
1237
- // XXX Using the "head" thread isn't strictly correct.
1238
- PyThreadState * tstate = PyInterpreterState_ThreadHead (interp );
1239
- // XXX Possible GILState issues?
1240
- save_tstate = PyThreadState_Swap (tstate );
1241
- }
1242
-
1243
1269
// "Release" the data and/or the object.
1244
- if (data -> free != NULL ) {
1245
- data -> free (data -> data );
1246
- }
1247
- Py_XDECREF (data -> obj );
1248
-
1249
- // Switch back.
1250
- if (save_tstate != NULL ) {
1251
- PyThreadState_Swap (save_tstate );
1252
- }
1270
+ _call_in_interpreter (interp , _release_xidata , data );
1253
1271
}
1254
1272
1255
1273
PyObject *
0 commit comments