Skip to content

Commit af0ee39

Browse files
committed
clinic
2 parents 8d2fb6d + bfc292a commit af0ee39

File tree

3 files changed

+176
-55
lines changed

3 files changed

+176
-55
lines changed

InternalDocs/jit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ When invoked, the executor jumps to the `tier2_dispatch:` label in
6666
executes the micro-ops. The body of this loop is a switch statement over
6767
the uops IDs, resembling the one used in the adaptive interpreter.
6868

69-
The swtich implementing the uops is in [`Python/executor_cases.c.h`](../Python/executor_cases.c.h),
69+
The switch implementing the uops is in [`Python/executor_cases.c.h`](../Python/executor_cases.c.h),
7070
which is generated by the build script
7171
[`Tools/cases_generator/tier2_generator.py`](../Tools/cases_generator/tier2_generator.py)
7272
from the bytecode definitions in

Modules/_ctypes/_ctypes.c

Lines changed: 60 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,16 +3007,17 @@ PyCData_nohash(PyObject *self)
30073007
}
30083008

30093009
/*[clinic input]
3010-
_ctypes.PyCData.__reduce__ as PyCData_reduce
3010+
@critical_section
3011+
_ctypes.PyCData.__reduce__
30113012
30123013
myself: self
30133014
cls: defining_class
30143015
/
30153016
[clinic start generated code]*/
30163017

30173018
static PyObject *
3018-
PyCData_reduce_impl(PyObject *myself, PyTypeObject *cls)
3019-
/*[clinic end generated code: output=1a025ccfdd8c935d input=34097a5226ea63c1]*/
3019+
_ctypes_PyCData___reduce___impl(PyObject *myself, PyTypeObject *cls)
3020+
/*[clinic end generated code: output=eaad97e111599294 input=6a464e1a1e2bbdbd]*/
30203021
{
30213022
CDataObject *self = _CDataObject_CAST(myself);
30223023

@@ -3037,33 +3038,33 @@ PyCData_reduce_impl(PyObject *myself, PyTypeObject *cls)
30373038
return NULL;
30383039
}
30393040
PyObject *bytes;
3040-
LOCK_PTR(self);
30413041
bytes = PyBytes_FromStringAndSize(self->b_ptr, self->b_size);
3042-
UNLOCK_PTR(self);
30433042
return Py_BuildValue("O(O(NN))", st->_unpickle, Py_TYPE(myself), dict,
30443043
bytes);
30453044
}
30463045

3046+
/*[clinic input]
3047+
@critical_section
3048+
_ctypes.PyCData.__setstate__
3049+
3050+
myself: self
3051+
dict: object(subclass_of="&PyDict_Type")
3052+
data: str(accept={str, robuffer}, zeroes=True)
3053+
/
3054+
[clinic start generated code]*/
3055+
30473056
static PyObject *
3048-
PyCData_setstate(PyObject *myself, PyObject *args)
3057+
_ctypes_PyCData___setstate___impl(PyObject *myself, PyObject *dict,
3058+
const char *data, Py_ssize_t data_length)
3059+
/*[clinic end generated code: output=8bd4c0a5b4f254bd input=124f5070258254c6]*/
30493060
{
3050-
void *data;
3051-
Py_ssize_t len;
3052-
int res;
3053-
PyObject *dict, *mydict;
30543061
CDataObject *self = _CDataObject_CAST(myself);
3055-
if (!PyArg_ParseTuple(args, "O!s#",
3056-
&PyDict_Type, &dict, &data, &len))
3057-
{
3058-
return NULL;
3062+
3063+
if (data_length > self->b_size) {
3064+
data_length = self->b_size;
30593065
}
3060-
if (len > self->b_size)
3061-
len = self->b_size;
3062-
// XXX Can we use locked_memcpy_to()?
3063-
LOCK_PTR(self);
3064-
memmove(self->b_ptr, data, len);
3065-
UNLOCK_PTR(self);
3066-
mydict = PyObject_GetAttrString(myself, "__dict__");
3066+
memmove(self->b_ptr, data, data_length);
3067+
PyObject *mydict = PyObject_GetAttrString(myself, "__dict__");
30673068
if (mydict == NULL) {
30683069
return NULL;
30693070
}
@@ -3074,26 +3075,30 @@ PyCData_setstate(PyObject *myself, PyObject *args)
30743075
Py_DECREF(mydict);
30753076
return NULL;
30763077
}
3077-
res = PyDict_Update(mydict, dict);
3078+
int res = PyDict_Update(mydict, dict);
30783079
Py_DECREF(mydict);
30793080
if (res == -1)
30803081
return NULL;
30813082
Py_RETURN_NONE;
30823083
}
30833084

3084-
/*
3085-
* default __ctypes_from_outparam__ method returns self.
3086-
*/
3085+
/*[clinic input]
3086+
_ctypes.PyCData.__ctypes_from_outparam__
3087+
3088+
default __ctypes_from_outparam__ method returns self.
3089+
[clinic start generated code]*/
3090+
30873091
static PyObject *
3088-
PyCData_from_outparam(PyObject *self, PyObject *args)
3092+
_ctypes_PyCData___ctypes_from_outparam___impl(PyObject *self)
3093+
/*[clinic end generated code: output=a7facc849097b549 input=910c5fec33e268c9]*/
30893094
{
30903095
return Py_NewRef(self);
30913096
}
30923097

