Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96cebde

Browse files
committed
Added PEP253 support to most Carbon modules. This isn't complete yet:
some of the more compilcated cases (CF, Res) haven't been done yet. Also, various types should inherit from each other (anything with an as_Resource method should be a Resource subtype, the CF types should become one family).
1 parent 99899b9 commit 96cebde

43 files changed

Lines changed: 1592 additions & 534 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Mac/Modules/ae/_AEmodule.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,24 @@ static PyGetSetDef AEDesc_getsetlist[] = {
869869
#define AEDesc_repr NULL
870870

871871
#define AEDesc_hash NULL
872+
#define AEDesc_tp_init 0
873+
874+
#define AEDesc_tp_alloc PyType_GenericAlloc
875+
876+
static PyObject *AEDesc_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
877+
{
878+
PyObject *self;
879+
AEDesc itself;
880+
char *kw[] = {"itself", 0};
881+
882+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, AEDesc_Convert, &itself)) return NULL;
883+
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
884+
((AEDescObject *)self)->ob_itself = itself;
885+
return self;
886+
}
887+
888+
#define AEDesc_tp_free PyObject_Del
889+
872890

873891
PyTypeObject AEDesc_Type = {
874892
PyObject_HEAD_INIT(NULL)
@@ -891,19 +909,27 @@ PyTypeObject AEDesc_Type = {
891909
0, /*tp_str*/
892910
PyObject_GenericGetAttr, /*tp_getattro*/
893911
PyObject_GenericSetAttr, /*tp_setattro */
894-
0, /*outputHook_tp_as_buffer*/
895-
0, /*outputHook_tp_flags*/
896-
0, /*outputHook_tp_doc*/
897-
0, /*outputHook_tp_traverse*/
898-
0, /*outputHook_tp_clear*/
899-
0, /*outputHook_tp_richcompare*/
900-
0, /*outputHook_tp_weaklistoffset*/
901-
0, /*outputHook_tp_iter*/
902-
0, /*outputHook_tp_iternext*/
912+
0, /*tp_as_buffer*/
913+
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
914+
0, /*tp_doc*/
915+
0, /*tp_traverse*/
916+
0, /*tp_clear*/
917+
0, /*tp_richcompare*/
918+
0, /*tp_weaklistoffset*/
919+
0, /*tp_iter*/
920+
0, /*tp_iternext*/
903921
AEDesc_methods, /* tp_methods */
904-
0, /*outputHook_tp_members*/
922+
0, /*tp_members*/
905923
AEDesc_getsetlist, /*tp_getset*/
906-
0, /*outputHook_tp_base*/
924+
0, /*tp_base*/
925+
0, /*tp_dict*/
926+
0, /*tp_descr_get*/
927+
0, /*tp_descr_set*/
928+
0, /*tp_dictoffset*/
929+
AEDesc_tp_init, /* tp_init */
930+
AEDesc_tp_alloc, /* tp_alloc */
931+
AEDesc_tp_new, /* tp_new */
932+
AEDesc_tp_free, /* tp_free */
907933
};
908934

909935
/* --------------------- End object type AEDesc --------------------- */
@@ -1429,8 +1455,10 @@ void init_AE(void)
14291455
return;
14301456
AEDesc_Type.ob_type = &PyType_Type;
14311457
Py_INCREF(&AEDesc_Type);
1432-
if (PyDict_SetItemString(d, "AEDescType", (PyObject *)&AEDesc_Type) != 0)
1433-
Py_FatalError("can't initialize AEDescType");
1458+
PyModule_AddObject(m, "AEDesc", (PyObject *)&AEDesc_Type);
1459+
/* Backward-compatible name */
1460+
Py_INCREF(&AEDesc_Type);
1461+
PyModule_AddObject(m, "AEDescType", (PyObject *)&AEDesc_Type);
14341462
}
14351463

14361464
/* ========================= End module _AE ========================= */

Mac/Modules/ae/aesupport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def passInput(self, name):
174174

175175
module = MacModule('_AE', 'AE', includestuff, finalstuff, initstuff)
176176

