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

Skip to content

Commit dbd5701

Browse files
committed
Converted the Carbon modules to use PEP252-style objects, with
descriptors in stead of manual getattr hooks to get at attributes of the objects. For Qd I have in stead gotten rid of most of the attribute access in favor of the carbon-style accessor methods (with the exception of visRgn, to be done later), and of the Carbon.Qd.qd global object, for which accessor functions are also available. For List I have fixed the fact that various methods were incorrectly generated as functions. CF is untouched: PEP252 doesn't allow "poor-mans-inheritance" with basechain, so it will have to wait for PEP253 support.
1 parent 8188559 commit dbd5701

48 files changed

Lines changed: 4184 additions & 4244 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: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
}} while(0)
2121

2222

23+
#ifndef PyDoc_STR
24+
#define PyDoc_STR(x) (x)
25+
#endif
2326
#ifdef WITHOUT_FRAMEWORKS
2427
#include <AppleEvents.h>
2528
#include <AEObjects.h>
@@ -35,7 +38,13 @@ extern int _AEDesc_Convert(PyObject *, AEDesc *);
3538
#define AEDesc_Convert _AEDesc_Convert
3639
#endif
3740

38-
static pascal OSErr GenericEventHandler(); /* Forward */
41+
#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
42+
typedef long refcontype;
43+
#else
44+
typedef unsigned long refcontype;
45+
#endif
46+
47+
static pascal OSErr GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon); /* Forward */
3948

4049
AEEventHandlerUPP upp_GenericEventHandler;
4150

@@ -820,46 +829,40 @@ static PyMethodDef AEDesc_methods[] = {
820829
{NULL, NULL, 0}
821830
};
822831

823-
PyMethodChain AEDesc_chain = { AEDesc_methods, NULL };
824-
825-
static PyObject *AEDesc_getattr(AEDescObject *self, char *name)
832+
static PyObject *AEDesc_get_type(AEDescObject *self, void *closure)
826833
{
834+
return PyMac_BuildOSType(self->ob_itself.descriptorType);
835+
}
827836

828-
if (strcmp(name, "type") == 0)
829-
return PyMac_BuildOSType(self->ob_itself.descriptorType);
830-
if (strcmp(name, "data") == 0) {
831-
PyObject *res;
832-
#if !TARGET_API_MAC_CARBON
833-
char state;
834-
state = HGetState(self->ob_itself.dataHandle);
835-
HLock(self->ob_itself.dataHandle);
836-
res = PyString_FromStringAndSize(
837-
*self->ob_itself.dataHandle,
838-
GetHandleSize(self->ob_itself.dataHandle));
839-
HUnlock(self->ob_itself.dataHandle);
840-
HSetState(self->ob_itself.dataHandle, state);
841-
#else
842-
Size size;
843-
char *ptr;
844-
OSErr err;
845-
846-
size = AEGetDescDataSize(&self->ob_itself);
847-
if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
848-
return NULL;
849-
if ( (ptr = PyString_AsString(res)) == NULL )
850-
return NULL;
851-
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
852-
return PyMac_Error(err);
853-
#endif
854-
return res;
855-
}
856-
if (strcmp(name, "__members__") == 0)
857-
return Py_BuildValue("[ss]", "data", "type");
837+
#define AEDesc_set_type NULL
858838

859-
return Py_FindMethodInChain(&AEDesc_chain, (PyObject *)self, name);
839+
static PyObject *AEDesc_get_data(AEDescObject *self, void *closure)
840+
{
841+
842+
PyObject *res;
843+
Size size;
844+
char *ptr;
845+
OSErr err;
846+
847+
size = AEGetDescDataSize(&self->ob_itself);
848+
if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
849+
return NULL;
850+
if ( (ptr = PyString_AsString(res)) == NULL )
851+
return NULL;
852+
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
853+
return PyMac_Error(err);
854+
return res;
855+
860856
}
861857

862-
#define AEDesc_setattr NULL
858+
#define AEDesc_set_data NULL
859+
860+
static PyGetSetDef AEDesc_getsetlist[] = {
861+
{"type", (getter)AEDesc_get_type, (setter)AEDesc_set_type, "Type of this AEDesc"},
862+
{"data", (getter)AEDesc_get_data, (setter)AEDesc_set_data, "The raw data in this AEDesc"},
863+
{NULL, NULL, NULL, NULL},
864+
};
865+
863866

864867
#define AEDesc_compare NULL
865868

@@ -876,14 +879,31 @@ PyTypeObject AEDesc_Type = {
876879
/* methods */
877880
(destructor) AEDesc_dealloc, /*tp_dealloc*/
878881
0, /*tp_print*/
879-
(getattrfunc) AEDesc_getattr, /*tp_getattr*/
880-
(setattrfunc) AEDesc_setattr, /*tp_setattr*/
882+
(getattrfunc)0, /*tp_getattr*/
883+
(setattrfunc)0, /*tp_setattr*/
881884
(cmpfunc) AEDesc_compare, /*tp_compare*/
882885
(reprfunc) AEDesc_repr, /*tp_repr*/
883886
(PyNumberMethods *)0, /* tp_as_number */
884887
(PySequenceMethods *)0, /* tp_as_sequence */
885888
(PyMappingMethods *)0, /* tp_as_mapping */
886889
(hashfunc) AEDesc_hash, /*tp_hash*/
890+
0, /*tp_call*/
891+
0, /*tp_str*/
892+
PyObject_GenericGetAttr, /*tp_getattro*/
893+
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*/
903+
AEDesc_methods, /* tp_methods */
904+
0, /*outputHook_tp_members*/
905+
AEDesc_getsetlist, /*tp_getset*/
906+
0, /*outputHook_tp_base*/
887907
};
888908

