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

Skip to content

Commit 537a69f

Browse files
committed
Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
1 parent 80c85d8 commit 537a69f

4 files changed

Lines changed: 186 additions & 38 deletions

File tree

Include/pymactoolbox.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
#include <Lists.h>
1616
#include <Movies.h>
1717
#include <Errors.h>
18+
#include <CFBase.h>
19+
#include <CFArray.h>
20+
#include <CFData.h>
21+
#include <CFDictionary.h>
22+
#include <CFString.h>
23+
#include <CFURL.h>
1824
#else
1925
#include <Carbon/Carbon.h>
2026
#include <QuickTime/QuickTime.h>
@@ -167,6 +173,24 @@ extern PyObject *WinObj_New(WindowPtr);
167173
extern int WinObj_Convert(PyObject *, WindowPtr *);
168174
extern PyObject *WinObj_WhichWindow(WindowPtr);
169175

176+
/* CF exports */
177+
extern PyObject *CFTypeRefObj_New(CFTypeRef);
178+
extern int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
179+
extern PyObject *CFStringRefObj_New(CFStringRef);
180+
extern int CFStringRefObj_Convert(PyObject *, CFStringRef *);
181+
extern PyObject *CFMutableStringRefObj_New(CFMutableStringRef);
182+
extern int CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
183+
extern PyObject *CFArrayRefObj_New(CFArrayRef);
184+
extern int CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
185+
extern PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef);
186+
extern int CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
187+
extern PyObject *CFDictionaryRefObj_New(CFDictionaryRef);
188+
extern int CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
189+
extern PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
190+
extern int CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
191+
extern PyObject *CFURLRefObj_New(CFURLRef);
192+
extern int CFURLRefObj_Convert(PyObject *, CFURLRef *);
193+
extern int OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
170194

171195
#ifdef __cplusplus
172196
}

Mac/Modules/cf/_CFmodule.c

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,58 @@
3131
#include <CoreServices/CoreServices.h>
3232
#endif
3333

34-
/* For now we declare them forward here. They'll go to mactoolbox later */
35-
staticforward PyObject *CFTypeRefObj_New(CFTypeRef);
36-
staticforward int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
37-
staticforward PyObject *CFStringRefObj_New(CFStringRef);
38-
staticforward int CFStringRefObj_Convert(PyObject *, CFStringRef *);
39-
staticforward PyObject *CFURLRefObj_New(CFURLRef);
40-
staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
41-
42-
staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
43-
44-
// ADD declarations
45-
#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
46-
//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
47-
//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
48-
49-
//#define CFTypeRefObj_New _CFTypeRefObj_New
50-
//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
34+
#ifdef USE_TOOLBOX_OBJECT_GLUE
35+
extern PyObject *_CFTypeRefObj_New(CFTypeRef);
36+
extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
37+
#define CFTypeRefObj_New _CFTypeRefObj_New
38+
#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
39+
40+
extern PyObject *_CFStringRefObj_New(CFStringRef);
41+
extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
42+
#define CFStringRefObj_New _CFStringRefObj_New
43+
#define CFStringRefObj_Convert _CFStringRefObj_Convert
44+
45+
extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
46+
extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
47+
#define CFMutableStringRefObj_New _CFMutableStringRefObj_New
48+
#define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
49+
50+
extern PyObject *_CFArrayRefObj_New(CFArrayRef);
51+
extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
52+
#define CFArrayRefObj_New _CFArrayRefObj_New
53+
#define CFArrayRefObj_Convert _CFArrayRefObj_Convert
54+
55+
extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
56+
extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
57+
#define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
58+
#define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
59+
60+
extern PyObject *_CFDataRefObj_New(CFDataRef);
61+
extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
62+
#define CFDataRefObj_New _CFDataRefObj_New
63+
#define CFDataRefObj_Convert _CFDataRefObj_Convert
64+
65+
extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
66+
extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
67+
#define CFMutableDataRefObj_New _CFMutableDataRefObj_New
68+
#define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
69+
70+
extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
71+
extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
72+
#define CFDictionaryRefObj_New _CFDictionaryRefObj_New
73+
#define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
74+
75+
extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
76+
extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
77+
#define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
78+
#define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
79+
80+
extern PyObject *_CFURLRefObj_New(CFURLRef);
81+
extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
82+
extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
83+
#define CFURLRefObj_New _CFURLRefObj_New
84+
#define CFURLRefObj_Convert _CFURLRefObj_Convert
85+
#define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
5186
#endif
5287