177-
class AEDescDefinition(PEP252Mixin, GlobalObjectDefinition):
177+
class AEDescDefinition(PEP253Mixin, GlobalObjectDefinition):
178178
getsetlist = [(
179179
'type',
180180
'return PyMac_BuildOSType(self->ob_itself.descriptorType);',

Mac/Modules/alias/_Aliasmodule.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,30 @@ static PyMethodDef AliasObj_methods[] = {
9797

9898
#define AliasObj_getsetlist NULL
9999

100+
100101
#define AliasObj_compare NULL
101102

102103
#define AliasObj_repr NULL
103104

104105
#define AliasObj_hash NULL
106+
#define AliasObj_tp_init 0
107+
108+
#define AliasObj_tp_alloc PyType_GenericAlloc
109+
110+
static PyObject *AliasObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
111+
{
112+
PyObject *self;
113+
AliasHandle itself;
114+
char *kw[] = {"itself", 0};
115+
116+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, AliasObj_Convert, &itself)) return NULL;
117+
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
118+
((AliasObject *)self)->ob_itself = itself;
119+
return self;
120+
}
121+
122+
#define AliasObj_tp_free PyObject_Del
123+
105124

106125
PyTypeObject Alias_Type = {
107126
PyObject_HEAD_INIT(NULL)
@@ -124,19 +143,27 @@ PyTypeObject Alias_Type = {
124143
0, /*tp_str*/
125144
PyObject_GenericGetAttr, /*tp_getattro*/
126145
PyObject_GenericSetAttr, /*tp_setattro */
127-
0, /*outputHook_tp_as_buffer*/
128-
0, /*outputHook_tp_flags*/
129-
0, /*outputHook_tp_doc*/
130-
0, /*outputHook_tp_traverse*/
131-
0, /*outputHook_tp_clear*/
132-
0, /*outputHook_tp_richcompare*/
133-
0, /*outputHook_tp_weaklistoffset*/
134-
0, /*outputHook_tp_iter*/
135-
0, /*outputHook_tp_iternext*/
146+
0, /*tp_as_buffer*/
147+
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
148+
0, /*tp_doc*/
149+
0, /*tp_traverse*/
150+
0, /*tp_clear*/
151+
0, /*tp_richcompare*/
152+
0, /*tp_weaklistoffset*/
153+
0, /*tp_iter*/
154+
0, /*tp_iternext*/
136155
AliasObj_methods, /* tp_methods */
137-
0, /*outputHook_tp_members*/
156+
0, /*tp_members*/
138157
AliasObj_getsetlist, /*tp_getset*/
139-
0, /*outputHook_tp_base*/
158+
0, /*tp_base*/
159+
0, /*tp_dict*/
160+
0, /*tp_descr_get*/
161+
0, /*tp_descr_set*/
162+
0, /*tp_dictoffset*/
163+
AliasObj_tp_init, /* tp_init */
164+
AliasObj_tp_alloc, /* tp_alloc */
165+
AliasObj_tp_new, /* tp_new */
166+
AliasObj_tp_free, /* tp_free */
140167
};
141168

142169
/* --------------------- End object type Alias ---------------------- */
@@ -665,8 +692,10 @@ void init_Alias(void)
665692
return;
666693
Alias_Type.ob_type = &PyType_Type;
667694
Py_INCREF(&Alias_Type);
668-
if (PyDict_SetItemString(d, "AliasType", (PyObject *)&Alias_Type) != 0)
669-
Py_FatalError("can't initialize AliasType");
695+
PyModule_AddObject(m, "Alias", (PyObject *)&Alias_Type);
696+
/* Backward-compatible name */
697+
Py_INCREF(&Alias_Type);
698+
PyModule_AddObject(m, "AliasType", (PyObject *)&Alias_Type);
670699
}
671700

672701
/* ======================= End module _Alias ======================== */

Mac/Modules/alias/aliassupport.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class VarReverseInputBufferType(ReverseInputBufferMixin, VarInputBufferType):
7272
# Create the generator groups and link them
7373
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
7474

75-
class AliasDefinition(PEP252Mixin, GlobalObjectDefinition):
75+
class AliasDefinition(PEP253Mixin, GlobalObjectDefinition):
76+
# XXXX Should inherit from resource?
7677

7778
def outputCheckNewArg(self):
7879
Output("if (itself == NULL) return PyMac_Error(resNotFound);")

Mac/Modules/app/_Appmodule.c

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,30 @@ static PyMethodDef ThemeDrawingStateObj_methods[] = {
115115

116116
#define ThemeDrawingStateObj_getsetlist NULL
117117

118+
118119
#define ThemeDrawingStateObj_compare NULL
119120

120121
#define ThemeDrawingStateObj_repr NULL
121122

122123
#define ThemeDrawingStateObj_hash NULL
124+
#define ThemeDrawingStateObj_tp_init 0
125+
126+
#define ThemeDrawingStateObj_tp_alloc PyType_GenericAlloc
127+
128+
static PyObject *ThemeDrawingStateObj_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
129+
{
130+
PyObject *self;
131+
ThemeDrawingState itself;
132+
char *kw[] = {"itself", 0};
133+
134+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kw, ThemeDrawingStateObj_Convert, &itself)) return NULL;
135+
if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;
136+
((ThemeDrawingStateObject *)self)->ob_itself = itself;
137+
return self;
138+
}
139+
140+
#define ThemeDrawingStateObj_tp_free PyObject_Del
141+
123142

