Skip to content

Commit 1a80f6d

Browse files
authored
gh-114258: Update _ctypes and tokenize to use AC where it can be. (gh-160404)
1 parent 4553849 commit 1a80f6d

4 files changed

Lines changed: 75 additions & 24 deletions

File tree

‎Modules/_ctypes/_ctypes.c‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5513,15 +5513,16 @@ static PyMethodDef Simple_methods[] = {
55135513
{ NULL, NULL },
55145514
};
55155515

5516+
/*[clinic input]
5517+
@critical_section
5518+
_ctypes.Simple.__bool__ as Simple_bool
5519+
[clinic start generated code]*/
5520+
55165521
static int
5517-
Simple_bool(PyObject *op)
5522+
Simple_bool_impl(CDataObject *self)
5523+
/*[clinic end generated code: output=c4466ece6a99fe8b input=326a1c8b24d8918e]*/
55185524
{
5519-
int cmp;
5520-
CDataObject *self = _CDataObject_CAST(op);
5521-
Py_BEGIN_CRITICAL_SECTION(self);
5522-
cmp = memcmp(self->b_ptr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", self->b_size);
5523-
Py_END_CRITICAL_SECTION();
5524-
return cmp;
5525+
return memcmp(self->b_ptr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", self->b_size);
55255526
}
55265527

55275528
/* "%s(%s)" % (self.__class__.__name__, self.value) */
@@ -5988,14 +5989,16 @@ Pointer_subscript(PyObject *myself, PyObject *item)
59885989
}
59895990
}
59905991

5992+
/*[clinic input]
5993+
@critical_section
5994+
_ctypes._Pointer.__bool__ as Pointer_bool
5995+
[clinic start generated code]*/
5996+
59915997
static int
5992-
Pointer_bool(PyObject *self)
5998+
Pointer_bool_impl(PyObject *self)
5999+
/*[clinic end generated code: output=0139acaf4d395a69 input=672b8d35e7e0752d]*/
59936000
{
5994-
int res;
5995-
Py_BEGIN_CRITICAL_SECTION(self);
5996-
res = *(void **)_CDataObject_CAST(self)->b_ptr != NULL;
5997-
Py_END_CRITICAL_SECTION();
5998-
return res;
6001+
return *(void **)_CDataObject_CAST(self)->b_ptr != NULL;
59996002
}
60006003

60016004
static PyType_Slot pycpointer_slots[] = {

‎Modules/_ctypes/clinic/_ctypes.c.h‎

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Python/Python-tokenize.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ get_tokenize_state(PyObject *module) {
1919
get_tokenize_state(PyType_GetModuleByDef(type, &_tokenizemodule))
2020

2121
#include "pycore_runtime.h"
22-
#include "clinic/Python-tokenize.c.h"
2322

2423
/*[clinic input]
2524
module _tokenizer
@@ -39,6 +38,8 @@ typedef struct
3938
Py_ssize_t byte_col_offset_diff;
4039
} tokenizeriterobject;
4140

41+
#include "clinic/Python-tokenize.c.h"
42+
4243
/*[clinic input]
4344
@classmethod
4445
_tokenizer.tokenizeriter.__new__ as tokenizeriter_new
@@ -228,17 +229,21 @@ _get_col_offsets(tokenizeriterobject *it, const struct token *token,
228229
return 0;
229230
}
230231

232+
/*[clinic input]
233+
@critical_section
234+
_tokenizer.tokenizeriter.__next__ as tokenizeriter_next
235+
[clinic start generated code]*/
236+
231237
static PyObject *
232-
tokenizeriter_next(PyObject *op)
238+
tokenizeriter_next_impl(tokenizeriterobject *self)
239+
/*[clinic end generated code: output=745c9c646781ff45 input=66f70c965ba8ccfe]*/
233240
{
234-
tokenizeriterobject *it = (tokenizeriterobject*)op;
241+
tokenizeriterobject *it = self;
235242
PyObject* result = NULL;
236243

237-
Py_BEGIN_CRITICAL_SECTION(it);
238-
239244
if (it->done) {
240245
PyErr_SetString(PyExc_StopIteration, "EOF");
241-
goto unlock;
246+
return NULL;
242247
}
243248

244249
struct token token;
@@ -324,9 +329,6 @@ tokenizeriter_next(PyObject *op)
324329
if (type == ENDMARKER) {
325330
it->done = 1;
326331
}
327-
328-
unlock:;
329-
Py_END_CRITICAL_SECTION();
330332
return result;
331333
}
332334

‎Python/clinic/Python-tokenize.c.h‎

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)