gh-114258: Update _ctypes and tokenize to use AC where it can be. (gh-160404)

This commit is contained in:
Donghee Na authored and GitHub committed 2026-10-23 02:42:16 +00:00
1 parent 45538495be
commit 1a80f6d454
4 files changed
+77 -26

No files matched your search

+16 -13
View File
@@ -5513,15 +5513,16 @@ static PyMethodDef Simple_methods[] = {
{ NULL, NULL },
};
/*[clinic input]
@critical_section
_ctypes.Simple.__bool__ as Simple_bool
[clinic start generated code]*/
static int
Simple_bool(PyObject *op)
Simple_bool_impl(CDataObject *self)
/*[clinic end generated code: output=c4466ece6a99fe8b input=326a1c8b24d8918e]*/
{
int cmp;
CDataObject *self = _CDataObject_CAST(op);
Py_BEGIN_CRITICAL_SECTION(self);
cmp = memcmp(self->b_ptr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", self->b_size);
Py_END_CRITICAL_SECTION();
return cmp;
return memcmp(self->b_ptr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", self->b_size);
}
/* "%s(%s)" % (self.__class__.__name__, self.value) */
@@ -5988,14 +5989,16 @@ Pointer_subscript(PyObject *myself, PyObject *item)
}
}
/*[clinic input]
@critical_section
_ctypes._Pointer.__bool__ as Pointer_bool
[clinic start generated code]*/
static int
Pointer_bool(PyObject *self)
Pointer_bool_impl(PyObject *self)
/*[clinic end generated code: output=0139acaf4d395a69 input=672b8d35e7e0752d]*/
{
int res;
Py_BEGIN_CRITICAL_SECTION(self);
res = *(void **)_CDataObject_CAST(self)->b_ptr != NULL;
Py_END_CRITICAL_SECTION();
return res;
return *(void **)_CDataObject_CAST(self)->b_ptr != NULL;
}
static PyType_Slot pycpointer_slots[] = {
+31 -1
View File
@@ -865,6 +865,21 @@ Simple_from_outparm(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py
return Simple_from_outparm_impl(self, cls);
}
static int
Simple_bool_impl(CDataObject *self);
static int
Simple_bool(PyObject *self)
{
int return_value = -1;
Py_BEGIN_CRITICAL_SECTION(self);
return_value = Simple_bool_impl((CDataObject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
}
static PyObject *
Pointer_item_impl(PyObject *myself, Py_ssize_t index);
@@ -894,6 +909,21 @@ Pointer_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
return return_value;
}
static int
Pointer_bool_impl(PyObject *self);
static int
Pointer_bool(PyObject *self)
{
int return_value = -1;
Py_BEGIN_CRITICAL_SECTION(self);
return_value = Pointer_bool_impl(self);
Py_END_CRITICAL_SECTION();
return return_value;
}
#define _CTYPES_CTYPE_TYPE___POINTER_TYPE___GETSETDEF {"__pointer_type__", (getter)_ctypes_CType_Type___pointer_type___get, (setter)_ctypes_CType_Type___pointer_type___set, NULL},
#define _CTYPES_PYCARRAYTYPE_TYPE_RAW_GETSETDEF {"raw", (getter)_ctypes_PyCArrayType_Type_raw_get, (setter)_ctypes_PyCArrayType_Type_raw_set, NULL},
@@ -908,4 +938,4 @@ Pointer_ass_item(PyObject *myself, Py_ssize_t index, PyObject *value)
#define _CTYPES_SIMPLE_VALUE_GETSETDEF {"value", (getter)_ctypes_Simple_value_get, (setter)_ctypes_Simple_value_set, NULL},
/*[clinic end generated code: output=8fc24edc31ab60b5 input=a9049054013a1b77]*/
/*[clinic end generated code: output=5d9dd4bbae13cfca input=a9049054013a1b77]*/
+13 -11
View File
@@ -19,7 +19,6 @@ get_tokenize_state(PyObject *module) {
get_tokenize_state(PyType_GetModuleByDef(type, &_tokenizemodule))
#include "pycore_runtime.h"
#include "clinic/Python-tokenize.c.h"
/*[clinic input]
module _tokenizer
@@ -39,6 +38,8 @@ typedef struct
Py_ssize_t byte_col_offset_diff;
} tokenizeriterobject;
#include "clinic/Python-tokenize.c.h"
/*[clinic input]
@classmethod
_tokenizer.tokenizeriter.__new__ as tokenizeriter_new
@@ -228,17 +229,21 @@ _get_col_offsets(tokenizeriterobject *it, const struct token *token,
return 0;
}
static PyObject *
tokenizeriter_next(PyObject *op)
{
tokenizeriterobject *it = (tokenizeriterobject*)op;
PyObject* result = NULL;
/*[clinic input]
@critical_section
_tokenizer.tokenizeriter.__next__ as tokenizeriter_next
[clinic start generated code]*/
Py_BEGIN_CRITICAL_SECTION(it);
static PyObject *
tokenizeriter_next_impl(tokenizeriterobject *self)
/*[clinic end generated code: output=745c9c646781ff45 input=66f70c965ba8ccfe]*/
{
tokenizeriterobject *it = self;
PyObject* result = NULL;
if (it->done) {
PyErr_SetString(PyExc_StopIteration, "EOF");
goto unlock;
return NULL;
}
struct token token;
@@ -324,9 +329,6 @@ exit:
if (type == ENDMARKER) {
it->done = 1;
}
unlock:;
Py_END_CRITICAL_SECTION();
return result;
}
+17 -1
View File
@@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
#include "pycore_unicodeobject.h" // _PyUnicode_AsUTF8NoNUL()
@@ -79,4 +80,19 @@ skip_optional_kwonly:
exit:
return return_value;
}
/*[clinic end generated code: output=f9091945b96e09b7 input=a9049054013a1b77]*/
static PyObject *
tokenizeriter_next_impl(tokenizeriterobject *self);
static PyObject *
tokenizeriter_next(PyObject *self)
{
PyObject *return_value = NULL;
Py_BEGIN_CRITICAL_SECTION(self);
return_value = tokenizeriter_next_impl((tokenizeriterobject *)self);
Py_END_CRITICAL_SECTION();
return return_value;
}
/*[clinic end generated code: output=67cc510ef85272ba input=a9049054013a1b77]*/