124143
PyTypeObject ThemeDrawingState_Type = {
125144
PyObject_HEAD_INIT(NULL)
@@ -142,19 +161,27 @@ PyTypeObject ThemeDrawingState_Type = {
142161
0, /*tp_str*/
143162
PyObject_GenericGetAttr, /*tp_getattro*/
144163
PyObject_GenericSetAttr, /*tp_setattro */
145-
0, /*outputHook_tp_as_buffer*/
146-
0, /*outputHook_tp_flags*/
147-
0, /*outputHook_tp_doc*/
148-
0, /*outputHook_tp_traverse*/
149-
0, /*outputHook_tp_clear*/
150-
0, /*outputHook_tp_richcompare*/
151-
0, /*outputHook_tp_weaklistoffset*/
152-
0, /*outputHook_tp_iter*/
153-
0, /*outputHook_tp_iternext*/
164+
0, /*tp_as_buffer*/
165+
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /* tp_flags */
166+
0, /*tp_doc*/
167+
0, /*tp_traverse*/
168+
0, /*tp_clear*/
169+
0, /*tp_richcompare*/
170+
0, /*tp_weaklistoffset*/
171+
0, /*tp_iter*/
172+
0, /*tp_iternext*/
154173
ThemeDrawingStateObj_methods, /* tp_methods */
155-
0, /*outputHook_tp_members*/
174+
0, /*tp_members*/
156175
ThemeDrawingStateObj_getsetlist, /*tp_getset*/
157-
0, /*outputHook_tp_base*/
176+
0, /*tp_base*/
177+
0, /*tp_dict*/
178+
0, /*tp_descr_get*/
179+
0, /*tp_descr_set*/
180+
0, /*tp_dictoffset*/
181+
ThemeDrawingStateObj_tp_init, /* tp_init */
182+
ThemeDrawingStateObj_tp_alloc, /* tp_alloc */
183+
ThemeDrawingStateObj_tp_new, /* tp_new */
184+
ThemeDrawingStateObj_tp_free, /* tp_free */
158185
};
159186

160187
/* --------------- End object type ThemeDrawingState ---------------- */
@@ -1822,8 +1849,10 @@ void init_App(void)
18221849
return;
18231850
ThemeDrawingState_Type.ob_type = &PyType_Type;
18241851
Py_INCREF(&ThemeDrawingState_Type);
1825-
if (PyDict_SetItemString(d, "ThemeDrawingStateType", (PyObject *)&ThemeDrawingState_Type) != 0)
1826-
Py_FatalError("can't initialize ThemeDrawingStateType");
1852+
PyModule_AddObject(m, "ThemeDrawingState", (PyObject *)&ThemeDrawingState_Type);
1853+
/* Backward-compatible name */
1854+
Py_INCREF(&ThemeDrawingState_Type);
1855+
PyModule_AddObject(m, "ThemeDrawingStateType", (PyObject *)&ThemeDrawingState_Type);
18271856
}
18281857

18291858
/* ======================== End module _App ========================= */

Mac/Modules/app/appsupport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
9595
"""
9696

97-
class MyObjectDefinition(PEP252Mixin, GlobalObjectDefinition):
97+
class MyObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
9898
pass
9999
## def outputCheckNewArg(self):
100100
## Output("if (itself == NULL) return PyMac_Error(resNotFound);")

Mac/Modules/carbonevt/CarbonEvtsupport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def precheck(self):
215215

216216

217217

218-
class EventHandlerRefObjectDefinition(PEP252Mixin, GlobalObjectDefinition):
218+
class EventHandlerRefObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
219219
def outputStructMembers(self):
220220
Output("%s ob_itself;", self.itselftype)
221221
Output("PyObject *ob_callback;")
@@ -228,7 +228,7 @@ def outputFreeIt(self, name):
228228
Output("Py_DECREF(self->ob_callback);")
229229
OutRbrace()
230230

231-
class MyGlobalObjectDefinition(PEP252Mixin, GlobalObjectDefinition):
231+
class MyGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
232232
pass
233233

234234
for typ in RefObjectTypes:

0 commit comments

Comments
 (0)