Skip to content

Commit

Permalink
Set Py_MOD_GIL_NOT_USED for a number of framework extensions
Browse files Browse the repository at this point in the history
Issue #608
  • Loading branch information
ronaldoussoren committed Jul 14, 2024
1 parent e8df357 commit 66c5899
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 40 deletions.
4 changes: 1 addition & 3 deletions pyobjc-framework-CoreMedia/Modules/_CoreMedia.m
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,7 @@ static int mod_exec_module(PyObject* m)
#pragma clang diagnostic ignored "-Wunguarded-availability-new"

if (&CMVideoFormatDescriptionCreateFromHEVCParameterSets == NULL) {
if (PyDict_DelItemString(PyModule_GetDict(m),
"CMVideoFormatDescriptionCreateFromHEVCParameterSets")
== -1) {
if (PyObject_DelAttrString(m, "CMVideoFormatDescriptionCreateFromHEVCParameterSets") == -1) {
return -1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static int mod_exec_module(PyObject* m)
return -1;

cls = objc_lookUpClass("SFAuthorizationView");
if (cls == NULL) {
if (cls == Nil) {
return 0;
}

Expand Down Expand Up @@ -205,7 +205,7 @@ static int mod_exec_module(PyObject* m)
{
/* The code in this extension should be safe to use without the GIL */
.slot = Py_mod_gil,
.value = Py_MOD_GIL_USED,
.value = Py_MOD_GIL_NOT_USED,
},
#endif
{ /* Sentinel */
Expand Down
6 changes: 1 addition & 5 deletions pyobjc-framework-SpriteKit/Modules/_SpriteKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

#import <SpriteKit/SpriteKit.h>

/* We include the source code here instead of
* using the linker due to limitations in pyobjc-api.h
*/
#include "_SpriteKit_protocols.m"

#if PyObjC_BUILD_RELEASE >= 1012
Expand Down Expand Up @@ -36,7 +33,6 @@
for (i = 0; i < vertexCount; i++) {
PyObject* item = PySequence_GetItem(value, i);
if (item == NULL) {
Py_DECREF(item);
PyMem_Free(result);
return NULL;
}
Expand Down Expand Up @@ -255,7 +251,7 @@ static int mod_exec_module(PyObject* m)
{
/* The code in this extension should be safe to use without the GIL */
.slot = Py_mod_gil,
.value = Py_MOD_GIL_USED,
.value = Py_MOD_GIL_NOT_USED,
},
#endif
{ /* Sentinel */
Expand Down
6 changes: 5 additions & 1 deletion pyobjc-framework-SystemConfiguration/Modules/_manual.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

/*
* Context definitions
*
* Note that the use of a tuple object for the context 'info'
* is safe because the tuple is fully owned by the context object,
* free-threading doesn't change this.
*/

static const void*
Expand Down Expand Up @@ -525,7 +529,7 @@ static int mod_exec_module(PyObject* m)
{
/* The code in this extension should be safe to use without the GIL */
.slot = Py_mod_gil,
.value = Py_MOD_GIL_USED,
.value = Py_MOD_GIL_NOT_USED,
},
#endif
{ /* Sentinel */
Expand Down
2 changes: 1 addition & 1 deletion pyobjc-framework-VideoToolbox/Modules/_VideoToolbox.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static int mod_exec_module(PyObject* m)
{
/* The code in this extension should be safe to use without the GIL */
.slot = Py_mod_gil,
.value = Py_MOD_GIL_USED,
.value = Py_MOD_GIL_NOT_USED,
},
#endif
{ /* Sentinel */
Expand Down
29 changes: 13 additions & 16 deletions pyobjc-framework-Vision/Modules/_Vision.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@
size_t imageWidth;
size_t imageHeight;

if (args == NULL || !PyTuple_Check(args) || PyTuple_Size(args) != 4) {
if (args == NULL || !PyTuple_Check(args) || PyTuple_GET_SIZE(args) != 4) {
PyErr_SetString(PyExc_TypeError,
"Vision.VNNormalizedFaceBoundingBoxPointForLandmarkPoint "
"requires 4 arguments");
return NULL;
}
if (PyObjC_PythonToObjC("<2f>", PyTuple_GetItem(args, 0), &faceLandmarkPoint) == -1) {
if (PyObjC_PythonToObjC("<2f>", PyTuple_GET_ITEM(args, 0), &faceLandmarkPoint) == -1) {
return NULL;
}
if (PyObjC_PythonToObjC(@encode(CGRect), PyTuple_GetItem(args, 1), &faceBoundingBox)
if (PyObjC_PythonToObjC(@encode(CGRect), PyTuple_GET_ITEM(args, 1), &faceBoundingBox)
== -1) {
return NULL;
}
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GetItem(args, 2), &imageWidth)
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GET_ITEM(args, 2), &imageWidth)
== -1) {
return NULL;
}
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GetItem(args, 3), &imageHeight)
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GET_ITEM(args, 3), &imageHeight)
== -1) {
return NULL;
}
Expand Down Expand Up @@ -89,23 +89,23 @@
size_t imageWidth;
size_t imageHeight;

if (args == NULL || !PyTuple_Check(args) || PyTuple_Size(args) != 4) {
if (args == NULL || !PyTuple_Check(args) || PyTuple_GET_SIZE(args) != 4) {
PyErr_SetString(PyExc_TypeError,
"Vision.VNImagePointForFaceLandmarkPoint requires 4 arguments");
return NULL;
}
if (PyObjC_PythonToObjC("<2f>", PyTuple_GetItem(args, 0), &faceLandmarkPoint) == -1) {
if (PyObjC_PythonToObjC("<2f>", PyTuple_GET_ITEM(args, 0), &faceLandmarkPoint) == -1) {
return NULL;
}
if (PyObjC_PythonToObjC(@encode(CGRect), PyTuple_GetItem(args, 1), &faceBoundingBox)
if (PyObjC_PythonToObjC(@encode(CGRect), PyTuple_GET_ITEM(args, 1), &faceBoundingBox)
== -1) {
return NULL;
}
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GetItem(args, 2), &imageWidth)
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GET_ITEM(args, 2), &imageWidth)
== -1) {
return NULL;
}
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GetItem(args, 3), &imageHeight)
if (PyObjC_PythonToObjC(@encode(size_t), PyTuple_GET_ITEM(args, 3), &imageHeight)
== -1) {
return NULL;
}
Expand Down Expand Up @@ -158,13 +158,10 @@ static int mod_exec_module(PyObject* m)
if (@available(macOS 10.13, *)) {
/* pass */
} else {
if (PyDict_DelItemString(PyModule_GetDict(m),
"VNNormalizedFaceBoundingBoxPointForLandmarkPoint")
== -1) {
if (PyObject_DelAttrString(m, "VNNormalizedFaceBoundingBoxPointForLandmarkPoint") == -1) {
return -1;
}
if (PyDict_DelItemString(PyModule_GetDict(m), "VNImagePointForFaceLandmarkPoint")
== -1) {
if (PyObject_DelAttrString(m, "VNImagePointForFaceLandmarkPoint") == -1) {
return -1;
}
}
Expand All @@ -188,7 +185,7 @@ static int mod_exec_module(PyObject* m)
{
/* The code in this extension should be safe to use without the GIL */
.slot = Py_mod_gil,
.value = Py_MOD_GIL_USED,
.value = Py_MOD_GIL_NOT_USED,
},
#endif
{ /* Sentinel */
Expand Down
14 changes: 2 additions & 12 deletions pyobjc-framework-libdispatch/Modules/_libdispatch.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,8 @@
return NULL;
}

#if Py_MAJOR_VERSION == 3
py_memview = PyMemoryView_FromMemory(buffer, size, PyBuf_READ)
#else
Py_buffer bufinfo;

if (PyBuffer_FillInfo(&bufinfo, NULL, (void*)buffer, size, 1, PyBUF_SIMPLE) == -1) {
Py_DECREF(py_result);
return NULL;
}
py_memview = PyMemoryView_FromBuffer(&bufinfo);
#endif
if (py_memview == NULL)
if (py_memview == NULL)
{
Py_DECREF(py_result);
return NULL;
Expand Down Expand Up @@ -222,7 +212,7 @@ static int mod_exec_module(PyObject* m)
{
/* The code in this extension should be safe to use without the GIL */
.slot = Py_mod_gil,
.value = Py_MOD_GIL_USED,
.value = Py_MOD_GIL_NOT_USED,
},
#endif
{ /* Sentinel */
Expand Down

0 comments on commit 66c5899

Please sign in to comment.