889909
/* --------------------- End object type AEDesc --------------------- */
@@ -1350,12 +1370,6 @@ static PyMethodDef AE_methods[] = {
13501370

13511371

13521372

1353-
#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
1354-
typedef long refcontype;
1355-
#else
1356-
typedef unsigned long refcontype;
1357-
#endif
1358-
13591373
static pascal OSErr
13601374
GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
13611375
{

Mac/Modules/ae/aesupport.py

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def passInput(self, name):
8282

8383

8484
includestuff = includestuff + """
85+
#ifndef PyDoc_STR
86+
#define PyDoc_STR(x) (x)
87+
#endif
8588
#ifdef WITHOUT_FRAMEWORKS
8689
#include <AppleEvents.h>
8790
#include <AEObjects.h>
@@ -97,7 +100,13 @@ def passInput(self, name):
97100
#define AEDesc_Convert _AEDesc_Convert
98101
#endif
99102
100-
static pascal OSErr GenericEventHandler(); /* Forward */
103+
#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
104+
typedef long refcontype;
105+
#else
106+
typedef unsigned long refcontype;
107+
#endif
108+
109+
static pascal OSErr GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon); /* Forward */
101110
102111
AEEventHandlerUPP upp_GenericEventHandler;
103112
@@ -118,12 +127,6 @@ def passInput(self, name):
118127
"""
119128

120129
finalstuff = finalstuff + """
121-
#if UNIVERSAL_INTERFACES_VERSION >= 0x0340
122-
typedef long refcontype;
123-
#else
124-
typedef unsigned long refcontype;
125-
#endif
126-
127130
static pascal OSErr
128131
GenericEventHandler(const AppleEvent *request, AppleEvent *reply, refcontype refcon)
129132
{
@@ -171,7 +174,32 @@ def passInput(self, name):
171174

172175
module = MacModule('_AE', 'AE', includestuff, finalstuff, initstuff)
173176

174-
class AEDescDefinition(GlobalObjectDefinition):
177+
class AEDescDefinition(PEP252Mixin, GlobalObjectDefinition):
178+
getsetlist = [(
179+
'type',
180+
'return PyMac_BuildOSType(self->ob_itself.descriptorType);',
181+
None,
182+
'Type of this AEDesc'
183+
), (
184+
'data',
185+
"""
186+
PyObject *res;
187+
Size size;
188+
char *ptr;
189+
OSErr err;
190+
191+
size = AEGetDescDataSize(&self->ob_itself);
192+
if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
193+
return NULL;
194+
if ( (ptr = PyString_AsString(res)) == NULL )
195+
return NULL;
196+
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
197+
return PyMac_Error(err);
198+
return res;
199+
""",
200+
None,
201+
'The raw data in this AEDesc'
202+
)]
175203

176204
def __init__(self, name, prefix = None, itselftype = None):
177205
GlobalObjectDefinition.__init__(self, name, prefix or name, itselftype or name)
@@ -180,41 +208,6 @@ def __init__(self, name, prefix = None, itselftype = None):
180208
def outputFreeIt(self, name):
181209
Output("AEDisposeDesc(&%s);", name)
182210

183-
def outputGetattrHook(self):
184-
Output("""
185-
if (strcmp(name, "type") == 0)
186-
return PyMac_BuildOSType(self->ob_itself.descriptorType);
187-
if (strcmp(name, "data") == 0) {
188-
PyObject *res;
189-
#if !TARGET_API_MAC_CARBON
190-
char state;
191-
state = HGetState(self->ob_itself.dataHandle);
192-
HLock(self->ob_itself.dataHandle);
193-
res = PyString_FromStringAndSize(
194-
*self->ob_itself.dataHandle,
195-
GetHandleSize(self->ob_itself.dataHandle));
196-
HUnlock(self->ob_itself.dataHandle);
197-
HSetState(self->ob_itself.dataHandle, state);
198-
#else
199-
Size size;
200-
char *ptr;
201-
OSErr err;
202-
203-
size = AEGetDescDataSize(&self->ob_itself);
204-
if ( (res = PyString_FromStringAndSize(NULL, size)) == NULL )
205-
return NULL;
206-
if ( (ptr = PyString_AsString(res)) == NULL )
207-
return NULL;
208-
if ( (err=AEGetDescData(&self->ob_itself, ptr, size)) < 0 )
209-
return PyMac_Error(err);
210-
#endif
211-
return res;
212-
}
213-
if (strcmp(name, "__members__") == 0)
214-
return Py_BuildValue("[ss]", "data", "type");
215-
""")
216-
217-
218211
aedescobject = AEDescDefinition('AEDesc')
219212
module.addobject(aedescobject)
220213

Mac/Modules/alias/_Aliasmodule.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,7 @@ static PyMethodDef AliasObj_methods[] = {
9595
{NULL, NULL, 0}
9696
};
9797

98-
PyMethodChain AliasObj_chain = { AliasObj_methods, NULL };
99-
100-
static PyObject *AliasObj_getattr(AliasObject *self, char *name)
101-
{
102-
return Py_FindMethodInChain(&AliasObj_chain, (PyObject *)self, name);
103-
}
104-
105-
#define AliasObj_setattr NULL
98+
#define AliasObj_getsetlist NULL
10699

107100
#define AliasObj_compare NULL
108101

@@ -119,14 +112,31 @@ PyTypeObject Alias_Type = {
119112
/* methods */
120113
(destructor) AliasObj_dealloc, /*tp_dealloc*/
121114
0, /*tp_print*/
122-
(getattrfunc) AliasObj_getattr, /*tp_getattr*/
123-
(setattrfunc) AliasObj_setattr, /*tp_setattr*/
115+
(getattrfunc)0, /*tp_getattr*/
116+
(setattrfunc)0, /*tp_setattr*/
124117
(cmpfunc) AliasObj_compare, /*tp_compare*/
125118
(reprfunc) AliasObj_repr, /*tp_repr*/
126119
(PyNumberMethods *)0, /* tp_as_number */
127120
(PySequenceMethods *)0, /* tp_as_sequence */
128121
(PyMappingMethods *)0, /* tp_as_mapping */
129122
(hashfunc) AliasObj_hash, /*tp_hash*/
123+
0, /*tp_call*/
124+
0, /*tp_str*/
125+
PyObject_GenericGetAttr, /*tp_getattro*/
126+
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*/
136+
AliasObj_methods, /* tp_methods */
137+
0, /*outputHook_tp_members*/
138+
AliasObj_getsetlist, /*tp_getset*/
139+
0, /*outputHook_tp_base*/
130140
};
131141

132142
/* --------------------- End object type Alias ---------------------- */

Mac/Modules/alias/aliassupport.py

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

75-
class AliasDefinition(GlobalObjectDefinition):
75+
class AliasDefinition(PEP252Mixin, GlobalObjectDefinition):
7676

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

Mac/Modules/app/_Appmodule.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,7 @@ static PyMethodDef ThemeDrawingStateObj_methods[] = {
113113
{NULL, NULL, 0}
114114
};
115115

116-
PyMethodChain ThemeDrawingStateObj_chain = { ThemeDrawingStateObj_methods, NULL };
117-
118-
static PyObject *ThemeDrawingStateObj_getattr(ThemeDrawingStateObject *self, char *name)
119-
{
120-
return Py_FindMethodInChain(&ThemeDrawingStateObj_chain, (PyObject *)self, name);
121-
}
122-
123-
#define ThemeDrawingStateObj_setattr NULL
116+
#define ThemeDrawingStateObj_getsetlist NULL
124117

125118
#define ThemeDrawingStateObj_compare NULL
126119

@@ -137,14 +130,31 @@ PyTypeObject ThemeDrawingState_Type = {
137130
/* methods */
138131
(destructor) ThemeDrawingStateObj_dealloc, /*tp_dealloc*/
139132
0, /*tp_print*/
140-
(getattrfunc) ThemeDrawingStateObj_getattr, /*tp_getattr*/
141-
(setattrfunc) ThemeDrawingStateObj_setattr, /*tp_setattr*/
133+
(getattrfunc)0, /*tp_getattr*/
134+
(setattrfunc)0, /*tp_setattr*/
142135
(cmpfunc) ThemeDrawingStateObj_compare, /*tp_compare*/
143136
(reprfunc) ThemeDrawingStateObj_repr, /*tp_repr*/
144137
(PyNumberMethods *)0, /* tp_as_number */
145138
(PySequenceMethods *)0, /* tp_as_sequence */
146139
(PyMappingMethods *)0, /* tp_as_mapping */
147140
(hashfunc) ThemeDrawingStateObj_hash, /*tp_hash*/
141+
0, /*tp_call*/
142+
0, /*tp_str*/
143+
PyObject_GenericGetAttr, /*tp_getattro*/
144+
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*/
154+
ThemeDrawingStateObj_methods, /* tp_methods */
155+
0, /*outputHook_tp_members*/
156+
ThemeDrawingStateObj_getsetlist, /*tp_getset*/
157+
0, /*outputHook_tp_base*/
148158
};
149159

150160
/* --------------- End object type ThemeDrawingState ---------------- */

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(GlobalObjectDefinition):
97+
class MyObjectDefinition(PEP252Mixin, GlobalObjectDefinition):
9898
pass
9999
## def outputCheckNewArg(self):
100100
## Output("if (itself == NULL) return PyMac_Error(resNotFound);")

0 commit comments

Comments
 (0)