30933098
static PyMethodDef PyCData_methods[] = {
3094-
{ "__ctypes_from_outparam__", PyCData_from_outparam, METH_NOARGS, },
3095-
PYCDATA_REDUCE_METHODDEF
3096-
{ "__setstate__", PyCData_setstate, METH_VARARGS, },
3099+
_CTYPES_PYCDATA___CTYPES_FROM_OUTPARAM___METHODDEF
3100+
_CTYPES_PYCDATA___SETSTATE___METHODDEF
3101+
_CTYPES_PYCDATA___REDUCE___METHODDEF
30973102
{ NULL, NULL },
30983103
};
30993104

@@ -5174,15 +5179,21 @@ PyCArrayType_from_ctype(ctypes_state *st, PyObject *itemtype, Py_ssize_t length)
51745179
*/
51755180

51765181
/*[clinic input]
5177-
class _ctypes.Simple "PyObject *" "clinic_state()->Simple_Type"
5182+
class _ctypes.Simple "CDataObject *" "clinic_state()->Simple_Type"
5183+
[clinic start generated code]*/
5184+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e0493451fecf8cd4]*/
5185+
5186+
/*[clinic input]
5187+
@critical_section
5188+
@setter
5189+
_ctypes.Simple.value
51785190
[clinic start generated code]*/
5179-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=016c476c7aa8b8a8]*/
51805191

51815192
static int
5182-
Simple_set_value(PyObject *op, PyObject *value, void *Py_UNUSED(ignored))
5193+
_ctypes_Simple_value_set_impl(CDataObject *self, PyObject *value)
5194+
/*[clinic end generated code: output=f267186118939863 input=977af9dc9e71e857]*/
51835195
{
51845196
PyObject *result;
5185-
CDataObject *self = _CDataObject_CAST(op);
51865197

51875198
if (value == NULL) {
51885199
PyErr_SetString(PyExc_TypeError,
@@ -5192,54 +5203,57 @@ Simple_set_value(PyObject *op, PyObject *value, void *Py_UNUSED(ignored))
51925203

51935204
ctypes_state *st = get_module_state_by_def(Py_TYPE(Py_TYPE(self)));
51945205
StgInfo *info;
5195-
if (PyStgInfo_FromObject(st, op, &info) < 0) {
5206+
if (PyStgInfo_FromObject(st, (PyObject *)self, &info) < 0) {
51965207
return -1;
51975208
}
51985209
assert(info); /* Cannot be NULL for CDataObject instances */
51995210
assert(info->setfunc);
52005211

5201-
LOCK_PTR(self);
52025212
result = info->setfunc(self->b_ptr, value, info->size);
5203-
UNLOCK_PTR(self);
52045213
if (!result)
52055214
return -1;
52065215

52075216
/* consumes the refcount the setfunc returns */
52085217
return KeepRef(self, 0, result);
52095218
}
52105219

5220+
52115221
static int
52125222
Simple_init(PyObject *self, PyObject *args, PyObject *kw)
52135223
{
52145224
PyObject *value = NULL;
52155225
if (!PyArg_UnpackTuple(args, "__init__", 0, 1, &value))
52165226
return -1;
52175227
if (value)
5218-
return Simple_set_value(self, value, NULL);
5228+
return _ctypes_Simple_value_set(self, value, NULL);
52195229
return 0;
52205230
}
52215231

5232+
5233+
/*[clinic input]
5234+
@critical_section
5235+
@getter
5236+
_ctypes.Simple.value
5237+
[clinic start generated code]*/
5238+
52225239
static PyObject *
5223-
Simple_get_value(PyObject *op, void *Py_UNUSED(ignored))
5240+
_ctypes_Simple_value_get_impl(CDataObject *self)
5241+
/*[clinic end generated code: output=ce5a26570830a243 input=3ed3f735cec89282]*/
52245242
{
5225-
CDataObject *self = _CDataObject_CAST(op);
52265243
ctypes_state *st = get_module_state_by_def(Py_TYPE(Py_TYPE(self)));
52275244
StgInfo *info;
5228-
if (PyStgInfo_FromObject(st, op, &info) < 0) {
5245+
if (PyStgInfo_FromObject(st, (PyObject *)self, &info) < 0) {
52295246
return NULL;
52305247
}
52315248
assert(info); /* Cannot be NULL for CDataObject instances */
52325249
assert(info->getfunc);
52335250
PyObject *res;
5234-
LOCK_PTR(self);
52355251
res = info->getfunc(self->b_ptr, self->b_size);
5236-
UNLOCK_PTR(self);
52375252
return res;
52385253
}
52395254

52405255
static PyGetSetDef Simple_getsets[] = {
5241-
{ "value", Simple_get_value, Simple_set_value,
5242-
"current value", NULL },
5256+
_CTYPES_SIMPLE_VALUE_GETSETDEF
52435257
{ NULL, NULL }
52445258
};
52455259

@@ -5260,7 +5274,7 @@ Simple_from_outparm_impl(PyObject *self, PyTypeObject *cls)
52605274
return Py_NewRef(self);
52615275
}
52625276
/* call stginfo->getfunc */
5263-
return Simple_get_value(self, NULL);
5277+
return _ctypes_Simple_value_get(self, NULL);
52645278
}
52655279

52665280
static PyMethodDef Simple_methods[] = {
@@ -5291,7 +5305,7 @@ Simple_repr(PyObject *self)
52915305
Py_TYPE(self)->tp_name, self);
52925306
}
52935307

5294-
val = Simple_get_value(self, NULL);
5308+
val = _ctypes_Simple_value_get(self, NULL);
52955309
if (val == NULL)
52965310
return NULL;
52975311

Modules/_ctypes/clinic/_ctypes.c.h

Lines changed: 115 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)