]> git.saurik.com Git - wxWidgets.git/blob - wxPython/SWIG/swig.python-prepend.patch
Updated SWIG patches to CWIG CVS 20040130.
[wxWidgets.git] / wxPython / SWIG / swig.python-prepend.patch
1 --- Source/Modules/mystuff/python.cxx.18 2004-01-30 15:22:49.000000000 -0800
2 +++ Source/Modules/python.cxx 2004-01-30 16:27:22.000000000 -0800
3 @@ -426,19 +426,21 @@
4 * functions.
5 * ------------------------------------------------------------ */
6
7 void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) {
8 - if ( ! have_addtofunc(n) && ! have_docstring(n) ) {
9 - /* If there is no addtofunc or docstring directive then just assign from the extension module */
10 + if ( !have_pythonprepend(n) && !have_pythonappend(n) && !have_docstring(n) ) {
11 + /* If there is no pythonappend or docstring directive then just assign from the extension module */
12 Printv(f_dest, "\n", name, " = ", module, ".", name, "\n", NIL);
13 } else {
14 /* Otherwise make a wrapper function to insert the code into */
15 Printv(f_dest, "\ndef ", name, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL);
16 if ( have_docstring(n) )
17 Printv(f_dest, tab4, docstring(n, AUTODOC_FUNC, tab4), "\n", NIL);
18 - if ( have_addtofunc(n) ) {
19 + if ( have_pythonprepend(n) )
20 + Printv(f_dest, tab4, pythonprepend(n), "\n", NIL);
21 + if ( have_pythonappend(n) ) {
22 Printv(f_dest, tab4, "val = ", funcCallHelper(name, kw), "\n", NIL);
23 - Printv(f_dest, tab4, addtofunc(n), "\n", NIL);
24 + Printv(f_dest, tab4, pythonappend(n), "\n", NIL);
25 Printv(f_dest, tab4, "return val\n", NIL);
26 } else {
27 Printv(f_dest, tab4, "return ", funcCallHelper(name, kw), "\n", NIL);
28 }
29 @@ -696,24 +698,49 @@
30 }
31
32
33 /* ------------------------------------------------------------
34 - * have_addtofunc()
35 - * Check if there is a %addtofunc directive and it has text
36 + * have_pythonprepend()
37 + * Check if there is a %pythonprepend directive and it has text
38 * ------------------------------------------------------------ */
39
40 - bool have_addtofunc(Node *n) {
41 - String* str = Getattr(n, "feature:addtofunc");
42 + bool have_pythonprepend(Node *n) {
43 + String* str = Getattr(n, "feature:pythonprepend");
44 return (str != NULL && Len(str) > 0);
45 }
46
47 /* ------------------------------------------------------------
48 - * addtofunc()
49 - * Get the %addtofunc code, stripping off {} if neccessary
50 + * pythonprepend()
51 + * Get the %pythonprepend code, stripping off {} if neccessary
52 * ------------------------------------------------------------ */
53
54 - String *addtofunc(Node *n) {
55 - String* str = Getattr(n, "feature:addtofunc");
56 + String *pythonprepend(Node *n) {
57 + String* str = Getattr(n, "feature:pythonprepend");
58 + char* t = Char(str);
59 + if (*t == '{') {
60 + Delitem(str ,0);
61 + Delitem(str,DOH_END);
62 + }
63 + return str;
64 + }
65 +
66 + /* ------------------------------------------------------------
67 + * have_pythonappend()
68 + * Check if there is a %pythonappend directive and it has text
69 + * ------------------------------------------------------------ */
70 +
71 + bool have_pythonappend(Node *n) {
72 + String* str = Getattr(n, "feature:pythonappend");
73 + return (str != NULL && Len(str) > 0);
74 + }
75 +
76 + /* ------------------------------------------------------------
77 + * pythonappend()
78 + * Get the %pythonappend code, stripping off {} if neccessary
79 + * ------------------------------------------------------------ */
80 +
81 + String *pythonappend(Node *n) {
82 + String* str = Getattr(n, "feature:pythonappend");
83 char* t = Char(str);
84 if (*t == '{') {
85 Delitem(str ,0);
86 Delitem(str,DOH_END);
87 @@ -2124,17 +2151,19 @@
88 Printv(f_shadow,pycode,"\n",NIL);
89 } else {
90
91 Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "):", NIL);
92 - if ( ! have_addtofunc(n) && ! have_docstring(n)) {
93 + if ( !have_pythonprepend(n) && !have_pythonappend(n) && !have_docstring(n)) {
94 Printv(f_shadow, " return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL);
95 } else {
96 Printv(f_shadow, "\n", NIL);
97 if ( have_docstring(n) )
98 Printv(f_shadow, tab8, docstring(n, AUTODOC_FUNC, tab8), "\n", NIL);
99 - if ( have_addtofunc(n) ) {
100 + if ( have_pythonprepend(n) )
101 + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL);
102 + if ( have_pythonappend(n) ) {
103 Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL);
104 - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL);
105 + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL);
106 Printv(f_shadow, tab8, "return val\n\n", NIL);
107 } else {
108 Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n\n", NIL);
109 }
110 @@ -2153,16 +2182,18 @@
111 virtual int staticmemberfunctionHandler(Node *n) {
112 String *symname = Getattr(n,"sym:name");
113 Language::staticmemberfunctionHandler(n);
114 if (shadow) {
115 - if ( !classic && (have_addtofunc(n) || have_docstring(n)) ) {
116 + if ( !classic && (have_pythonprepend(n) || have_pythonappend(n) || have_docstring(n)) ) {
117 int kw = (check_kwargs(n) && !Getattr(n,"sym:overloaded")) ? 1 : 0;
118 Printv(f_shadow, tab4, "def ", symname, "(*args", (kw ? ", **kwargs" : ""), "):\n", NIL);
119 if ( have_docstring(n) )
120 Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL);
121 - if ( have_addtofunc(n) ) {
122 + if ( have_pythonprepend(n) )
123 + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL);
124 + if ( have_pythonappend(n) ) {
125 Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n", NIL);
126 - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL);
127 + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL);
128 Printv(f_shadow, tab8, "return val\n\n", NIL);
129 } else {
130 Printv(f_shadow, tab8, "return ", funcCallHelper(Swig_name_member(class_name, symname), kw), "\n\n", NIL);
131 }
132 @@ -2253,8 +2284,10 @@
133 Printv(f_shadow, tab4, "def __init__(self, *args",
134 (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL);
135 if ( have_docstring(n) )
136 Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL);
137 + if ( have_pythonprepend(n) )
138 + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL);
139 Printv(f_shadow, pass_self, NIL);
140 if (!modern) {
141 Printv(f_shadow, tab8, "_swig_setattr(self, ", rclassname, ", 'this', ",
142 funcCallHelper(Swig_name_construct(symname), allow_kwargs), ")\n", NIL);
143 @@ -2267,10 +2300,10 @@
144 Printv(f_shadow, tab8, "self.this = newobj.this\n", NIL);
145 Printv(f_shadow, tab8, "self.thisown = 1\n", NIL);
146 Printv(f_shadow, tab8, "del newobj.thisown\n", NIL);
147 }
148 - if ( have_addtofunc(n) )
149 - Printv(f_shadow, tab8, addtofunc(n), "\n\n", NIL);
150 + if ( have_pythonappend(n) )
151 + Printv(f_shadow, tab8, pythonappend(n), "\n\n", NIL);
152 Delete(pass_self);
153 }
154 have_constructor = 1;
155 } else {
156 @@ -2288,13 +2321,15 @@
157 Printv(f_shadow_stubs, "\ndef ", symname, "(*args",
158 (allow_kwargs ? ", **kwargs" : ""), "):\n", NIL);
159 if ( have_docstring(n) )
160 Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL);
161 + if ( have_pythonprepend(n) )
162 + Printv(f_shadow_stubs, tab4, pythonprepend(n), "\n", NIL);
163 Printv(f_shadow_stubs, tab4, "val = ",
164 funcCallHelper(Swig_name_construct(symname), allow_kwargs), "\n", NIL);
165 Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL);
166 - if ( have_addtofunc(n) )
167 - Printv(f_shadow_stubs, tab4, addtofunc(n), "\n", NIL);
168 + if ( have_pythonappend(n) )
169 + Printv(f_shadow_stubs, tab4, pythonappend(n), "\n", NIL);
170 Printv(f_shadow_stubs, tab4, "return val\n", NIL);
171 }
172 }
173 }
174 @@ -2323,13 +2358,16 @@
175 } else {
176 Printv(f_shadow, tab4, "def __del__(self, destroy=", module, ".", Swig_name_destroy(symname), "):\n", NIL);
177 if ( have_docstring(n) )
178 Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL);
179 - if ( have_addtofunc(n) )
180 - Printv(f_shadow, tab8, addtofunc(n), "\n", NIL);
181 + if ( have_pythonprepend(n) )
182 + Printv(f_shadow, tab8, pythonprepend(n), "\n", NIL);
183 Printv(f_shadow, tab8, "try:\n", NIL);
184 Printv(f_shadow, tab8, tab4, "if self.thisown: destroy(self)\n", NIL);
185 - Printv(f_shadow, tab8, "except: pass\n\n", NIL);
186 + Printv(f_shadow, tab8, "except: pass\n", NIL);
187 + if ( have_pythonappend(n) )
188 + Printv(f_shadow, tab8, pythonappend(n), "\n", NIL);
189 + Printv(f_shadow, "\n", NIL);
190 }
191 }
192 return SWIG_OK;
193 }