annotate Mac/Modules/cf/cfsupport.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 840ff58d1e9e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 # This script generates a Python interface for an Apple Macintosh Manager.
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 # It uses the "bgen" package to generate C code.
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 # The function specifications are generated by scanning the mamager's header file,
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 # using the "scantools" package (customized for this particular manager).
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6 #error missing SetActionFilter
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 import string
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 # Declarations that change for each manager
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
11 MODNAME = '_CF' # The name of the module
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 # The following is *usually* unchanged but may still require tuning
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
14 MODPREFIX = 'CF' # The prefix for module-wide routines
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
16 OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 from macsupport import *
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19
18677
e421aa45040c Used an adapted MethodGenerator to generate methods too for functions that have the object as the second arg after a first CFAllocatorRef arg (which we pass as NULL always anyway).
Jack Jansen <jack.jansen@cwi.nl>
parents: 18387
diff changeset
20 # Special case generator for the functions that have an AllocatorRef first argument,
e421aa45040c Used an adapted MethodGenerator to generate methods too for functions that have the object as the second arg after a first CFAllocatorRef arg (which we pass as NULL always anyway).
Jack Jansen <jack.jansen@cwi.nl>
parents: 18387
diff changeset
21 # which we skip anyway, and the object as the second arg.
e421aa45040c Used an adapted MethodGenerator to generate methods too for functions that have the object as the second arg after a first CFAllocatorRef arg (which we pass as NULL always anyway).
Jack Jansen <jack.jansen@cwi.nl>
parents: 18387
diff changeset
22 class MethodSkipArg1(MethodGenerator):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
23 """Similar to MethodGenerator, but has self as last argument"""
18677
e421aa45040c Used an adapted MethodGenerator to generate methods too for functions that have the object as the second arg after a first CFAllocatorRef arg (which we pass as NULL always anyway).
Jack Jansen <jack.jansen@cwi.nl>
parents: 18387
diff changeset
24
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
25 def parseArgumentList(self, args):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
26 if len(args) < 2:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
27 raise ValueError, "MethodSkipArg1 expects at least 2 args"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
28 a0, a1, args = args[0], args[1], args[2:]
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
29 t0, n0, m0 = a0
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
30 if t0 != "CFAllocatorRef" and m0 != InMode:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
31 raise ValueError, "MethodSkipArg1 should have dummy AllocatorRef first arg"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
32 t1, n1, m1 = a1
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
33 if m1 != InMode:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
34 raise ValueError, "method's 'self' must be 'InMode'"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
35 dummy = Variable(t0, n0, m0)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
36 self.argumentList.append(dummy)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
37 self.itself = Variable(t1, "_self->ob_itself", SelfMode)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
38 self.argumentList.append(self.itself)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
39 FunctionGenerator.parseArgumentList(self, args)
18677
e421aa45040c Used an adapted MethodGenerator to generate methods too for functions that have the object as the second arg after a first CFAllocatorRef arg (which we pass as NULL always anyway).
Jack Jansen <jack.jansen@cwi.nl>
parents: 18387
diff changeset
40
e421aa45040c Used an adapted MethodGenerator to generate methods too for functions that have the object as the second arg after a first CFAllocatorRef arg (which we pass as NULL always anyway).
Jack Jansen <jack.jansen@cwi.nl>
parents: 18387
diff changeset
41
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 # Create the type objects
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 includestuff = includestuff + """
18978
34284216201b If we use frameworks we should include CoreServices/CoreServices.h, not the
Jack Jansen <jack.jansen@cwi.nl>
parents: 18677
diff changeset
45 #include <CoreServices/CoreServices.h>
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
47 #include "pycfbridge.h"
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
48
20877
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
49 #ifdef USE_TOOLBOX_OBJECT_GLUE
29279
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
50 extern PyObject *_CFObj_New(CFTypeRef);
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
51 extern int _CFObj_Convert(PyObject *, CFTypeRef *);
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
52 #define CFObj_New _CFObj_New
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
53 #define CFObj_Convert _CFObj_Convert
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
54
20877
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
55 extern PyObject *_CFTypeRefObj_New(CFTypeRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
56 extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
57 #define CFTypeRefObj_New _CFTypeRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
58 #define CFTypeRefObj_Convert _CFTypeRefObj_Convert
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
59
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
60 extern PyObject *_CFStringRefObj_New(CFStringRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
61 extern int _CFStringRefObj_Convert(PyObject *, CFStringRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
62 #define CFStringRefObj_New _CFStringRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
63 #define CFStringRefObj_Convert _CFStringRefObj_Convert
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
64
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
65 extern PyObject *_CFMutableStringRefObj_New(CFMutableStringRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
66 extern int _CFMutableStringRefObj_Convert(PyObject *, CFMutableStringRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
67 #define CFMutableStringRefObj_New _CFMutableStringRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
68 #define CFMutableStringRefObj_Convert _CFMutableStringRefObj_Convert
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
69
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
70 extern PyObject *_CFArrayRefObj_New(CFArrayRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
71 extern int _CFArrayRefObj_Convert(PyObject *, CFArrayRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
72 #define CFArrayRefObj_New _CFArrayRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
73 #define CFArrayRefObj_Convert _CFArrayRefObj_Convert
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
74
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
75 extern PyObject *_CFMutableArrayRefObj_New(CFMutableArrayRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
76 extern int _CFMutableArrayRefObj_Convert(PyObject *, CFMutableArrayRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
77 #define CFMutableArrayRefObj_New _CFMutableArrayRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
78 #define CFMutableArrayRefObj_Convert _CFMutableArrayRefObj_Convert
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
79
20877
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
80 extern PyObject *_CFDataRefObj_New(CFDataRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
81 extern int _CFDataRefObj_Convert(PyObject *, CFDataRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
82 #define CFDataRefObj_New _CFDataRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
83 #define CFDataRefObj_Convert _CFDataRefObj_Convert
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
84
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
85 extern PyObject *_CFMutableDataRefObj_New(CFMutableDataRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
86 extern int _CFMutableDataRefObj_Convert(PyObject *, CFMutableDataRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
87 #define CFMutableDataRefObj_New _CFMutableDataRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
88 #define CFMutableDataRefObj_Convert _CFMutableDataRefObj_Convert
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89
20877
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
90 extern PyObject *_CFDictionaryRefObj_New(CFDictionaryRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
91 extern int _CFDictionaryRefObj_Convert(PyObject *, CFDictionaryRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
92 #define CFDictionaryRefObj_New _CFDictionaryRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
93 #define CFDictionaryRefObj_Convert _CFDictionaryRefObj_Convert
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94
20877
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
95 extern PyObject *_CFMutableDictionaryRefObj_New(CFMutableDictionaryRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
96 extern int _CFMutableDictionaryRefObj_Convert(PyObject *, CFMutableDictionaryRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
97 #define CFMutableDictionaryRefObj_New _CFMutableDictionaryRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
98 #define CFMutableDictionaryRefObj_Convert _CFMutableDictionaryRefObj_Convert
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
99
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
100 extern PyObject *_CFURLRefObj_New(CFURLRef);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
101 extern int _CFURLRefObj_Convert(PyObject *, CFURLRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
102 extern int _OptionalCFURLRefObj_Convert(PyObject *, CFURLRef *);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
103 #define CFURLRefObj_New _CFURLRefObj_New
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
104 #define CFURLRefObj_Convert _CFURLRefObj_Convert
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
105 #define OptionalCFURLRefObj_Convert _OptionalCFURLRefObj_Convert
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 #endif
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
108 /*
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
109 ** Parse/generate CFRange records
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
110 */
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
111 PyObject *CFRange_New(CFRange *itself)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
112 {
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
113
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
114 return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
115 }
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
116
19708
6eafc4a6359a Regenerated without default int return types.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19441
diff changeset
117 int
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
118 CFRange_Convert(PyObject *v, CFRange *p_itself)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
119 {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
120 long location, length;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
121
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
122 if( !PyArg_ParseTuple(v, "ll", &location, &length) )
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
123 return 0;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
124 p_itself->location = (CFIndex)location;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
125 p_itself->length = (CFIndex)length;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
126 return 1;
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
127 }
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
128
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
129 /* Optional CFURL argument or None (passed as NULL) */
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
130 int
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
131 OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
132 {
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
133 if ( v == Py_None ) {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
134 p_itself = NULL;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
135 return 1;
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
136 }
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
137 return CFURLRefObj_Convert(v, p_itself);
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
138 }
29279
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
139 """
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
140
29279
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
141 finalstuff = finalstuff + """
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
142
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
143 /* Routines to convert any CF type to/from the corresponding CFxxxObj */
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
144 PyObject *CFObj_New(CFTypeRef itself)
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
145 {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
146 if (itself == NULL)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
147 {
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
148 PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
149 return NULL;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
150 }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
151 if (CFGetTypeID(itself) == CFArrayGetTypeID()) return CFArrayRefObj_New((CFArrayRef)itself);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
152 if (CFGetTypeID(itself) == CFDictionaryGetTypeID()) return CFDictionaryRefObj_New((CFDictionaryRef)itself);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
153 if (CFGetTypeID(itself) == CFDataGetTypeID()) return CFDataRefObj_New((CFDataRef)itself);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
154 if (CFGetTypeID(itself) == CFStringGetTypeID()) return CFStringRefObj_New((CFStringRef)itself);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
155 if (CFGetTypeID(itself) == CFURLGetTypeID()) return CFURLRefObj_New((CFURLRef)itself);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
156 /* XXXX Or should we use PyCF_CF2Python here?? */
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
157 return CFTypeRefObj_New(itself);
29279
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
158 }
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
159 int CFObj_Convert(PyObject *v, CFTypeRef *p_itself)
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
160 {
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
161
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
162 if (v == Py_None) { *p_itself = NULL; return 1; }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
163 /* Check for other CF objects here */
29279
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
164
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
165 if (!CFTypeRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
166 !CFArrayRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
167 !CFMutableArrayRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
168 !CFDictionaryRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
169 !CFMutableDictionaryRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
170 !CFDataRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
171 !CFMutableDataRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
172 !CFStringRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
173 !CFMutableStringRefObj_Check(v) &&
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
174 !CFURLRefObj_Check(v) )
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
175 {
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
176 /* XXXX Or should we use PyCF_Python2CF here?? */
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
177 PyErr_SetString(PyExc_TypeError, "CF object required");
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
178 return 0;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
179 }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
180 *p_itself = ((CFTypeRefObject *)v)->ob_itself;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
181 return 1;
29279
b372b903d10e Added functions CFObj_New and CFObj_Convert, general functions to convert
Jack Jansen <jack.jansen@cwi.nl>
parents: 28147
diff changeset
182 }
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 """
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 initstuff = initstuff + """
29345
b3455c4c1798 Forgot the code to initialize the glue for the new CFObj_ routines.
Jack Jansen <jack.jansen@cwi.nl>
parents: 29279
diff changeset
186 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFObj_New);
b3455c4c1798 Forgot the code to initialize the glue for the new CFObj_ routines.
Jack Jansen <jack.jansen@cwi.nl>
parents: 29279
diff changeset
187 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFObj_Convert);
20877
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
188 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFTypeRef, CFTypeRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
189 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFTypeRef, CFTypeRefObj_Convert);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
190 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFStringRef, CFStringRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
191 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFStringRef, CFStringRefObj_Convert);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
192 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableStringRef, CFMutableStringRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
193 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableStringRef, CFMutableStringRefObj_Convert);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
194 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFArrayRef, CFArrayRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
195 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFArrayRef, CFArrayRefObj_Convert);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
196 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableArrayRef, CFMutableArrayRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
197 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableArrayRef, CFMutableArrayRefObj_Convert);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
198 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFDictionaryRef, CFDictionaryRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
199 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFDictionaryRef, CFDictionaryRefObj_Convert);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
200 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFMutableDictionaryRef, CFMutableDictionaryRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
201 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFMutableDictionaryRef, CFMutableDictionaryRefObj_Convert);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
202 PyMac_INIT_TOOLBOX_OBJECT_NEW(CFURLRef, CFURLRefObj_New);
d54e294484b2 Make the CoreFoundation object _New and _Convert routines available to other modules. Idea by Donovan Preston, implementaion by me.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19723
diff changeset
203 PyMac_INIT_TOOLBOX_OBJECT_CONVERT(CFURLRef, CFURLRefObj_Convert);
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204 """
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205
23438
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
206 variablestuff="""
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
207 #define _STRINGCONST(name) PyModule_AddObject(m, #name, CFStringRefObj_New(name))
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
208 _STRINGCONST(kCFPreferencesAnyApplication);
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
209 _STRINGCONST(kCFPreferencesCurrentApplication);
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
210 _STRINGCONST(kCFPreferencesAnyHost);
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
211 _STRINGCONST(kCFPreferencesCurrentHost);
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
212 _STRINGCONST(kCFPreferencesAnyUser);
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
213 _STRINGCONST(kCFPreferencesCurrentUser);
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
214
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
215 """
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
216
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 Boolean = Type("Boolean", "l")
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218 CFTypeID = Type("CFTypeID", "l") # XXXX a guess, seems better than OSTypeType.
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219 CFHashCode = Type("CFHashCode", "l")
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
220 CFIndex = Type("CFIndex", "l")
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
221 CFRange = OpaqueByValueType('CFRange', 'CFRange')
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
222 CFOptionFlags = Type("CFOptionFlags", "l")
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
223 CFStringEncoding = Type("CFStringEncoding", "l")
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
224 CFComparisonResult = Type("CFComparisonResult", "l") # a bit dangerous, it's an enum
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
225 CFURLPathStyle = Type("CFURLPathStyle", "l") # a bit dangerous, it's an enum
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
226
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
227 char_ptr = stringptr
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
228 return_stringptr = Type("char *", "s") # ONLY FOR RETURN VALUES!!
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
229
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 CFAllocatorRef = FakeType("(CFAllocatorRef)NULL")
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
231 CFArrayCallBacks_ptr = FakeType("&kCFTypeArrayCallBacks")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
232 CFDictionaryKeyCallBacks_ptr = FakeType("&kCFTypeDictionaryKeyCallBacks")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
233 CFDictionaryValueCallBacks_ptr = FakeType("&kCFTypeDictionaryValueCallBacks")
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 # The real objects
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235 CFTypeRef = OpaqueByValueType("CFTypeRef", "CFTypeRefObj")
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
236 CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
237 CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
238 CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
239 CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
240 CFDataRef = OpaqueByValueType("CFDataRef", "CFDataRefObj")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
241 CFMutableDataRef = OpaqueByValueType("CFMutableDataRef", "CFMutableDataRefObj")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
242 CFDictionaryRef = OpaqueByValueType("CFDictionaryRef", "CFDictionaryRefObj")
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
243 CFMutableDictionaryRef = OpaqueByValueType("CFMutableDictionaryRef", "CFMutableDictionaryRefObj")
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj")
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
245 CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
246 CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
247 OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
23414
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
248 ##CFPropertyListRef = OpaqueByValueType("CFPropertyListRef", "CFTypeRefObj")
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
249 # ADD object type here
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
251 # Our (opaque) objects
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
252
32690
2bf869d31f0c Make CF module PEP253 based (finally).
Jack Jansen <jack.jansen@cwi.nl>
parents: 30973
diff changeset
253 class MyGlobalObjectDefinition(PEP253Mixin, GlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
254 def outputCheckNewArg(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
255 Output('if (itself == NULL)')
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
256 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
257 Output('PyErr_SetString(PyExc_RuntimeError, "cannot wrap NULL");')
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
258 Output('return NULL;')
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
259 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
260 def outputStructMembers(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
261 GlobalObjectDefinition.outputStructMembers(self)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
262 Output("void (*ob_freeit)(CFTypeRef ptr);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
263 def outputInitStructMembers(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
264 GlobalObjectDefinition.outputInitStructMembers(self)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
265 ## Output("it->ob_freeit = NULL;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
266 Output("it->ob_freeit = CFRelease;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
267 def outputCheckConvertArg(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
268 Out("""
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
269 if (v == Py_None) { *p_itself = NULL; return 1; }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
270 /* Check for other CF objects here */
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
271 """)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
272 def outputCleanupStructMembers(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
273 Output("if (self->ob_freeit && self->ob_itself)")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
274 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
275 Output("self->ob_freeit((CFTypeRef)self->ob_itself);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
276 Output("self->ob_itself = NULL;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
277 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
278
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
279 def outputCompare(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
280 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
281 Output("static int %s_compare(%s *self, %s *other)", self.prefix, self.objecttype, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
282 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
283 Output("/* XXXX Or should we use CFEqual?? */")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
284 Output("if ( self->ob_itself > other->ob_itself ) return 1;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
285 Output("if ( self->ob_itself < other->ob_itself ) return -1;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
286 Output("return 0;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
287 OutRbrace()
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
289 def outputHash(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
290 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
291 Output("static int %s_hash(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
292 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
293 Output("/* XXXX Or should we use CFHash?? */")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
294 Output("return (int)self->ob_itself;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
295 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
296
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
297 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
298 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
299 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
300 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
301 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
302 Output("""sprintf(buf, "<CFTypeRef type-%%d object at 0x%%8.8x for 0x%%8.8x>", (int)CFGetTypeID(self->ob_itself), (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
303 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
304 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
305
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
306 def output_tp_newBody(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
307 Output("PyObject *self;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
308 Output
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
309 Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
310 Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
311 Output("((%s *)self)->ob_freeit = CFRelease;", self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
312 Output("return self;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
313
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
314 def output_tp_initBody(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
315 Output("%s itself;", self.itselftype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
316 Output("char *kw[] = {\"itself\", 0};")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
317 Output()
35200
5df1c692bb41 Updated (and regenerated) for name change in tp_init method arguments:
Jack Jansen <jack.jansen@cwi.nl>
parents: 32736
diff changeset
318 Output("if (PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, %s_Convert, &itself))",
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
319 self.prefix)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
320 OutLbrace()
35200
5df1c692bb41 Updated (and regenerated) for name change in tp_init method arguments:
Jack Jansen <jack.jansen@cwi.nl>
parents: 32736
diff changeset
321 Output("((%s *)_self)->ob_itself = itself;", self.objecttype)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
322 Output("return 0;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
323 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
324 if self.prefix != 'CFTypeRefObj':
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
325 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
326 Output("/* Any CFTypeRef descendent is allowed as initializer too */")
35200
5df1c692bb41 Updated (and regenerated) for name change in tp_init method arguments:
Jack Jansen <jack.jansen@cwi.nl>
parents: 32736
diff changeset
327 Output("if (PyArg_ParseTupleAndKeywords(_args, _kwds, \"O&\", kw, CFTypeRefObj_Convert, &itself))")
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
328 OutLbrace()
35200
5df1c692bb41 Updated (and regenerated) for name change in tp_init method arguments:
Jack Jansen <jack.jansen@cwi.nl>
parents: 32736
diff changeset
329 Output("((%s *)_self)->ob_itself = itself;", self.objecttype)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
330 Output("return 0;")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
331 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
332 Output("return -1;")
32690
2bf869d31f0c Make CF module PEP253 based (finally).
Jack Jansen <jack.jansen@cwi.nl>
parents: 30973
diff changeset
333
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
334 class CFTypeRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
335 pass
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
336
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
337 class CFArrayRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
338 basetype = "CFTypeRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
339
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
340 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
341 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
342 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
343 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
344 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
345 Output("""sprintf(buf, "<CFArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
346 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
347 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
348
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
349 class CFMutableArrayRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
350 basetype = "CFArrayRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
351
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
352 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
353 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
354 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
355 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
356 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
357 Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
358 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
359 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
360
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
361 class CFDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
362 basetype = "CFTypeRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
363
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
364 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
365 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
366 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
367 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
368 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
369 Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
370 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
371 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
372
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
373 class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
374 basetype = "CFDictionaryRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
375
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
376 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
377 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
378 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
379 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
380 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
381 Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
382 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
383 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
384
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
385 class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
386 basetype = "CFTypeRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
387
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
388 def outputCheckConvertArg(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
389 Out("""
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
390 if (v == Py_None) { *p_itself = NULL; return 1; }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
391 if (PyString_Check(v)) {
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
392 char *cStr;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
393 int cLen;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
394 if( PyString_AsStringAndSize(v, &cStr, &cLen) < 0 ) return 0;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
395 *p_itself = CFDataCreate((CFAllocatorRef)NULL, (unsigned char *)cStr, cLen);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
396 return 1;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
397 }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
398 """)
23414
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
399
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
400 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
401 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
402 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
403 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
404 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
405 Output("""sprintf(buf, "<CFDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
406 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
407 OutRbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
408
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
409 class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
410 basetype = "CFDataRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
411
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
412 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
413 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
414 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
415 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
416 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
417 Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
418 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
419 OutRbrace()
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
420
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
421 class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
422 basetype = "CFTypeRef_Type"
18353
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
423
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
424 def outputCheckConvertArg(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
425 Out("""
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
426 if (v == Py_None) { *p_itself = NULL; return 1; }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
427 if (PyString_Check(v)) {
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
428 char *cStr;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
429 if (!PyArg_Parse(v, "es", "ascii", &cStr))
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
430 return NULL;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
431 *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, kCFStringEncodingASCII);
43344
840ff58d1e9e bug #1154: release memory allocated by "es" PyArg_ParseTuple format specifier.
Georg Brandl <georg@python.org>
parents: 35200
diff changeset
432 PyMem_Free(cStr);
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
433 return 1;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
434 }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
435 if (PyUnicode_Check(v)) {
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
436 /* We use the CF types here, if Python was configured differently that will give an error */
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
437 CFIndex size = PyUnicode_GetSize(v);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
438 UniChar *unichars = PyUnicode_AsUnicode(v);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
439 if (!unichars) return 0;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
440 *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
441 return 1;
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
442 }
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
443
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
444 """)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
445
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
446 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
447 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
448 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
449 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
450 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
451 Output("""sprintf(buf, "<CFStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
452 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
453 OutRbrace()
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
454
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
455 class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
456 basetype = "CFStringRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
457
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
458 def outputCheckConvertArg(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
459 # Mutable, don't allow Python strings
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
460 return MyGlobalObjectDefinition.outputCheckConvertArg(self)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
461
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
462 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
463 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
464 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
465 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
466 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
467 Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
468 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
469 OutRbrace()
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
470
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
471 class CFURLRefObjectDefinition(MyGlobalObjectDefinition):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
472 basetype = "CFTypeRef_Type"
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
473
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
474 def outputRepr(self):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
475 Output()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
476 Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
477 OutLbrace()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
478 Output("char buf[100];")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
479 Output("""sprintf(buf, "<CFURL object at 0x%%8.8x for 0x%%8.8x>", (unsigned)self, (unsigned)self->ob_itself);""")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
480 Output("return PyString_FromString(buf);")
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
481 OutRbrace()
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
482
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
483
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
484 # ADD object class here
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
485
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
486 # From here on it's basically all boiler plate...
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
487
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
488 # Create the generator groups and link them
23438
08d6c8b780d9 Added CFPreferences support. Added these as functions, not methods, which seemed counter-intuitive.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23424
diff changeset
489 module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff, variablestuff)
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
490 CFTypeRef_object = CFTypeRefObjectDefinition('CFTypeRef', 'CFTypeRefObj', 'CFTypeRef')
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
491 CFArrayRef_object = CFArrayRefObjectDefinition('CFArrayRef', 'CFArrayRefObj', 'CFArrayRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
492 CFMutableArrayRef_object = CFMutableArrayRefObjectDefinition('CFMutableArrayRef', 'CFMutableArrayRefObj', 'CFMutableArrayRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
493 CFDictionaryRef_object = CFDictionaryRefObjectDefinition('CFDictionaryRef', 'CFDictionaryRefObj', 'CFDictionaryRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
494 CFMutableDictionaryRef_object = CFMutableDictionaryRefObjectDefinition('CFMutableDictionaryRef', 'CFMutableDictionaryRefObj', 'CFMutableDictionaryRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
495 CFDataRef_object = CFDataRefObjectDefinition('CFDataRef', 'CFDataRefObj', 'CFDataRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
496 CFMutableDataRef_object = CFMutableDataRefObjectDefinition('CFMutableDataRef', 'CFMutableDataRefObj', 'CFMutableDataRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
497 CFStringRef_object = CFStringRefObjectDefinition('CFStringRef', 'CFStringRefObj', 'CFStringRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
498 CFMutableStringRef_object = CFMutableStringRefObjectDefinition('CFMutableStringRef', 'CFMutableStringRefObj', 'CFMutableStringRef')
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
499 CFURLRef_object = CFURLRefObjectDefinition('CFURLRef', 'CFURLRefObj', 'CFURLRef')
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
500
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
501 # ADD object here
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
502
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
503 module.addobject(CFTypeRef_object)
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
504 module.addobject(CFArrayRef_object)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
505 module.addobject(CFMutableArrayRef_object)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
506 module.addobject(CFDictionaryRef_object)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
507 module.addobject(CFMutableDictionaryRef_object)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
508 module.addobject(CFDataRef_object)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
509 module.addobject(CFMutableDataRef_object)
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
510 module.addobject(CFStringRef_object)
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
511 module.addobject(CFMutableStringRef_object)
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
512 module.addobject(CFURLRef_object)
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
513 # ADD addobject call here
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
514
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
515 # Create the generator classes used to populate the lists
18353
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
516 Function = OSErrWeakLinkFunctionGenerator
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
517 Method = OSErrWeakLinkMethodGenerator
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
518
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
519 # Create and populate the lists
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
520 functions = []
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
521 CFTypeRef_methods = []
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
522 CFArrayRef_methods = []
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
523 CFMutableArrayRef_methods = []
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
524 CFDictionaryRef_methods = []
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
525 CFMutableDictionaryRef_methods = []
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
526 CFDataRef_methods = []
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
527 CFMutableDataRef_methods = []
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
528 CFStringRef_methods = []
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
529 CFMutableStringRef_methods = []
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
530 CFURLRef_methods = []
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
531
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
532 # ADD _methods initializer here
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
533 execfile(INPUTFILE)
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
534
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
535
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
536 # add the populated lists to the generator groups
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
537 # (in a different wordl the scan program would generate this)
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
538 for f in functions: module.add(f)
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
539 for f in CFTypeRef_methods: CFTypeRef_object.add(f)
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
540 for f in CFArrayRef_methods: CFArrayRef_object.add(f)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
541 for f in CFMutableArrayRef_methods: CFMutableArrayRef_object.add(f)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
542 for f in CFDictionaryRef_methods: CFDictionaryRef_object.add(f)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
543 for f in CFMutableDictionaryRef_methods: CFMutableDictionaryRef_object.add(f)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
544 for f in CFDataRef_methods: CFDataRef_object.add(f)
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
545 for f in CFMutableDataRef_methods: CFMutableDataRef_object.add(f)
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
546 for f in CFStringRef_methods: CFStringRef_object.add(f)
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
547 for f in CFMutableStringRef_methods: CFMutableStringRef_object.add(f)
18335
6a1630117805 Added CFURL support, and got base chaining to really work.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18331
diff changeset
548 for f in CFURLRef_methods: CFURLRef_object.add(f)
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
549
18353
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
550 # Manual generators for getting data out of strings
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
551
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
552 getasstring_body = """
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
553 int size = CFStringGetLength(_self->ob_itself)+1;
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
554 char *data = malloc(size);
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
555
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
556 if( data == NULL ) return PyErr_NoMemory();
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
557 if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
558 _res = (PyObject *)PyString_FromString(data);
18353
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
559 } else {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
560 PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
561 _res = NULL;
18353
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
562 }
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
563 free(data);
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
564 return _res;
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
565 """
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
566
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
567 f = ManualGenerator("CFStringGetString", getasstring_body);
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
568 f.docstring = lambda: "() -> (string _rv)"
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
569 CFStringRef_object.add(f)
9c58ddc47195 - Use weaklink generators so we can support OSX-only calls without crashing on OS9.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18335
diff changeset
570
18387
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
571 getasunicode_body = """
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
572 int size = CFStringGetLength(_self->ob_itself)+1;
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
573 Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
574 CFRange range;
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
575
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
576 range.location = 0;
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
577 range.length = size;
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
578 if( data == NULL ) return PyErr_NoMemory();
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
579 CFStringGetCharacters(_self->ob_itself, range, data);
32691
5fb78a2d94f0 CFStringGetUnicode() returned an extra null character at the end of the string.
Jack Jansen <jack.jansen@cwi.nl>
parents: 32690
diff changeset
580 _res = (PyObject *)PyUnicode_FromUnicode(data, size-1);
18387
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
581 free(data);
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
582 return _res;
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
583 """
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
584
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
585 f = ManualGenerator("CFStringGetUnicode", getasunicode_body);
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
586 f.docstring = lambda: "() -> (unicode _rv)"
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
587 CFStringRef_object.add(f)
9c6a8dcd722d Do conversion of CFStrings to/from unicode.
unknown <tools@python.org>
parents: 18353
diff changeset
588
23414
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
589 # Get data from CFDataRef
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
590 getasdata_body = """
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
591 int size = CFDataGetLength(_self->ob_itself);
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
592 char *data = (char *)CFDataGetBytePtr(_self->ob_itself);
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
593
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
594 _res = (PyObject *)PyString_FromStringAndSize(data, size);
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
595 return _res;
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
596 """
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
597
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
598 f = ManualGenerator("CFDataGetData", getasdata_body);
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
599 f.docstring = lambda: "() -> (string _rv)"
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
600 CFDataRef_object.add(f)
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
601
23424
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
602 # Manual generator for CFPropertyListCreateFromXMLData because of funny error return
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
603 fromxml_body = """
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
604 CFTypeRef _rv;
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
605 CFOptionFlags mutabilityOption;
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
606 CFStringRef errorString;
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
607 if (!PyArg_ParseTuple(_args, "l",
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
608 &mutabilityOption))
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
609 return NULL;
23424
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
610 _rv = CFPropertyListCreateFromXMLData((CFAllocatorRef)NULL,
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
611 _self->ob_itself,
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
612 mutabilityOption,
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
613 &errorString);
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
614 if (errorString)
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
615 CFRelease(errorString);
23424
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
616 if (_rv == NULL) {
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
617 PyErr_SetString(PyExc_RuntimeError, "Parse error in XML data");
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
618 return NULL;
23424
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
619 }
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
620 _res = Py_BuildValue("O&",
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
621 CFTypeRefObj_New, _rv);
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
622 return _res;
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
623 """
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
624 f = ManualGenerator("CFPropertyListCreateFromXMLData", fromxml_body)
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
625 f.docstring = lambda: "(CFOptionFlags mutabilityOption) -> (CFTypeRefObj)"
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
626 CFTypeRef_object.add(f)
23414
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
627
23424
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
628 # Convert CF objects to Python objects
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
629 toPython_body = """
26767
ad263d268255 - Various tweaks to forestall compiler warnings.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23438
diff changeset
630 _res = PyCF_CF2Python(_self->ob_itself);
ad263d268255 - Various tweaks to forestall compiler warnings.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23438
diff changeset
631 return _res;
23424
63890bc29a7c - Better exception when a NULL CF object is encountered.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23414
diff changeset
632 """
23414
e5ef166fc22f - Get data from CFData objects as Python strings and vv.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23395
diff changeset
633
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
634 f = ManualGenerator("toPython", toPython_body);
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
635 f.docstring = lambda: "() -> (python_object)"
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
636 CFTypeRef_object.add(f)
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
637
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
638 toCF_body = """
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
639 CFTypeRef rv;
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
640 CFTypeID typeid;
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
641
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
642 if (!PyArg_ParseTuple(_args, "O&", PyCF_Python2CF, &rv))
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
643 return NULL;
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
644 typeid = CFGetTypeID(rv);
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
645
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
646 if (typeid == CFStringGetTypeID())
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
647 return Py_BuildValue("O&", CFStringRefObj_New, rv);
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
648 if (typeid == CFArrayGetTypeID())
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
649 return Py_BuildValue("O&", CFArrayRefObj_New, rv);
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
650 if (typeid == CFDictionaryGetTypeID())
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
651 return Py_BuildValue("O&", CFDictionaryRefObj_New, rv);
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
652 if (typeid == CFURLGetTypeID())
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 32693
diff changeset
653 return Py_BuildValue("O&", CFURLRefObj_New, rv);
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
654
26767
ad263d268255 - Various tweaks to forestall compiler warnings.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23438
diff changeset
655 _res = Py_BuildValue("O&", CFTypeRefObj_New, rv);
ad263d268255 - Various tweaks to forestall compiler warnings.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23438
diff changeset
656 return _res;
23395
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
657 """
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
658 f = ManualGenerator("toCF", toCF_body);
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
659 f.docstring = lambda: "(python_object) -> (CF_object)"
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
660 module.add(f)
bfe91e1e31b2 More support for bridging between Python and CoreFoundation objects. Still untested.
Jack Jansen <jack.jansen@cwi.nl>
parents: 21614
diff changeset
661
18331
bf936c529635 CFArray, CFData and CFDictonary are now covered, but mainly opaque.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18289
diff changeset
662 # ADD add forloop here
18289
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
663
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
664 # generate output (open the output file as late as possible)
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
665 SetOutputFileName(OUTPUTFILE)
4fa31eca3be4 First small step towards bgen-generated CoreFoundation. there is hardly any real functionality yet, but method chains seem to work, and so do Retain/Release semantics.
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
666 module.generate()