5388
/*
@@ -3122,8 +3157,24 @@ void init_CF(void)
31223157

31233158

31243159

3125-
// PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
3126-
// PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
3160+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New);
3161+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert);
3162+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New);
3163+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert);
3164+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New);
3165+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert);
3166+
3167+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New);
3168+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert);
3169+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New);
3170+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert);
3171+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New);
3172+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert);
3173+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New);
3174+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert);
3175+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New);
3176+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
3177+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
31273178

31283179

31293180
m = Py_InitModule("_CF", CF_methods);

Mac/Modules/cf/cfsupport.py

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,58 @@ def parseArgumentList(self, args):
5353
#include <CoreServices/CoreServices.h>
5454
#endif
5555
56-
/* For now we declare them forward here. They'll go to mactoolbox later */
57-
staticforward PyObject *CFTypeRefObj_New(CFTypeRef);
58-
staticforward int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
59-
staticforward PyObject *CFStringRefObj_New(CFStringRef);
60-
staticforward int CFStringRefObj_Convert(PyObject *, CFStringRef *);
61-
staticforward PyObject *CFURLRefObj_New(CFURLRef);
62-
staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
63-
64-
staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
65-
66-
// ADD declarations
67-
#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
68-
//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
69-
//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
70-
71-
//#define CFTypeRefObj_New _CFTypeRefObj_New
72-
//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
56+
#ifdef USE_TOOLBOX_OBJECT_GLUE
57+
extern PyObject *_CFTypeRefObj_New(CFTypeRef);
58+
extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
59+
#define CFTypeRefObj_New _CFTypeRefObj_New
60+
#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
61+
62+
extern PyObject *_CFStringRefObj_New(CFStringRef);
63+
extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
64+
#define CFStringRefObj_New _CFStringRefObj_New
65+
#define CFStringRefObj_Convert _CFStringRefObj_Convert
66+
67+
extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
68+
extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
69+
#define CFMutableStringRefObj_New _CFMutableStringRefObj_New
70+
#define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
71+
72+
extern PyObject *_CFArrayRefObj_New(CFArrayRef);
73+
extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
74+
#define CFArrayRefObj_New _CFArrayRefObj_New
75+
#define CFArrayRefObj_Convert _CFArrayRefObj_Convert
76+
77+
extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
78+
extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
79+
#define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
80+
#define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
81+
82+
extern PyObject *_CFDataRefObj_New(CFDataRef);
83+
extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
84+
#define CFDataRefObj_New _CFDataRefObj_New
85+
#define CFDataRefObj_Convert _CFDataRefObj_Convert
86+
87+
extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
88+
extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
89+
#define CFMutableDataRefObj_New _CFMutableDataRefObj_New
90+
#define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
91+
92+
extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
93+
extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
94+
#define CFDictionaryRefObj_New _CFDictionaryRefObj_New
95+
#define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
96+
97+
extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
98+
extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
99+
#define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
100+
#define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
101+
102+
extern PyObject *_CFURLRefObj_New(CFURLRef);
103+
extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
104+
extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
105+
#define CFURLRefObj_New _CFURLRefObj_New
106+
#define CFURLRefObj_Convert _CFURLRefObj_Convert
107+
#define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
73108
#endif
74109
75110
/*
@@ -107,8 +142,24 @@ def parseArgumentList(self, args):
107142
"""
108143

109144
initstuff = initstuff + """
110-
// PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
111-
// PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
145+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New);
146+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert);
147+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New);
148+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert);
149+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New);
150+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert);
151+
152+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New);
153+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert);
154+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New);
155+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert);
156+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New);
157+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert);
158+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New);
159+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert);
160+
PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New);
161+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
162+
PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
112163
"""
113164

114165
Boolean = Type("Boolean", "l")

Python/mactoolboxglue.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,4 +459,26 @@ GLUE_NEW(WindowPtr, WinObj_New, "Carbon.Win")
459459
GLUE_CONVERT(WindowPtr, WinObj_Convert, "Carbon.Win")
460460
GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Carbon.Win")
461461

462+
GLUE_CONVERT(CFTypeRef, CFTypeRefObj_Convert, "Carbon.CF")
463+
GLUE_NEW(CFTypeRef, CFTypeRefObj_New, "Carbon.CF")
464+
465+
GLUE_CONVERT(CFStringRef, CFStringRefObj_Convert, "Carbon.CF")
466+
GLUE_NEW(CFStringRef, CFStringRefObj_New, "Carbon.CF")
467+
GLUE_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert, "Carbon.CF")
468+
GLUE_NEW(CFMutableStringRef, CFMutableStringRefObj_New, "Carbon.CF")
469+
470+
GLUE_CONVERT(CFArrayRef, CFArrayRefObj_Convert, "Carbon.CF")
471+
GLUE_NEW(CFArrayRef, CFArrayRefObj_New, "Carbon.CF")
472+
GLUE_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert, "Carbon.CF")
473+
GLUE_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New, "Carbon.CF")
474+
475+
GLUE_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert, "Carbon.CF")
476+
GLUE_NEW(CFDictionaryRef, CFDictionaryRefObj_New, "Carbon.CF")
477+
GLUE_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert, "Carbon.CF")
478+
GLUE_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New, "Carbon.CF")
479+
480+
GLUE_CONVERT(CFURLRef, CFURLRefObj_Convert, "Carbon.CF")
481+
GLUE_CONVERT(CFURLRef, OptionalCFURLRefObj_Convert, "Carbon.CF")
482+
GLUE_NEW(CFURLRef, CFURLRefObj_New, "Carbon.CF")
483+
462484
#endif /* USE_TOOLBOX_OBJECT_GLUE */

0 commit comments

Comments
 (0)