8000 Stackless issue #294: convert Stackless type definitions to new syntax · stackless-dev/stackless@97af706 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 97af706

Browse files
authored
Stackless issue #294: convert Stackless type definitions to new syntax
Convert initializers for static type objects to use C99 designator syntax. This way the code is more robust against changes of PyTypeObject.
1 parent 1aefc88 commit 97af706

File tree

8 files changed

+110
-369
lines changed

8 files changed

+110
-369
lines changed

Stackless/core/cframeobject.c

Lines changed: 18 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -321,44 +321,18 @@ static PyMemberDef cframe_memberlist[] = {
321321

322322
PyTypeObject PyCFrame_Type = {
323323
PyVarObject_HEAD_INIT(&PyType_Type, 0)
324-
"_stackless.cframe",
325-
sizeof(PyCFrameObject),
326-
0,
327-
(destructor)cframe_dealloc, /* tp_dealloc */
328-
0, /* tp_print */
329-
0, /* tp_getattr */
330-
0, /* tp_setattr */
331-
0, /* tp_compare */
332-
0, /* tp_repr */
333-
0, /* tp_as_number */
334-
0, /* tp_as_sequence */
335-
0, /* tp_as_mapping */
336-
0, /* tp_hash */
337-
0, /* tp_call */
338-
0, /* tp_str */
339-
PyObject_GenericGetAttr, /* tp_getattro */
340-
PyObject_GenericSetAttr, /* tp_setattro */
341-
0, /* tp_as_buffer */
342-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
343-
0, /* tp_doc */
344-
(traverseproc)cframe_traverse, /* tp_traverse */
345-
(inquiry) cframe_clear, /* tp_clear */
346-
0, /* tp_richcompare */
347-
0, /* tp_weaklistoffset */
348-
0, /* tp_iter */
349-
0, /* tp_iternext */
350-
cframe_methods, /* tp_methods */
351-
cframe_memberlist, /* tp_members */
352-
0, /* tp_getset */
353-
0, /* tp_base */
354-
0, /* tp_dict */
355-
0, /* tp_descr_get */
356-
0, /* tp_descr_set */
357-
0, /* tp_dictoffset */
358-
0, /* tp_init */
359-
0, /* tp_alloc */
360-
cframe_new, /* tp_new */
361-
PyObject_ 57A7 GC_Del, /* tp_free */
324+
.tp_name = "_stackless.cframe",
325+
.tp_basicsize = sizeof(PyCFrameObject),
326+
.tp_dealloc = (destructor)cframe_dealloc,
327+
.tp_getattro = PyObject_GenericGetAttr,
328+
.tp_setattro = PyObject_GenericSetAttr,
329+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
330+
.tp_traverse = (traverseproc)cframe_traverse,
331+
.tp_clear = (inquiry) cframe_clear,
332+
.tp_methods = cframe_methods,
333+
.tp_members = cframe_memberlist,
334+
.tp_new = cframe_new,
335+
.tp_free = PyObject_GC_Del
362336
};
363337

364338
int slp_init_cframetype(void)
@@ -425,35 +399,12 @@ extension function written in C in a pickle.\n\
425399

426400
PyTypeObject PyStacklessFunctionDeclaration_Type = {
427401
PyVarObject_HEAD_INIT(&PyType_Type, 0)
428-
"_stackless.FunctionDeclaration", /*tp_name*/
429-
sizeof(PyStacklessFunctionDeclarationObject), /*tp_basicsize*/
430-
0, /*tp_itemsize*/
431-
/* methods */
432-
0, /* tp_dealloc */
433-
0, /* tp_print */
434-
0, /* tp_getattr */
435-
0, /* tp_setattr */
436-
0, /* tp_compare */
437-
0, /* tp_repr */
438-
0, /* tp_as_number */
439-
0, /* tp_as_sequence */
440-
0, /* tp_as_mapping */
441-
0, /* tp_hash */
442-
0, /* tp_call */
443-
0, /* tp_str */
444-
0, /* tp_getattro */
445-
0, /* tp_setattro */
446-
0, /* tp_as_buffer */
447-
Py_TPFLAGS_DEFAULT, /* tp_flags */
448-
PyStacklessFunctionDeclaration_Type__doc__, /* tp_doc */
449-
0, /* tp_traverse */
450-
0, /* tp_clear */
451-
0, /* tp_richcompare */
452-
0, /* tp_weaklistoffset */
453-
0, /* tp_iter */
454-
0, /* tp_iternext */
455-
function_declaration_methods, /* tp_methods */
456-
function_declaration_memberlist, /* tp_members */
402+
.tp_name = "_stackless.FunctionDeclaration",
403+
.tp_basicsize = sizeof(PyStacklessFunctionDeclarationObject),
404+
.tp_flags = Py_TPFLAGS_DEFAULT,
405+
.tp_doc = PyStacklessFunctionDeclaration_Type__doc__,
406+
.tp_methods = function_declaration_methods,
407+
.tp_members = function_declaration_memberlist
457408
};
458409

459410
static

Stackless/core/stacklesseval.c

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -186,34 +186,16 @@ cstack_str(PyObject *o)
186186

187187
PyTypeObject PyCStack_Type = {
188188
PyVarObject_HEAD_INIT(&PyType_Type, 0)
189-
"_stackless.cstack",
190-
sizeof(PyCStackObject),
191-
sizeof(PyObject *),
192-
(destructor)cstack_dealloc, /* tp_dealloc */
193-
0, /* tp_print */
194-
0, /* tp_getattr */
195-
0, /* tp_setattr */
196-
0, /* tp_compare */
197-
0, /* tp_repr */
198-
0, /* tp_as_number */
199-
0, /* tp_as_sequence */
200-
0, /* tp_as_mapping */
201-
0, /* tp_hash */
202-
0, /* tp_call */
203-
(reprfunc)cstack_str, /* tp_str */
204-
PyObject_GenericGetAttr, /* tp_getattro */
205-
PyObject_GenericSetAttr, /* tp_setattro */
206-
0, /* tp_as_buffer */
207-
Py_TPFLAGS_DEFAULT, /* tp_flags */
208-
cstack_doc, /* tp_doc */
209-
0, /* tp_traverse */
210-
0, /* tp_clear */
211-
0, /* tp_richcompare */
212-
0, /* tp_weaklistoffset */
213-
0, /* tp_iter */
214-
0, /* tp_iternext */
215-
0, /* tp_methods */
216-
cstack_members, /* tp_members */
189+
.tp_name = "_stackless.cstack",
190+
.tp_basicsize = sizeof(PyCStackObject),
191+
.tp_itemsize = sizeof(PyObject *),
192+
.tp_dealloc = (destructor)cstack_dealloc,
193+
.tp_str = (reprfunc)cstack_str,
194+
.tp_getattro = PyObject_GenericGetAttr,
195+
.tp_setattro = PyObject_GenericSetAttr,
196+
.tp_flags = Py_TPFLAGS_DEFAULT,
197+
.tp_doc = cstack_doc,
198+
.tp_members = cstack_members
217199
};
218200

219201

@@ -970,19 +952,9 @@ static void unwind_dealloc(PyObject *op) {
970952

971953
static PyTypeObject PyUnwindToken_Type = {
972954
PyVarObject_HEAD_INIT(&PyUnwindToken_Type, 0)
973-
"UnwindToken",
974-
0,
975-
0,
976-
(destructor)unwind_dealloc, /*tp_dealloc*/ /*should never be called*/
977-
0, /*tp_print*/
978-
0, /*tp_getattr*/
979-
0, /*tp_setattr*/
980-
0, /*tp_compare*/
981-
(reprfunc)unwind_repr, /*tp_repr*/
982-
0, /*tp_as_number*/
983-
0, /*tp_as_sequence*/
984-
0, /*tp_as_mapping*/
985-
0, /*tp_hash */
955+
.tp_name = "UnwindToken",
956+
.tp_dealloc = (destructor)unwind_dealloc, /*should never be called*/
957+
.tp_repr = (reprfunc)unwind_repr
986958
};
987959

988960
static PyUnwindObject unwind_token = {

Stackless/module/_teststackless.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -269,46 +269,11 @@ static PyTypeObject SoftSwitchableDemo_Type = {
269269
/* The ob_type field must be initialized in the module init function
270270
* to be portable to Windows without using C++. */
271271
PyVarObject_HEAD_INIT(NULL, 0)
272-
"_teststackless.SoftSwitchableDemo", /*tp_name*/
273-
sizeof(SoftSwitchableDemoObject), /*tp_basicsize*/
274-
0, /*tp_itemsize*/
275-
/* methods */
276-
0, /*tp_dealloc*/
277-
0, /*tp_print*/
278-
0, /*tp_getattr*/
279-
0, /*tp_setattr*/
280-
0, /*tp_reserved*/
281-
0, /*tp_repr*/
282-
0, /*tp_as_number*/
283-
0, /*tp_as_sequence*/
284-
0, /*tp_as_mapping*/
285-
0, /*tp_hash*/
286-
0, /*tp_call*/
287-
0, /*tp_str*/
288-
0, /*tp_getattro*/
289-
0, /*tp_setattro*/
290-
0, /*tp_as_buffer*/
291-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
292-
0, /*tp_doc*/
293-
0, /*tp_traverse*/
294-
0, /*tp_clear*/
295-
0, /*tp_richcompare*/
296-
0, /*tp_weaklistoffset*/
297-
0, /*tp_iter*/
298-
0, /*tp_iternext*/
299-
SoftSwitchableDemo_methods, /*tp_methods*/
300-
0, /*tp_members*/
301-
0, /*tp_getset*/
302-
0, /*tp_base*/
303-
0, /*tp_dict*/
304-
0, /*tp_descr_get*/
305-
0, /*tp_descr_set*/
306-
0, /*tp_dictoffset*/
307-
0, /*tp_init*/
308-
0, /*tp_alloc*/
309-
PyType_GenericNew, /*tp_new*/
310-
0, /*tp_free*/
311-
0, /*tp_is_gc*/
272+
.tp_name = "_teststackless.SoftSwitchableDemo",
273+
.tp_basicsize = sizeof(SoftSwitchableDemoObject),
274+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
275+
.tp_methods = SoftSwitchableDemo_methods,
276+
.tp_new = PyType_GenericNew,
312277
};
313278
/* --------------------------------------------------------------------- */
314279

Stackless/module/channelobject.c

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,47 +1218,26 @@ static PyMappingMethods channel_as_mapping = {
12181218

12191219
PyTypeObject PyChannel_Type = {
12201220
PyVarObject_HEAD_INIT(&PyType_Type, 0)
1221-
"_stackless.channel",
1222-
sizeof(PyChannelObject),
1223-
0,
1224-
(destructor)channel_dealloc, /* tp_dealloc */
1225-
0, /* tp_print */
1226-
0, /* tp_getattr */
1227-
0, /* tp_setattr */
1228-
0, /* tp_compare */
1229-
0, /* tp_repr */
1230-
0, /* tp_as_number */
1231-
0, /* tp_as_sequence */
1232-
SLP_TP_AS_MAPPING(channel_as_mapping), /* tp_as_mapping */
1233-
0, /* tp_hash */
1234-
0, /* tp_call */
1235-
0, /* tp_str */
1236-
PyObject_GenericGetAttr, /* tp_getattro */
1237-
PyObject_GenericSetAttr, /* tp_setattro */
1238-
0, /* tp_as_buffer */
1239-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1221+
.tp_name = "_stackless.channel",
1222+
.tp_basicsize = sizeof(PyChannelObject),
1223+
.tp_dealloc = (destructor)channel_dealloc,
1224+
.tp_as_mapping = SLP_TP_AS_MAPPING(channel_as_mapping),
1225+
.tp_getattro = PyObject_GenericGetAttr,
1226+
.tp_setattro = PyObject_GenericSetAttr,
1227+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
12401228
Py_TPFLAGS_BASETYPE |
1241-
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION, /* tp_flags */
1242-
channel__doc__, /* tp_doc */
1243-
(traverseproc)channel_traverse, /* tp_traverse */
1244-
(inquiry) channel_clear, /* tp_clear */
1245-
0, /* tp_richcompare */
1246-
offsetof(PyChannelObject, chan_weakreflist),
1247-
/* tp_weaklistoffset */
1248-
(getiterfunc)channel_getiter, /* tp_iter */
1249-
(iternextfunc)channel_iternext, /* tp_iternext */
1250-
channel_methods, /* tp_methods */
1251-
channel_members, /* tp_members */
1252-
channel_getsetlist, /* tp_getset */
1253-
0, /* tp_base */
1254-
0, /* tp_dict */
1255-
0, /* tp_descr_get */
1256-
0, /* tp_descr_set */
1257-
0, /* tp_dictoffset */
1258-
0, /* tp_init */
1259-
0, /* tp_alloc */
1260-
channel_new, /* tp_new */
1261-
PyObject_GC_Del, /* tp_free */
1229+
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION,
1230+
.tp_doc = channel__doc__,
1231+
.tp_traverse = (traverseproc)channel_traverse,
1232+
.tp_clear = (inquiry) channel_clear,
1233+
.tp_weaklistoffset = offsetof(PyChannelObject, chan_weakreflist),
1234+
.tp_iter = (getiterfunc)channel_getiter,
1235+
.tp_iternext = (iternextfunc)channel_iternext,
1236+
.tp_methods = channel_methods,
1237+
.tp_members = channel_members,
1238+
.tp_getset = channel_getsetlist,
1239+
.tp_new = channel_new,
1240+
.tp_free = PyObject_GC_Del,
12621241
};
12631242

12641243
#endif

Stackless/module/scheduling.c

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -276,44 +276,19 @@ t.run() # let the bomb explode");
276276

277277
PyTypeObject PyBomb_Type = {
278278
PyVarObject_HEAD_INIT(&PyType_Type, 0)
279-
"_stackless.bomb",
280-
sizeof(PyBombObject),
281-
0,
282-
(destructor)bomb_dealloc, /* tp_dealloc */
283-
0, /* tp_print */
284-
0, /* tp_getattr */
285-
0, /* tp_setattr */
286-
0, /* tp_compare */
287-
0, /* tp_repr */
288-
0, /* tp_as_number */
289-
0, /* tp_as_sequence */
290-
0, /* tp_as_mapping */
291-
0, /* tp_hash */
292-
0, /* tp_call */
293-
0, /* tp_str */
294-
PyObject_GenericGetAttr, /* tp_getattro */
295-
PyObject_GenericSetAttr, /* tp_setattro */
296-
0, /* tp_as_buffer */
297-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
298-
bomb__doc__, /* tp_doc */
299-
(traverseproc)bomb_traverse, /* tp_traverse */
300-
(inquiry) bomb_clear, /* tp_clear */
301-
0, /* tp_richcompare */
302-
0, /* tp_weaklistoffset */
303-
0, /* tp_iter */
304-
0, /* tp_iternext */
305-
bomb_methods, /* tp_methods */
306-
bomb_members, /* tp_members */
307-
0, /* tp_getset */
308-
0, /* tp_base */
309-
0, /* tp_dict */
310-
0, /* tp_descr_get */
311-
0, /* tp_descr_set */
312-
0, /* tp_dictoffset */
313-
0, /* tp_init */
314-
0, /* tp_alloc */
315-
bomb_new, /* tp_new */
316-
PyObject_GC_Del, /* tp_free */
279+
.tp_name = "_stackless.bomb",
280+
.tp_basicsize = sizeof(PyBombObject),
281+
.tp_dealloc = (destructor)bomb_dealloc,
282+
.tp_getattro = PyObject_GenericGetAttr,
283+
.tp_setattro = PyObject_GenericSetAttr,
284+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
285+
.tp_doc = bomb__doc__,
286+
.tp_traverse = (traverseproc)bomb_traverse,
287+
.tp_clear = (inquiry) bomb_clear,
288+
.tp_methods = bomb_methods,
289+
.tp_members = bomb_members,
290+
.tp_new = bomb_new,
291+
.tp_free = PyObject_GC_Del,
317292
};
318293

319294
int

0 commit comments

Comments
 (0)
0