Commit | Line | Data |
---|---|---|
34e49164 C |
1 | /* |
2 | * (C) arty 2002 | |
3 | * This software is covered under the GNU lesser general public license | |
4 | */ | |
5 | ||
6 | #include "Python.h" | |
7 | #include "caml/mlvalues.h" | |
8 | #include "caml/memory.h" | |
9 | #include "caml/callback.h" | |
10 | #include "caml/custom.h" | |
11 | #include "caml/alloc.h" | |
12 | #include <unistd.h> | |
13 | ||
14 | #define true 1 | |
15 | #define false 0 | |
16 | ||
17 | static void *getcustom( value v ) { return *((void **)Data_custom_val(v)); } | |
18 | ||
19 | static void pydecref( value v ) { | |
20 | if( getcustom(v) ) { Py_DECREF((PyObject *)getcustom(v)); } | |
21 | } | |
22 | ||
23 | static int pycompare( value v1, value v2 ) { | |
24 | int result; | |
25 | if( getcustom(v1) && !getcustom(v2) ) return -1; | |
26 | if( getcustom(v2) && !getcustom(v1) ) return 1; | |
27 | if( !getcustom(v1) && !getcustom(v2) ) return 0; | |
28 | PyObject_Cmp((PyObject *)getcustom(v1), | |
29 | (PyObject *)getcustom(v2),&result); | |
30 | return result; | |
31 | } | |
32 | ||
33 | static long pyhash( value v ) { | |
34 | if( getcustom(v) ) return PyObject_Hash((PyObject *)getcustom(v)); | |
35 | else return 0; | |
36 | } | |
37 | ||
38 | static unsigned long pydeserialize( void *dst ) { | |
39 | return 0; | |
40 | } | |
41 | ||
42 | struct custom_operations pyops = { | |
43 | "PythonObject", | |
44 | pydecref, | |
45 | pycompare, | |
46 | pyhash, | |
47 | custom_serialize_default, | |
48 | pydeserialize | |
49 | }; | |
50 | ||
51 | struct custom_operations fnops = { | |
52 | "FuncPointer", | |
53 | NULL, | |
54 | NULL, | |
55 | NULL, | |
56 | NULL, | |
57 | NULL | |
58 | }; | |
59 | ||
60 | value pywrap( PyObject *obj ) { | |
61 | CAMLparam0(); | |
62 | CAMLlocal1(v); | |
63 | if( obj ) | |
64 | Py_INCREF(obj); | |
65 | v = alloc_custom( &pyops, sizeof( PyObject * ), 100, 100000 ); | |
66 | *((PyObject **)Data_custom_val(v)) = obj; | |
67 | CAMLreturn(v); | |
68 | } | |
69 | ||
70 | value funcwrap( void *obj ) { | |
71 | CAMLparam0(); | |
72 | CAMLlocal1(v); | |
73 | v = alloc_custom( &fnops, sizeof( void * ), 100, 100000 ); | |
74 | *((void **)Data_custom_val(v)) = obj; | |
75 | CAMLreturn(v); | |
76 | } | |
77 | ||
78 | PyObject *pyunwrap( value v ) { | |
79 | return *((PyObject **)Data_custom_val(v)); | |
80 | } | |
81 | ||
82 | static void camldestr( void *v ) { | |
83 | value *valptr = (value *)v; | |
84 | remove_global_root(valptr); | |
85 | free( v ); | |
86 | } | |
87 | ||
88 | PyObject *camlwrap( value val, void *aux_str, int size ) { | |
89 | value *v = (value *)malloc(sizeof(value) + size); | |
90 | *v = val; | |
91 | memcpy((void *)v+sizeof(value),aux_str,size); | |
92 | register_global_root(v); | |
93 | return PyCObject_FromVoidPtr(v,camldestr); | |
94 | } | |
95 | ||
96 | void *caml_aux( PyObject *obj ) { | |
97 | value *v = (value *)PyCObject_AsVoidPtr( obj ); | |
98 | return (void *)v+sizeof(value); | |
99 | } | |
100 | ||
101 | PyObject *pycall_callback( PyObject *obj, PyObject *args ) { | |
102 | value out; | |
103 | value *v; | |
104 | ||
105 | if( !PyCObject_Check(obj) ) { | |
106 | Py_INCREF(Py_None); | |
107 | return Py_None; | |
108 | } | |
109 | v = (value *)PyCObject_AsVoidPtr( obj ); | |
110 | out = callback(*v,pywrap(args)); | |
111 | return pyunwrap(out); | |
112 | } | |
113 | ||
114 | typedef void (*type_1)( void ); | |
115 | typedef void (*type_2)( int ); | |
116 | typedef void (*type_3)( char * ); | |
117 | typedef int (*type_4)( void ); | |
118 | typedef int (*type_5)( char * ); | |
119 | typedef int (*type_6)( FILE *, char * ); | |
120 | typedef int (*type_7)( FILE *, char *, int ); | |
121 | typedef char *(*type_8)( void ); | |
122 | typedef PyObject* (*type_9)(char*, int, PyObject *, PyObject *); | |
123 | typedef PyObject* (*type_10)(FILE *, char*, int, PyObject *, PyObject *); | |
124 | typedef PyObject* (*type_11)(FILE *, char*, int, PyObject *, PyObject *, int ); | |
125 | typedef PyObject* (*type_12)(char*, char*, int); | |
126 | typedef int (*type_13)(PyObject *, FILE *, int); | |
127 | typedef PyObject * (*type_14)(PyObject *); | |
128 | typedef PyObject * (*type_15)(PyObject *, PyObject *, int); | |
129 | typedef PyObject * (*type_16)(PyObject *, char *); | |
130 | typedef PyObject * (*type_17)(PyObject *, PyObject *); | |
131 | typedef int (*type_18)(PyObject *); | |
132 | typedef int (*type_19)(PyObject *, PyObject *); | |
133 | typedef int (*type_20)(PyObject *, PyObject *, int); | |
134 | typedef int (*type_21)(PyObject *, char *, PyObject *); | |
135 | typedef int (*type_22)(PyObject *, char *); | |
136 | typedef int (*type_23)(PyObject **, PyObject **); | |
137 | typedef int (*type_24)(PyObject *, PyObject *, PyObject *); | |
138 | typedef long (*type_25)(PyObject *); | |
139 | typedef char *(*type_26)(PyObject *); | |
140 | typedef void (*type_27)(PyObject **, PyObject *); | |
141 | typedef PyObject *(*type_28)(char *); | |
142 | typedef PyObject *(*type_29)(void); | |
143 | typedef void (*type_30)(PyObject *); | |
144 | typedef int (*type_31)(PyObject *, int *, PyObject **, PyObject **); | |
145 | typedef PyObject *(*type_32)(char*, char**, int); | |
146 | typedef PyObject *(*type_33)(Py_UNICODE*, int, int); | |
147 | typedef PyObject *(*type_34)(long); | |
148 | typedef long (*type_35)(void); | |
149 | typedef PyObject *(*type_36)(double); | |
150 | typedef double (*type_37)(PyObject *); | |
151 | typedef PyObject *(*type_38)(PyObject*, char**); | |
152 | typedef PyObject *(*type_39)(int size); | |
153 | typedef PyObject *(*type_40)(PyObject *, int); | |
154 | typedef int (*type_41)(PyObject *, int, PyObject *); | |
155 | typedef PyObject *(*type_42)(PyObject* start, PyObject* stop, PyObject* step); | |
156 | typedef int (*type_43)(PySliceObject *r, int length, int *start, int *stop, int *step); | |
157 | typedef PyObject *(*type_44)(long, long, long, int); | |
158 | typedef void (*type_45)(PyObject *, PyObject *); | |
159 | typedef void (*type_46)(PyObject *, const char *); | |
160 | typedef void (*type_47)(PyObject **, PyObject **, PyObject **); | |
161 | typedef void (*type_48)(PyObject *, PyObject *, PyObject *); | |
162 | typedef PyObject *(*type_49)(PyObject *, char *); | |
163 | typedef PyObject *(*type_50)(char *,PyObject *,char *); | |
164 | typedef PyObject *(*type_51)(char *,PyObject *,PyObject *,PyObject *); | |
165 | typedef int (*type_52)(PyObject *obj,const char **buffer,int *buffer_len); | |
166 | typedef int (*type_53)(PyObject *o, int i1, int i2, PyObject *v); | |
167 | typedef int (*type_54)(PyObject *o, int i1, int i2); | |
168 | ||
169 | value pygencall( value format, value arg ) { | |
170 | CAMLparam2(format,arg); | |
171 | CAMLlocal1(rv); | |
172 | FILE *f; | |
173 | int fd; | |
174 | int x; | |
175 | int ret_int; | |
0708f913 | 176 | const char *rvs; |
34e49164 C |
177 | int fmt = Int_val(Field(format,1)); |
178 | PyObject *ob1,*ob2,*ob3; | |
179 | void *func = getcustom(Field(format,0)); | |
180 | int reflect = Int_val(Field(format,2)); | |
181 | ||
182 | rv = Val_unit; | |
183 | ||
184 | switch( fmt ) { | |
185 | case 1: | |
186 | ((type_1)func)(); | |
187 | CAMLreturn(Val_unit); | |
188 | ||
189 | case 2: | |
190 | ((type_2)func)(Int_val(arg)); | |
191 | CAMLreturn(Val_unit); | |
192 | ||
193 | case 3: | |
194 | ((type_3)func)(String_val(arg)); | |
195 | CAMLreturn(Val_unit); | |
196 | ||
197 | case 4: | |
198 | CAMLreturn(Int_val(((type_4)func)())); | |
199 | ||
200 | case 5: | |
201 | CAMLreturn(Int_val(((type_5)func) | |
202 | (String_val(arg)))); | |
203 | ||
204 | case 6: | |
205 | case 7: | |
206 | case 10: | |
207 | case 11: | |
208 | fd = dup(Int_val(Field(arg,0))); | |
209 | f = fdopen(fd,"r+"); | |
210 | switch( fmt ) { | |
211 | case 6: | |
212 | rv = Val_int(((type_6)func) | |
213 | (f,String_val(Field(arg,1)))); | |
214 | break; | |
215 | ||
216 | case 7: | |
217 | rv = Val_int(((type_7)func) | |
218 | (f, | |
219 | String_val(Field(arg,1)), | |
220 | Int_val(Field(arg,2)))); | |
221 | break; | |
222 | ||
223 | case 10: | |
224 | rv = pywrap(((type_10)func) | |
225 | (f, | |
226 | String_val(Field(arg,1)), | |
227 | Int_val(Field(arg,2)), | |
228 | pyunwrap(Field(arg,3)), | |
229 | pyunwrap(Field(arg,4)))); | |
230 | break; | |
231 | ||
232 | case 11: | |
233 | rv = pywrap(((type_11)func) | |
234 | (f, | |
235 | String_val(Field(arg,1)), | |
236 | Int_val(Field(arg,2)), | |
237 | pyunwrap(Field(arg,3)), | |
238 | pyunwrap(Field(arg,4)), | |
239 | Int_val(Field(arg,5)))); | |
240 | break; | |
241 | } | |
242 | ||
243 | fclose( f ); | |
244 | CAMLreturn( rv ); | |
245 | ||
246 | case 8: | |
247 | CAMLreturn(copy_string(((type_8)func)())); | |
248 | ||
249 | case 9: | |
250 | CAMLreturn(pywrap(((type_9)func) | |
251 | (String_val(Field(arg,0)), | |
252 | Int_val(Field(arg,1)), | |
253 | pyunwrap(Field(arg,2)), | |
254 | pyunwrap(Field(arg,3))))); | |
255 | ||
256 | case 12: | |
257 | CAMLreturn(pywrap(((type_12)func) | |
258 | (String_val(Field(arg,0)), | |
259 | String_val(Field(arg,1)), | |
260 | Int_val(Field(arg,2))))); | |
261 | ||
262 | case 13: | |
263 | fd = dup(Int_val(Field(arg,1))); | |
264 | f = fdopen(fd,"r+"); | |
265 | rv = Val_int(((type_13)func) | |
266 | (pyunwrap(Field(arg,0)), | |
267 | f, | |
268 | Int_val(Field(arg,2)))); | |
269 | fclose( f ); | |
270 | break; | |
271 | ||
272 | case 14: | |
273 | CAMLreturn(pywrap(((type_14)func)(pyunwrap(arg)))); | |
274 | ||
275 | case 15: | |
276 | CAMLreturn(pywrap(((type_15)func) | |
277 | (pyunwrap(Field(arg,0)), | |
278 | pyunwrap(Field(arg,1)),Int_val(Field(arg,2))))); | |
279 | ||
280 | case 16: | |
281 | CAMLreturn(pywrap(((type_16)func) | |
282 | (pyunwrap(Field(arg,0)), | |
283 | String_val(Field(arg,1))))); | |
284 | ||
285 | case 17: | |
286 | CAMLreturn(pywrap(((type_17)func) | |
287 | (pyunwrap(Field(arg,0)),pyunwrap(Field(arg,1))))); | |
288 | ||
289 | case 18: | |
290 | CAMLreturn(Val_int(((type_18)func)(pyunwrap(arg)))); | |
291 | ||
292 | case 19: | |
293 | CAMLreturn(Val_int(((type_19)func) | |
294 | (pyunwrap(Field(arg,0)), | |
295 | pyunwrap(Field(arg,1))))); | |
296 | ||
297 | case 20: | |
298 | CAMLreturn(Val_int(((type_20)func) | |
299 | (pyunwrap(Field(arg,0)), | |
300 | pyunwrap(Field(arg,1)), | |
301 | Int_val(Field(arg,2))))); | |
302 | ||
303 | case 21: | |
304 | CAMLreturn(Val_int(((type_21)func) | |
305 | (pyunwrap(Field(arg,0)), | |
306 | String_val(Field(arg,1)), | |
307 | pyunwrap(Field(arg,2))))); | |
308 | ||
309 | case 22: | |
310 | CAMLreturn(Val_int(((type_22)func) | |
311 | (pyunwrap(Field(arg,0)), | |
312 | String_val(Field(arg,1))))); | |
313 | ||
314 | case 23: | |
315 | ob1 = pyunwrap(Field(arg,0)); ob2 = pyunwrap(Field(arg,1)); | |
316 | ret_int = ((type_23)func)( &ob1, &ob2 ); | |
317 | if( ret_int == -1 ) CAMLreturn((value)1); | |
318 | else { | |
319 | rv = alloc_tuple(2); | |
320 | Field(rv,0) = pywrap(ob1); | |
321 | Field(rv,1) = pywrap(ob2); | |
322 | CAMLreturn(rv); | |
323 | } | |
324 | ||
325 | case 24: | |
326 | CAMLreturn(Int_val(((type_24)func) | |
327 | (pyunwrap(Field(arg,0)), | |
328 | pyunwrap(Field(arg,1)), | |
329 | pyunwrap(Field(arg,2))))); | |
330 | ||
331 | case 25: | |
332 | CAMLreturn(copy_int64(((type_25)func)(pyunwrap(arg)))); | |
333 | ||
334 | case 26: | |
335 | CAMLreturn(copy_string(((type_26)func)(pyunwrap(arg)))); | |
336 | ||
337 | case 27: | |
338 | ob1 = pyunwrap(Field(arg,0)); | |
339 | ((type_27)func)(&ob1,pyunwrap(Field(arg,1))); | |
340 | CAMLreturn(pywrap(ob1)); | |
341 | ||
342 | case 28: | |
343 | CAMLreturn(pywrap(((type_28)func)(String_val(arg)))); | |
344 | ||
345 | case 29: | |
346 | CAMLreturn(pywrap(((type_29)func)())); | |
347 | ||
348 | case 30: | |
349 | ((type_30)func)(pyunwrap(arg)); | |
350 | CAMLreturn(Val_unit); | |
351 | ||
352 | case 31: | |
353 | x = Int_val(Field(arg,1)); | |
354 | ret_int = ((type_31)func) | |
355 | (pyunwrap(Field(arg,0)), | |
356 | &x, | |
357 | &ob1, &ob2); | |
358 | if( !ret_int ) CAMLreturn((value)1); | |
359 | else { | |
360 | rv = alloc_tuple(3); | |
361 | Field(rv,0) = pywrap(ob1); | |
362 | Field(rv,1) = pywrap(ob2); | |
363 | Field(rv,2) = Val_int(x); | |
364 | CAMLreturn(rv); | |
365 | } | |
366 | ||
367 | /* case 32: string -> int */ | |
368 | ||
369 | /* case 33: unicode ... need to do something coherent */ | |
370 | ||
371 | case 34: | |
372 | CAMLreturn(pywrap(((type_34)func)(Int64_val(arg)))); | |
373 | ||
374 | case 35: | |
375 | CAMLreturn(copy_int64(((type_35)func)())); | |
376 | ||
377 | case 36: | |
378 | CAMLreturn(pywrap(((type_36)func)(Double_val(arg)))); | |
379 | ||
380 | case 37: | |
381 | CAMLreturn(copy_double(((type_37)func) | |
382 | (pyunwrap(arg)))); | |
383 | ||
384 | /* case 38: string -> float */ | |
385 | ||
386 | case 39: | |
387 | CAMLreturn(pywrap(((type_39)func)(Int_val(arg)))); | |
388 | ||
389 | case 40: | |
390 | CAMLreturn(pywrap(((type_40)func) | |
391 | (pyunwrap(Field(arg,0)), | |
392 | Int_val(Field(arg,1))))); | |
393 | ||
394 | case 41: | |
395 | CAMLreturn(Val_int(((type_41)func) | |
396 | (pyunwrap(Field(arg,0)), | |
397 | Int_val(Field(arg,1)), | |
398 | pyunwrap(Field(arg,2))))); | |
399 | ||
400 | case 42: | |
401 | CAMLreturn(pywrap(((type_42)func) | |
402 | (pyunwrap(Field(arg,0)), | |
403 | pyunwrap(Field(arg,1)), | |
404 | pyunwrap(Field(arg,2))))); | |
405 | ||
406 | case 43: { | |
407 | int start,end,step; | |
408 | ||
409 | ret_int = ((type_43)func) | |
410 | ((PySliceObject *)pyunwrap(Field(arg,0)), | |
411 | Int_val(Field(arg,1)), | |
412 | &start, &end, &step); | |
413 | if( !ret_int ) CAMLreturn((value)1); | |
414 | else { | |
415 | rv = alloc_tuple(3); | |
416 | Field(rv,0) = start; | |
417 | Field(rv,1) = end; | |
418 | Field(rv,2) = step; | |
419 | CAMLreturn(rv); | |
420 | } | |
421 | } | |
422 | ||
423 | case 44: | |
424 | CAMLreturn(pywrap(((type_44)func) | |
425 | (Int_val(Field(arg,0)), | |
426 | Int_val(Field(arg,1)), | |
427 | Int_val(Field(arg,2)), | |
428 | Int_val(Field(arg,3))))); | |
429 | ||
430 | case 45: | |
431 | ((type_45)func) | |
432 | (pyunwrap(Field(arg,0)), | |
433 | pyunwrap(Field(arg,1))); | |
434 | CAMLreturn(Val_unit); | |
435 | ||
436 | case 46: | |
437 | ((type_46)func) | |
438 | (pyunwrap(Field(arg,0)),String_val(Field(arg,1))); | |
439 | CAMLreturn(Val_unit); | |
440 | ||
441 | case 47: | |
442 | ob1 = pyunwrap(Field(arg,0)); | |
443 | ob2 = pyunwrap(Field(arg,1)); | |
444 | ob3 = pyunwrap(Field(arg,2)); | |
445 | ((type_47)func)(&ob1,&ob2,&ob3); | |
446 | rv = alloc_tuple(3); | |
447 | Field(rv,0) = pywrap(ob1); | |
448 | Field(rv,1) = pywrap(ob2); | |
449 | Field(rv,2) = pywrap(ob3); | |
450 | CAMLreturn(rv); | |
451 | ||
452 | case 48: | |
453 | ((type_48)func) | |
454 | (pyunwrap(Field(arg,0)), | |
455 | pyunwrap(Field(arg,1)), | |
456 | pyunwrap(Field(arg,2))); | |
457 | CAMLreturn(Val_unit); | |
458 | ||
459 | case 49: | |
460 | CAMLreturn(pywrap(((type_49)func) | |
461 | (pyunwrap(Field(arg,0)), | |
462 | String_val(Field(arg,1))))); | |
463 | ||
464 | case 50: | |
465 | CAMLreturn(pywrap(((type_50)func) | |
466 | (String_val(Field(arg,0)), | |
467 | pyunwrap(Field(arg,1)), | |
468 | String_val(Field(arg,2))))); | |
469 | ||
470 | case 51: | |
471 | CAMLreturn(pywrap(((type_51)func) | |
472 | (String_val(Field(arg,0)), | |
473 | pyunwrap(Field(arg,1)), | |
474 | pyunwrap(Field(arg,2)), | |
475 | pyunwrap(Field(arg,3))))); | |
476 | ||
477 | case 52: | |
478 | ((type_52)func)(pyunwrap(arg),&rvs,&ret_int); | |
479 | rv = copy_string(rvs); | |
480 | CAMLreturn(rv); | |
481 | ||
482 | case 53: | |
483 | CAMLreturn(Val_int(((type_53)func) | |
484 | (pyunwrap(Field(arg,0)), | |
485 | Int_val(Field(arg,1)), | |
486 | Int_val(Field(arg,2)), | |
487 | pyunwrap(Field(arg,3))))); | |
488 | ||
489 | case 54: | |
490 | CAMLreturn(Val_int(((type_54)func) | |
491 | (pyunwrap(Field(arg,0)), | |
492 | Int_val(Field(arg,1)), | |
493 | Int_val(Field(arg,2))))); | |
494 | } | |
495 | ||
496 | CAMLreturn(rv); | |
497 | } | |
498 | ||
499 | #ifdef DONT_COMPILE_THIS | |
500 | /* 1 */ | |
501 | DL_IMPORT(void) Py_Initialize(void); | |
502 | DL_IMPORT(void) Py_Finalize(void); | |
503 | DL_IMPORT(void) PyErr_Print(void); | |
504 | /* 2 */ | |
505 | DL_IMPORT(void) Py_Exit(int); | |
506 | DL_IMPORT(void) PyErr_PrintEx(int); | |
507 | /* 3 */ | |
508 | DL_IMPORT(void) Py_SetProgramName(char *); | |
509 | DL_IMPORT(void) Py_SetPythonHome(char *); | |
510 | /* 4 */ | |
511 | DL_IMPORT(int) Py_IsInitialized(void); | |
512 | /* 5 */ | |
513 | DL_IMPORT(int) PyRun_SimpleString(char *); | |
514 | /* 6 */ | |
515 | DL_IMPORT(int) PyRun_AnyFile(FILE *, char *); | |
516 | DL_IMPORT(int) PyRun_SimpleFile(FILE *, char *); | |
517 | DL_IMPORT(int) PyRun_InteractiveOne(FILE *, char *); | |
518 | DL_IMPORT(int) PyRun_InteractiveLoop(FILE *, char *); | |
519 | DL_IMPORT(int) Py_FdIsInteractive(FILE *, char *); | |
520 | /* 7 */ | |
521 | DL_IMPORT(int) PyRun_AnyFileEx(FILE *, char *, int); | |
522 | DL_IMPORT(int) PyRun_SimpleFileEx(FILE *, char *, int); | |
523 | /* 8 */ | |
524 | DL_IMPORT(char*) Py_GetProgramName(void); | |
525 | DL_IMPORT(char*) Py_GetPythonHome(void); | |
526 | DL_IMPORT(char*) Py_GetProgramFullPath(void); | |
527 | DL_IMPORT(char*) Py_GetPrefix(void); | |
528 | DL_IMPORT(char*) Py_GetExecPrefix(void); | |
529 | DL_IMPORT(char*) Py_GetPath(void); | |
530 | DL_IMPORT(char*) Py_GetVersion(void); | |
531 | DL_IMPORT(char*) Py_GetPlatform(void); | |
532 | DL_IMPORT(char*) Py_GetCopyright(void); | |
533 | DL_IMPORT(char*) Py_GetCompiler(void); | |
534 | DL_IMPORT(char*) Py_GetBuildInfo(void); | |
535 | /* 9 */ | |
536 | DL_IMPORT(PyObject*) PyRun_String(char*, int, PyObject *, PyObject *); | |
537 | /* 10 */ | |
538 | DL_IMPORT(PyObject*) PyRun_File(FILE *, char*, int, PyObject *, PyObject *); | |
539 | /* 11 */ | |
540 | DL_IMPORT(PyObject*) PyRun_FileEx(FILE *, char*, int, PyObject *, PyObject *, int ); | |
541 | /* 12 */ | |
542 | DL_IMPORT(PyObject*) Py_CompileString(char*, char*, int); /* FUNCTION 30 */ | |
543 | ||
544 | /* Generic operations on objects */ | |
545 | /* 13 */ | |
546 | extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int); | |
547 | /* 14 */ | |
548 | extern DL_IMPORT(PyObject *) PyObject_Repr(PyObject *); | |
549 | extern DL_IMPORT(PyObject *) PyObject_Str(PyObject *); | |
550 | extern DL_IMPORT(PyObject *) PyObject_Unicode(PyObject *); | |
551 | /* 15 */ | |
552 | extern DL_IMPORT(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int); | |
553 | /* 16 */ | |
554 | extern DL_IMPORT(PyObject *) PyObject_GetAttrString(PyObject *, char *); | |
555 | /* 17 */ | |
556 | extern DL_IMPORT(PyObject *) PyObject_GetAttr(PyObject *, PyObject *); | |
557 | extern DL_IMPORT(PyObject *) PyObject_CallObject(PyObject *, PyObject *); | |
558 | /* 18 */ | |
559 | extern DL_IMPORT(int) PyObject_IsTrue(PyObject *); | |
560 | extern DL_IMPORT(int) PyObject_Not(PyObject *); | |
561 | extern DL_IMPORT(int) PyCallable_Check(PyObject *); | |
562 | /* 19 */ | |
563 | extern DL_IMPORT(int) PyObject_Compare(PyObject *, PyObject *); | |
564 | extern DL_IMPORT(int) PyObject_HasAttr(PyObject *, PyObject *); | |
565 | /* 20 */ | |
566 | extern DL_IMPORT(int) PyObject_RichCompareBool(PyObject *, PyObject *, int); | |
567 | /* 21 */ | |
568 | extern DL_IMPORT(int) PyObject_SetAttrString(PyObject *, char *, PyObject *); | |
569 | /* 22 */ | |
570 | extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *); | |
571 | /* 23 */ | |
572 | extern DL_IMPORT(int) PyNumber_Coerce(PyObject **, PyObject **); | |
573 | extern DL_IMPORT(int) PyNumber_CoerceEx(PyObject **, PyObject **); | |
574 | /* 24 */ | |
575 | extern DL_IMPORT(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *); | |
576 | /* 25 */ | |
577 | extern DL_IMPORT(long) PyObject_Hash(PyObject *); | |
578 | ||
579 | /* Strings */ | |
580 | /* 18 */ | |
581 | extern DL_IMPORT(int) PyString_Size(PyObject *); | |
582 | /* 26 */ | |
583 | extern DL_IMPORT(char *) PyString_AsString(PyObject *); | |
584 | /* 27 */ | |
585 | extern DL_IMPORT(void) PyString_Concat(PyObject **, PyObject *); | |
586 | extern DL_IMPORT(void) PyString_ConcatAndDel(PyObject **, PyObject *); | |
587 | /* 28 */ | |
588 | extern DL_IMPORT(PyObject *) PyString_FromString(const char *); | |
589 | /* 17 */ | |
590 | extern DL_IMPORT(PyObject *) PyString_Format(PyObject *, PyObject *); | |
591 | ||
592 | /* Dictionaries */ | |
593 | /* 29 */ | |
594 | extern DL_IMPORT(PyObject *) PyDict_New(void); | |
595 | /* 17 */ | |
596 | extern DL_IMPORT(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key); | |
597 | /* 24 */ | |
598 | extern DL_IMPORT(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item); | |
599 | /* 19 */ | |
600 | extern DL_IMPORT(int) PyDict_DelItem(PyObject *mp, PyObject *key); | |
601 | /* 30 */ | |
602 | extern DL_IMPORT(void) PyDict_Clear(PyObject *mp); | |
603 | /* 31 */ | |
604 | extern DL_IMPORT(int) PyDict_Next | |
605 | (PyObject *mp, int *pos, PyObject **key, PyObject **value); | |
606 | /* 14 */ | |
607 | extern DL_IMPORT(PyObject *) PyDict_Keys(PyObject *mp); | |
608 | extern DL_IMPORT(PyObject *) PyDict_Values(PyObject *mp); | |
609 | extern DL_IMPORT(PyObject *) PyDict_Items(PyObject *mp); | |
610 | extern DL_IMPORT(PyObject *) PyDict_Copy(PyObject *mp); | |
611 | /* 18 */ | |
612 | extern DL_IMPORT(int) PyDict_Size(PyObject *mp); | |
613 | /* 16 */ | |
614 | extern DL_IMPORT(PyObject *) PyDict_GetItemString(PyObject *dp, char *key); | |
615 | /* 22 */ | |
616 | extern DL_IMPORT(int) PyDict_DelItemString(PyObject *dp, char *key); | |
617 | /* 21 */ | |
618 | extern DL_IMPORT(int) PyDict_SetItemString(PyObject *dp, char *key, PyObject *item); | |
619 | ||
620 | /* Integer */ | |
621 | /* 32 */ | |
622 | extern DL_IMPORT(PyObject *) PyInt_FromString(char*, char**, int); | |
623 | /* 33 */ | |
624 | extern DL_IMPORT(PyObject *) PyInt_FromUnicode(Py_UNICODE*, int, int); | |
625 | /* 34 */ | |
626 | extern DL_IMPORT(PyObject *) PyInt_FromLong(long); | |
627 | /* 25 */ | |
628 | extern DL_IMPORT(long) PyInt_AsLong(PyObject *); | |
629 | /* 35 */ | |
630 | extern DL_IMPORT(long) PyInt_GetMax(void); | |
631 | /* Long */ | |
632 | /* 34 */ | |
633 | extern DL_IMPORT(PyObject *) PyLong_FromLong(long); | |
634 | /* 36 */ | |
635 | extern DL_IMPORT(PyObject *) PyLong_FromDouble(double); | |
636 | /* 25 */ | |
637 | extern DL_IMPORT(long) PyLong_AsLong(PyObject *); | |
638 | ||
639 | /* Float */ | |
640 | /* 36 */ | |
641 | extern DL_IMPORT(PyObject *) PyFloat_FromDouble(double); | |
642 | /* 37 */ | |
643 | extern DL_IMPORT(double) PyFloat_AsDouble(PyObject *); | |
644 | ||
645 | /* Modules */ | |
646 | /* 28 */ | |
647 | extern DL_IMPORT(PyObject *) PyModule_New(char *); | |
648 | /* 14 */ | |
649 | extern DL_IMPORT(PyObject *) PyModule_GetDict(PyObject *); | |
650 | /* 26 */ | |
651 | extern DL_IMPORT(char *) PyModule_GetName(PyObject *); | |
652 | extern DL_IMPORT(char *) PyModule_GetFilename(PyObject *); | |
653 | ||
654 | /* 39 */ | |
655 | extern DL_IMPORT(PyObject *) PyTuple_New(int size); | |
656 | /* 18 */ | |
657 | extern DL_IMPORT(int) PyTuple_Size(PyObject *); | |
658 | extern DL_IMPORT(int) PyTuple_Check(PyObject *); | |
659 | /* 40 */ | |
660 | extern DL_IMPORT(PyObject *) PyTuple_GetItem(PyObject *, int); | |
661 | /* 41 */ | |
662 | extern DL_IMPORT(int) PyTuple_SetItem(PyObject *, int, PyObject *); | |
663 | /* 13 */ | |
664 | extern DL_IMPORT(PyObject *) PyTuple_GetSlice(PyObject *, int, int); | |
665 | ||
666 | /* 42 */ | |
667 | DL_IMPORT(PyObject *) PySlice_New(PyObject* start, PyObject* stop, PyObject* step); | |
668 | /* 43 */ | |
669 | DL_IMPORT(int) PySlice_GetIndices(PySliceObject *r, int length, int *start, int *stop, int *step); | |
670 | /* 44 */ | |
671 | DL_IMPORT(PyObject *) PyRange_New(long, long, long, int); | |
672 | ||
673 | /* Error handling definitions */ | |
674 | ||
675 | /* 30 */ | |
676 | DL_IMPORT(void) PyErr_SetNone(PyObject *); | |
677 | /* 45 */ | |
678 | DL_IMPORT(void) PyErr_SetObject(PyObject *, PyObject *); | |
679 | /* 46 */ | |
680 | DL_IMPORT(void) PyErr_SetString(PyObject *, const char *); | |
681 | /* 29 */ | |
682 | DL_IMPORT(PyObject *) PyErr_Occurred(void); | |
683 | /* 1 */ | |
684 | DL_IMPORT(void) PyErr_Clear(void); | |
685 | /* 47 */ | |
686 | DL_IMPORT(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **); | |
687 | /* 48 */ | |
688 | DL_IMPORT(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); | |
689 | ||
690 | /* Error testing and normalization */ | |
691 | /* 19 */ | |
692 | DL_IMPORT(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); | |
693 | /* 18 */ | |
694 | DL_IMPORT(int) PyErr_ExceptionMatches(PyObject *); | |
695 | /* 47 */ | |
696 | DL_IMPORT(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); | |
697 | ||
698 | /* Classes */ | |
699 | /* 42 */ | |
700 | extern DL_IMPORT(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *); | |
701 | /* 42 */ | |
702 | extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *, | |
703 | PyObject *); | |
704 | /* 17 */ | |
705 | extern DL_IMPORT(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *); | |
706 | /* 42 */ | |
707 | extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *); | |
708 | /* 14 */ | |
709 | extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *); | |
710 | extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *); | |
711 | extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *); | |
712 | ||
713 | /* Module */ | |
714 | /* 28 */ | |
715 | extern DL_IMPORT(PyObject *) PyModule_New(char *); | |
716 | /* 14 */ | |
717 | extern DL_IMPORT(PyObject *) PyModule_GetDict(PyObject *); | |
718 | /* 26 */ | |
719 | extern DL_IMPORT(char *) PyModule_GetName(PyObject *); | |
720 | extern DL_IMPORT(char *) PyModule_GetFilename(PyObject *); | |
721 | /* 35 */ | |
722 | DL_IMPORT(long) PyImport_GetMagicNumber(void); | |
723 | /* 49 */ | |
724 | DL_IMPORT(PyObject *) PyImport_ExecCodeModule(char *name, PyObject *co); | |
725 | /* 50 */ | |
726 | DL_IMPORT(PyObject *) PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname); | |
727 | /* 29 */ | |
728 | DL_IMPORT(PyObject *) PyImport_GetModuleDict(void); | |
729 | /* 28 */ | |
730 | DL_IMPORT(PyObject *) PyImport_AddModule(char *name); | |
731 | DL_IMPORT(PyObject *) PyImport_ImportModule(char *name); | |
732 | /* 51 */ | |
733 | DL_IMPORT(PyObject *) PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist); | |
734 | /* 28 */ | |
735 | DL_IMPORT(PyObject *) PyImport_Import(PyObject *name); | |
736 | /* 14 */ | |
737 | DL_IMPORT(PyObject *) PyImport_ReloadModule(PyObject *m); | |
738 | /* 1 */ | |
739 | DL_IMPORT(void) PyImport_Cleanup(void); | |
740 | /* 5 */ | |
741 | DL_IMPORT(int) PyImport_ImportFrozenModule(char *); | |
742 | ||
743 | /* Interface to random parts in ceval.c */ | |
744 | /* 42 */ | |
745 | DL_IMPORT(PyObject *) PyEval_CallObjectWithKeywords(PyObject *, PyObject *, PyObject *); | |
746 | /* 17 */ | |
747 | DL_IMPORT(PyObject *) PyEval_CallObject(PyObject *, PyObject *); | |
748 | ||
749 | /* 29 */ | |
750 | DL_IMPORT(PyObject *) PyEval_GetBuiltins(void); | |
751 | DL_IMPORT(PyObject *) PyEval_GetGlobals(void); | |
752 | DL_IMPORT(PyObject *) PyEval_GetLocals(void); | |
753 | DL_IMPORT(PyObject *) PyEval_GetFrame(void); | |
754 | /* 4 */ | |
755 | DL_IMPORT(int) PyEval_GetRestricted(void); | |
756 | ||
757 | /* Abstract layer */ | |
758 | /* 14 */ | |
759 | DL_IMPORT(PyObject *) PyObject_Type(PyObject *o); | |
760 | /* 18 */ | |
761 | DL_IMPORT(int) PyObject_Size(PyObject *o); | |
762 | /* 17 */ | |
763 | DL_IMPORT(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); | |
764 | /* 24 */ | |
765 | DL_IMPORT(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); | |
766 | /* 17 */ | |
767 | DL_IMPORT(int) PyObject_DelItem(PyObject *o, PyObject *key); | |
768 | /* 52 */ | |
769 | DL_IMPORT(int) PyObject_AsCharBuffer(PyObject *obj,const char **buffer,int *buffer_len); | |
770 | DL_IMPORT(int) PyObject_AsReadBuffer(PyObject *obj,const void **buffer,int *buffer_len); | |
771 | DL_IMPORT(int) PyObject_AsWriteBuffer(PyObject *obj,void **buffer,int *buffer_len); | |
772 | /* 18 */ | |
773 | DL_IMPORT(int) PyNumber_Check(PyObject *o); | |
774 | /* 17 */ | |
775 | DL_IMPORT(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2); | |
776 | DL_IMPORT(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2); | |
777 | DL_IMPORT(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2); | |
778 | DL_IMPORT(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2); | |
779 | DL_IMPORT(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2); | |
780 | DL_IMPORT(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2); | |
781 | /* 42 */ | |
782 | DL_IMPORT(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,PyObject *o3); | |
783 | /* 14 */ | |
784 | DL_IMPORT(PyObject *) PyNumber_Negative(PyObject *o); | |
785 | DL_IMPORT(PyObject *) PyNumber_Positive(PyObject *o); | |
786 | DL_IMPORT(PyObject *) PyNumber_Absolute(PyObject *o); | |
787 | DL_IMPORT(PyObject *) PyNumber_Invert(PyObject *o); | |
788 | /* 17 */ | |
789 | DL_IMPORT(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2); | |
790 | DL_IMPORT(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2); | |
791 | DL_IMPORT(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2); | |
792 | DL_IMPORT(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2); | |
793 | DL_IMPORT(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2); | |
794 | /* 14 */ | |
795 | DL_IMPORT(PyObject *) PyNumber_Int(PyObject *o); | |
796 | DL_IMPORT(PyObject *) PyNumber_Long(PyObject *o); | |
797 | DL_IMPORT(PyObject *) PyNumber_Float(PyObject *o); | |
798 | /* 17 */ | |
799 | DL_IMPORT(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2); | |
800 | DL_IMPORT(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2); | |
801 | DL_IMPORT(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2); | |
802 | DL_IMPORT(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2); | |
803 | DL_IMPORT(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2); | |
804 | DL_IMPORT(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2); | |
805 | DL_IMPORT(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2); | |
806 | DL_IMPORT(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2); | |
807 | DL_IMPORT(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2); | |
808 | DL_IMPORT(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2); | |
809 | /* 42 */ | |
810 | DL_IMPORT(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,PyObject *o3); | |
811 | /* 18 */ | |
812 | DL_IMPORT(int) PySequence_Check(PyObject *o); | |
813 | DL_IMPORT(int) PySequence_Size(PyObject *o); | |
814 | DL_IMPORT(int) PySequence_Length(PyObject *o); | |
815 | /* 17 */ | |
816 | DL_IMPORT(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2); | |
817 | /* 40 */ | |
818 | DL_IMPORT(PyObject *) PySequence_Repeat(PyObject *o, int count); | |
819 | DL_IMPORT(PyObject *) PySequence_GetItem(PyObject *o, int i); | |
820 | /* 13 */ | |
821 | DL_IMPORT(PyObject *) PySequence_GetSlice(PyObject *o, int i1, int i2); | |
822 | /* 41 */ | |
823 | DL_IMPORT(int) PySequence_SetItem(PyObject *o, int i, PyObject *v); | |
824 | /* 20 */ | |
825 | DL_IMPORT(int) PySequence_DelItem(PyObject *o, int i); | |
826 | /* 53 */ | |
827 | DL_IMPORT(int) PySequence_SetSlice(PyObject *o, int i1, int i2, PyObject *v); | |
828 | /* 54 */ | |
829 | DL_IMPORT(int) PySequence_DelSlice(PyObject *o, int i1, int i2); | |
830 | /* 14 */ | |
831 | DL_IMPORT(PyObject *) PySequence_Tuple(PyObject *o); | |
832 | DL_IMPORT(PyObject *) PySequence_List(PyObject *o); | |
833 | /* 16 */ | |
834 | DL_IMPORT(PyObject *) PySequence_Fast(PyObject *o, const char* m); | |
835 | /* 19 */ | |
836 | DL_IMPORT(int) PySequence_Count(PyObject *o, PyObject *value); | |
837 | DL_IMPORT(int) PySequence_Contains(PyObject *o, PyObject *value); | |
838 | DL_IMPORT(int) PySequence_In(PyObject *o, PyObject *value); | |
839 | DL_IMPORT(int) PySequence_Index(PyObject *o, PyObject *value); | |
840 | /* 17 */ | |
841 | DL_IMPORT(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2); | |
842 | /* 22 */ | |
843 | DL_IMPORT(PyObject *) PySequence_InPlaceRepeat(PyObject *o, int count); | |
844 | /* 18 */ | |
845 | DL_IMPORT(int) PyMapping_Check(PyObject *o); | |
846 | DL_IMPORT(int) PyMapping_Size(PyObject *o); | |
847 | DL_IMPORT(int) PyMapping_Length(PyObject *o); | |
848 | /* 16 */ | |
849 | DL_IMPORT(int) PyMapping_HasKeyString(PyObject *o, char *key); | |
850 | /* 19 */ | |
851 | DL_IMPORT(int) PyMapping_HasKey(PyObject *o, PyObject *key); | |
852 | /* 16 */ | |
853 | DL_IMPORT(PyObject *) PyMapping_GetItemString(PyObject *o, char *key); | |
854 | /* 41 */ | |
855 | DL_IMPORT(int) PyMapping_SetItemString(PyObject *o, char *key, PyObject *value); | |
856 | ||
857 | ||
858 | #ifdef MAYBE_RUN | |
859 | DL_IMPORT(void) init_exceptions(void); | |
860 | DL_IMPORT(void) fini_exceptions(void); | |
861 | DL_IMPORT(void) _PyImport_Init(void); | |
862 | DL_IMPORT(void) _PyImport_Fini(void); | |
863 | DL_IMPORT(void) PyMethod_Fini(void); | |
864 | DL_IMPORT(void) PyFrame_Fini(void); | |
865 | DL_IMPORT(void) PyCFunction_Fini(void); | |
866 | DL_IMPORT(void) PyTuple_Fini(void); | |
867 | DL_IMPORT(void) PyString_Fini(void); | |
868 | DL_IMPORT(void) PyInt_Fini(void); | |
869 | DL_IMPORT(void) PyFloat_Fini(void); | |
870 | DL_IMPORT(PyObject*) _PyBuiltin_Init(void); | |
871 | DL_IMPORT(PyObject*) _PySys_Init(void); | |
872 | DL_IMPORT(struct symtable *) Py_SymtableString(char*, char*, int); | |
873 | DL_IMPORT(struct _node *) PyParser_SimpleParseString(char*, int); | |
874 | DL_IMPORT(struct _node *) PyParser_SimpleParseFile(FILE *, char*, int); | |
875 | DL_IMPORT(int) Py_AtExit(void (*func)(void)); | |
876 | DL_IMPORT(void) Py_EndInterpreter(PyThreadState *); | |
877 | DL_IMPORT(PyThreadState *) Py_NewInterpreter(void); | |
878 | DL_IMPORT(int) (*PyOS_InputHook)(void); | |
879 | DL_IMPORT(int) PyOS_CheckStack(void); | |
880 | DL_IMPORT(char) *(*PyOS_ReadlineFunctionPointer)(char*); | |
881 | DL_IMPORT(PyOS_sighandler_t) PyOS_getsig(int); | |
882 | DL_IMPORT(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t); | |
883 | DL_IMPORT(void) PyOS_FiniInterrupts(void); | |
884 | DL_IMPORT(char*) PyOS_Readline(char*); | |
885 | #endif//MAYBE_RUN | |
886 | #endif//DONT_COMPILE_THIS | |
887 | ||
888 | /* HST FIXUP */ | |
889 | #if (PY_MAJOR_VERSION >= 2 && PY_MINOR_VERSION > 4) | |
890 | #undef PyRun_SimpleString | |
891 | #define PyRun_SimpleString PyRun_SimpleString_redo | |
892 | int PyRun_SimpleString_redo(const char* command) { return PyRun_SimpleStringFlags(command, NULL); } | |
893 | ||
894 | #undef PyRun_AnyFile | |
895 | #define PyRun_AnyFile PyRun_AnyFile_redo | |
896 | int PyRun_AnyFile_redo(FILE* fp, const char* filename) { return PyRun_AnyFileExFlags(fp, filename, 0, NULL); } | |
897 | ||
898 | #undef PyRun_SimpleFile | |
899 | #define PyRun_SimpleFile PyRun_SimpleFile_redo | |
900 | int PyRun_SimpleFile_redo(FILE* fp, const char* filename) { return PyRun_SimpleFileExFlags(fp, filename, 0, NULL); } | |
901 | ||
902 | #undef PyRun_InteractiveOne | |
903 | #define PyRun_InteractiveOne PyRun_InteractiveOne_redo | |
904 | int PyRun_InteractiveOne_redo(FILE* fp, const char* filename) { return PyRun_InteractiveOneFlags(fp, filename, NULL); } | |
905 | ||
906 | #undef PyRun_InteractiveLoop | |
907 | #define PyRun_InteractiveLoop PyRun_InteractiveLoop_redo | |
908 | int PyRun_InteractiveLoop_redo(FILE* fp, const char* filename) { return PyRun_InteractiveLoopFlags(fp, filename, NULL); } | |
909 | ||
910 | #undef PyRun_AnyFileEx | |
911 | #define PyRun_AnyFileEx PyRun_AnyFileEx_redo | |
912 | int PyRun_AnyFileEx_redo(FILE* fp, const char* filename, int closeit) { return PyRun_AnyFileExFlags(fp, filename, closeit, NULL); } | |
913 | ||
914 | #undef PyRun_SimpleFileEx | |
915 | #define PyRun_SimpleFileEx PyRun_SimpleFileEx_redo | |
916 | int PyRun_SimpleFileEx_redo(FILE* fp, const char* filename, int closeit) { return PyRun_SimpleFileExFlags(fp, filename, closeit, NULL); } | |
917 | ||
918 | #undef PyRun_String | |
919 | #define PyRun_String PyRun_String_redo | |
920 | PyObject* PyRun_String_redo(const char* str, int start, PyObject* globals, PyObject* locals) { return PyRun_StringFlags(str, start, globals, locals, NULL); } | |
921 | ||
922 | #undef PyRun_File | |
923 | #define PyRun_File PyRun_File_redo | |
924 | PyObject* PyRun_File_redo(FILE* fp, const char* filename, int start, PyObject* globals, PyObject* locals) { return PyRun_FileExFlags(fp, filename, start, globals, locals, 0, NULL); } | |
925 | ||
926 | #undef PyRun_FileEx | |
927 | #define PyRun_FileEx PyRun_FileEx_redo | |
928 | PyObject* PyRun_FileEx_redo(FILE* fp, const char* filename, int start, PyObject* globals, PyObject* locals, int closeit) { return PyRun_FileExFlags(fp, filename, start, globals, locals, closeit, NULL); } | |
929 | ||
930 | #undef Py_CompileString | |
931 | #define Py_CompileString Py_CompileString_redo | |
932 | PyObject* Py_CompileString_redo(const char* str, const char* filename, int start) { return Py_CompileStringFlags(str, filename, start, NULL); } | |
933 | ||
934 | #undef PyRange_New | |
935 | #define PyRange_New PyRange_New_redo | |
936 | PyObject* PyRange_New_redo(PyObject* start, PyObject* stop, PyObject* step) { return PyObject_CallFunction((PyObject*)&PyRange_Type, "lll", start, stop, step); } | |
937 | #endif /* PYTHON 2.4 */ | |
938 | ||
939 | #undef PyTuple_Check | |
940 | int PyTuple_Check(PyObject* op) { return PyObject_TypeCheck(op, &PyTuple_Type); } | |
941 | /* END HST FIXUP */ | |
942 | ||
943 | /* Value -> Pyobject */ | |
944 | ||
945 | value pywrapvalue( value cb ) { | |
946 | CAMLparam1(cb); | |
947 | CAMLreturn(pywrap(camlwrap(cb,NULL,0))); | |
948 | } | |
949 | ||
950 | value pyunwrapvalue( value cb ) { | |
951 | CAMLparam1(cb); | |
952 | value *v; | |
953 | v = (value *)PyCObject_AsVoidPtr( pyunwrap(cb) ); | |
954 | CAMLreturn(*v); | |
955 | } | |
956 | ||
957 | /* Create the function table */ | |
958 | ||
959 | typedef struct _python_func_table { | |
960 | void *func; | |
961 | int format; | |
962 | char *desc; | |
963 | } python_func_table; | |
964 | ||
965 | python_func_table the_python_func_table[] = { | |
966 | /* 1 */ | |
967 | { (void *)Py_Initialize, 1, "Py_Initialize" }, | |
968 | { (void *)Py_Finalize, 1, "Py_Finalize" }, | |
969 | { (void *)PyErr_Print, 1, "PyErr_Print" }, | |
970 | /* 2 */ | |
971 | { (void *)Py_Exit, 2, "Py_Exit" }, | |
972 | { (void *)PyErr_PrintEx, 2, "PyErr_PrintEx" }, | |
973 | /* 3 */ | |
974 | { (void *)Py_SetProgramName, 3, "Py_SetProgramName" }, | |
975 | { (void *)Py_SetPythonHome, 3, "Py_SetPythonHome" }, | |
976 | /* 4 */ | |
977 | { (void *)Py_IsInitialized, 4, "Py_IsInitialized" }, | |
978 | /* 5 */ | |
979 | { (void *)PyRun_SimpleString, 5, "PyRun_SimpleString" }, | |
980 | /* 6 */ | |
981 | { (void *)PyRun_AnyFile, 6, "PyRun_AnyFile" }, | |
982 | { (void *)PyRun_SimpleFile, 6, "PyRun_SimpleFile" }, | |
983 | { (void *)PyRun_InteractiveOne, 6, "PyRun_InteractiveOne" }, | |
984 | { (void *)PyRun_InteractiveLoop, 6, "PyRun_InteractiveLoop" }, | |
985 | { (void *)Py_FdIsInteractive, 6, "Py_FdIsInteractive" }, | |
986 | /* 7 */ | |
987 | { (void *)PyRun_AnyFileEx, 7, "PyRun_AnyFileEx" }, | |
988 | { (void *)PyRun_SimpleFileEx, 7, "PyRun_SimpleFileEx" }, | |
989 | /* 8 */ | |
990 | { (void *)Py_GetProgramName, 8, "Py_GetProgramName" }, | |
991 | { (void *)Py_GetPythonHome, 8, "Py_GetPythonHome" }, | |
992 | { (void *)Py_GetProgramFullPath, 8, "Py_GetProgramFullPath" }, | |
993 | { (void *)Py_GetPrefix, 8, "Py_GetPrefix" }, | |
994 | { (void *)Py_GetExecPrefix, 8, "Py_GetExecPrefix" }, | |
995 | { (void *)Py_GetPath, 8, "Py_GetPath" }, | |
996 | { (void *)Py_GetVersion, 8, "Py_GetVersion" }, | |
997 | { (void *)Py_GetPlatform, 8, "Py_GetPlatform" }, | |
998 | { (void *)Py_GetCopyright, 8, "Py_GetCopyright" }, | |
999 | { (void *)Py_GetCompiler, 8, "Py_GetCompiler" }, | |
1000 | { (void *)Py_GetBuildInfo, 8, "Py_GetBuildInfo" }, | |
1001 | /* 9 */ | |
1002 | { (void *)PyRun_String, 9, "PyRun_String" }, | |
1003 | /* 10 */ | |
1004 | { (void *)PyRun_File, 10, "PyRun_File" }, | |
1005 | /* 11 */ | |
1006 | { (void *)PyRun_FileEx, 11, "PyRun_FileEx" }, | |
1007 | /* 12 */ | |
1008 | { (void *)Py_CompileString, 12, "Py_CompileString" }, | |
1009 | ||
1010 | /* Object */ | |
1011 | /* 13 */ | |
1012 | { (void *)PyObject_Print, 13, "PyObject_Print" }, | |
1013 | /* 14 */ | |
1014 | { (void *)PyObject_Repr, 14, "PyObject_Repr" }, | |
1015 | { (void *)PyObject_Str, 14, "PyObject_Str" }, | |
1016 | { (void *)PyObject_Unicode, 14, "PyObject_Unicode" }, | |
1017 | /* 15 */ | |
1018 | { (void *)PyObject_RichCompare, 15, "PyObject_RichCompare" }, | |
1019 | /* 16 */ | |
1020 | { (void *)PyObject_GetAttrString, 16, "PyObject_GetAttrString" }, | |
1021 | /* 17 */ | |
1022 | { (void *)PyObject_GetAttr, 17, "PyObject_GetAttr" }, | |
1023 | { (void *)PyObject_CallObject, 17, "PyObject_CallObject" }, | |
1024 | /* 18 */ | |
1025 | { (void *)PyObject_IsTrue, 18, "PyObject_IsTrue" }, | |
1026 | { (void *)PyObject_Not, 18, "PyObject_Not" }, | |
1027 | { (void *)PyCallable_Check, 18, "PyCallable_Check" }, | |
1028 | /* 19 */ | |
1029 | { (void *)PyObject_Compare, 19, "PyObject_Compare" }, | |
1030 | { (void *)PyObject_HasAttr, 19, "PyObject_HasAttr" }, | |
1031 | /* 20 */ | |
1032 | { (void *)PyObject_RichCompareBool, 20, "PyObject_RichCompareBool" }, | |
1033 | /* 21 */ | |
1034 | { (void *)PyObject_SetAttrString, 21, "PyObject_SetAttrString" }, | |
1035 | /* 22 */ | |
1036 | { (void *)PyObject_HasAttrString, 22, "PyObject_HasAttrString" }, | |
1037 | /* 23 */ | |
1038 | { (void *)PyNumber_Coerce, 23, "PyNumber_Coerce" }, | |
1039 | { (void *)PyNumber_CoerceEx, 23, "PyNumber_CoerceEx" }, | |
1040 | /* 24 */ | |
1041 | { (void *)PyObject_SetAttr, 24, "PyObject_SetAttr" }, | |
1042 | /* 25 */ | |
1043 | { (void *)PyObject_Hash, 25, "PyObject_Hash" }, | |
1044 | ||
1045 | /* Strings */ | |
1046 | /* 18 */ | |
1047 | { (void *)PyString_Size, 18, "PyString_Size" }, | |
1048 | /* 26 */ | |
1049 | { (void *)PyString_AsString, 26, "PyString_AsString" }, | |
1050 | /* 27 */ | |
1051 | { (void *)PyString_Concat, 27, "PyString_Concat" }, | |
1052 | { (void *)PyString_ConcatAndDel, 27, "PyString_ConcatAndDel" }, | |
1053 | /* 28 */ | |
1054 | { (void *)PyString_FromString, 28, "PyString_FromString" }, | |
1055 | /* 17 */ | |
1056 | { (void *)PyString_Format, 17, "PyString_Format" }, | |
1057 | ||
1058 | /* Dictionaries */ | |
1059 | /* 29 */ | |
1060 | { (void *)PyDict_New, 29, "PyDict_New" }, | |
1061 | /* 17 */ | |
1062 | { (void *)PyDict_GetItem, 17, "PyDict_GetItem" }, | |
1063 | /* 24 */ | |
1064 | { (void *)PyDict_SetItem, 24, "PyDict_SetItem" }, | |
1065 | /* 19 */ | |
1066 | { (void *)PyDict_DelItem, 19, "PyDict_DelItem" }, | |
1067 | /* 30 */ | |
1068 | { (void *)PyDict_Clear, 30, "PyDict_Clear" }, | |
1069 | /* 31 */ | |
1070 | { (void *)PyDict_Next, 31, "PyDict_Next" }, | |
1071 | /* 14 */ | |
1072 | { (void *)PyDict_Keys, 14, "PyDict_Keys" }, | |
1073 | { (void *)PyDict_Values, 14, "PyDict_Values" }, | |
1074 | { (void *)PyDict_Items, 14, "PyDict_Items" }, | |
1075 | { (void *)PyDict_Copy, 14, "PyDict_Copy" }, | |
1076 | /* 18 */ | |
1077 | { (void *)PyDict_Size, 18, "PyDict_Size" }, | |
1078 | /* 16 */ | |
1079 | { (void *)PyDict_GetItemString, 16, "PyDict_GetItemString" }, | |
1080 | /* 22 */ | |
1081 | { (void *)PyDict_DelItemString, 22, "PyDict_DelItemString" }, | |
1082 | /* 21 */ | |
1083 | { (void *)PyDict_SetItemString, 21, "PyDict_SetItemString" }, | |
1084 | ||
1085 | /* Integer */ | |
1086 | /* 34 */ | |
1087 | { (void *)PyInt_FromLong, 34, "PyInt_FromLong" }, | |
1088 | /* 25 */ | |
1089 | { (void *)PyInt_AsLong, 25, "PyInt_AsLong" }, | |
1090 | /* 35 */ | |
1091 | { (void *)PyInt_GetMax, 35, "PyInt_GetMax" }, | |
1092 | ||
1093 | /* Float */ | |
1094 | /* 36 */ | |
1095 | { (void *)PyFloat_FromDouble, 36, "PyFloat_FromDouble" }, | |
1096 | /* 37 */ | |
1097 | { (void *)PyFloat_AsDouble, 37, "PyFloat_AsDouble" }, | |
1098 | ||
1099 | /* Modules */ | |
1100 | /* 28 */ | |
1101 | { (void *)PyModule_New, 28, "PyModule_New" }, | |
1102 | /* 14 */ | |
1103 | { (void *)PyModule_GetDict, 14, "PyModule_GetDict" }, | |
1104 | /* 26 */ | |
1105 | { (void *)PyModule_GetName, 26, "PyModule_GetName" }, | |
1106 | { (void *)PyModule_GetFilename, 26, "PyModule_GetFilename" }, | |
1107 | ||
1108 | /* 39 */ | |
1109 | { (void *)PyTuple_New, 39, "PyTuple_New" }, | |
1110 | /* 18 */ | |
1111 | { (void *)PyTuple_Size, 18, "PyTuple_Size" }, | |
1112 | { (void *)PyTuple_Check, 18, "PyTuple_Check" }, | |
1113 | /* 40 */ | |
1114 | { (void *)PyTuple_GetItem, 40, "PyTuple_GetItem" }, | |
1115 | /* 41 */ | |
1116 | { (void *)PyTuple_SetItem, 41, "PyTuple_SetItem" }, | |
1117 | /* 13 */ | |
1118 | { (void *)PyTuple_GetSlice, 13, "PyTuple_GetSlice" }, | |
1119 | ||
1120 | /* 42 */ | |
1121 | { (void *)PySlice_New, 42, "PySlice_New" }, | |
1122 | /* 43 */ | |
1123 | { (void *)PySlice_GetIndices, 43, "PySlice_GetIndices" }, | |
1124 | /* 44 */ | |
1125 | { (void *)PyRange_New, 44, "PyRange_New" }, | |
1126 | ||
1127 | /* Error handling definitions */ | |
1128 | ||
1129 | /* 30 */ | |
1130 | { (void *)PyErr_SetNone, 30, "PyErr_SetNone" }, | |
1131 | /* 45 */ | |
1132 | { (void *)PyErr_SetObject, 45, "PyErr_SetObject" }, | |
1133 | /* 46 */ | |
1134 | { (void *)PyErr_SetString, 46, "PyErr_SetString" }, | |
1135 | /* 29 */ | |
1136 | { (void *)PyErr_Occurred, 29, "PyErr_Occurred" }, | |
1137 | /* 1 */ | |
1138 | { (void *)PyErr_Clear, 1, "PyErr_Clear" }, | |
1139 | /* 47 */ | |
1140 | { (void *)PyErr_Fetch, 47, "PyErr_Fetch" }, | |
1141 | /* 48 */ | |
1142 | { (void *)PyErr_Restore, 48, "PyErr_Restore" }, | |
1143 | ||
1144 | /* Error testing and normalization */ | |
1145 | /* 19 */ | |
1146 | { (void *)PyErr_GivenExceptionMatches, 19, "PyErr_GivenExceptionMatches" }, | |
1147 | /* 18 */ | |
1148 | { (void *)PyErr_ExceptionMatches, 18, "PyErr_ExceptionMatches" }, | |
1149 | /* 47 */ | |
1150 | { (void *)PyErr_NormalizeException, 47, "PyErr_NormalizeException" }, | |
1151 | ||
1152 | /* Classes */ | |
1153 | /* 42 */ | |
1154 | { (void *)PyClass_New, 42, "PyClass_New" }, | |
1155 | /* 42 */ | |
1156 | { (void *)PyInstance_New, 42, "PyInstance_New" }, | |
1157 | ||
1158 | /* 17 */ | |
1159 | { (void *)PyInstance_NewRaw, 17, "PyInstance_NewRaw" }, | |
1160 | /* 42 */ | |
1161 | { (void *)PyMethod_New, 42, "PyMethod_New" }, | |
1162 | /* 14 */ | |
1163 | { (void *)PyMethod_Function, 14, "PyMethod_Function" }, | |
1164 | { (void *)PyMethod_Self, 14, "PyMethod_Self" }, | |
1165 | { (void *)PyMethod_Class, 14, "PyMethod_Class" }, | |
1166 | ||
1167 | /* Module */ | |
1168 | /* 28 */ | |
1169 | { (void *)PyModule_New, 28, "PyModule_New" }, | |
1170 | /* 14 */ | |
1171 | { (void *)PyModule_GetDict, 14, "PyModule_GetDict" }, | |
1172 | /* 26 */ | |
1173 | { (void *)PyModule_GetName, 26, "PyModule_GetName" }, | |
1174 | { (void *)PyModule_GetFilename, 26, "PyModule_GetFilename" }, | |
1175 | /* 35 */ | |
1176 | { (void *)PyImport_GetMagicNumber, 35, "PyImport_GetMagicNumber" }, | |
1177 | /* 49 */ | |
1178 | { (void *)PyImport_ExecCodeModule, 49, "PyImport_ExecCodeModule" }, | |
1179 | /* 50 */ | |
1180 | { (void *)PyImport_ExecCodeModuleEx, 50, "PyImport_ExecCodeModuleEx" }, | |
1181 | /* 29 */ | |
1182 | { (void *)PyImport_GetModuleDict, 29, "PyImport_GetModuleDict" }, | |
1183 | /* 28 */ | |
1184 | { (void *)PyImport_AddModule, 28, "PyImport_AddModule" }, | |
1185 | { (void *)PyImport_ImportModule, 28, "PyImport_ImportModule" }, | |
1186 | /* 51 */ | |
0708f913 C |
1187 | #if 0 |
1188 | /* In Python 2.6, this because a #define so we cannot take | |
1189 | * the address of the function. - RWMJ. | |
1190 | */ | |
34e49164 | 1191 | { (void *)PyImport_ImportModuleEx, 51, "PyImport_ImportModuleEx" }, |
0708f913 | 1192 | #endif |
34e49164 C |
1193 | /* 28 */ |
1194 | { (void *)PyImport_Import, 28, "PyImport_Import" }, | |
1195 | /* 14 */ | |
1196 | { (void *)PyImport_ReloadModule, 14, "PyImport_ReloadModule" }, | |
1197 | /* 1 */ | |
1198 | { (void *)PyImport_Cleanup, 1, "PyImport_Cleanup" }, | |
1199 | /* 5 */ | |
1200 | { (void *)PyImport_ImportFrozenModule, 5, "PyImport_ImportFrozenModule" }, | |
1201 | ||
1202 | /* Interface to random parts in ceval.c */ | |
1203 | /* 42 */ | |
1204 | { (void *)PyEval_CallObjectWithKeywords, 42, "PyEval_CallObjectWithKeywords" }, | |
1205 | /* 17 */ | |
1206 | { (void *)PyEval_CallObject, 17, "PyEval_CallObject" }, | |
1207 | ||
1208 | /* 29 */ | |
1209 | { (void *)PyEval_GetBuiltins, 29, "PyEval_GetBuiltins" }, | |
1210 | { (void *)PyEval_GetGlobals, 29, "PyEval_GetGlobals" }, | |
1211 | { (void *)PyEval_GetLocals, 29, "PyEval_GetLocals" }, | |
1212 | { (void *)PyEval_GetFrame, 29, "PyEval_GetFrame" }, | |
1213 | /* 4 */ | |
1214 | { (void *)PyEval_GetRestricted, 4, "PyEval_GetRestricted" }, | |
1215 | ||
1216 | /* Abstract layer */ | |
1217 | /* 14 */ | |
1218 | { (void *)PyObject_Type, 14, "PyObject_Type" }, | |
1219 | /* 18 */ | |
1220 | { (void *)PyObject_Size, 18, "PyObject_Size" }, | |
1221 | /* 17 */ | |
1222 | { (void *)PyObject_GetItem, 17, "PyObject_GetItem" }, | |
1223 | /* 24 */ | |
1224 | { (void *)PyObject_SetItem, 24, "PyObject_SetItem" }, | |
1225 | /* 17 */ | |
1226 | { (void *)PyObject_DelItem, 17, "PyObject_DelItem" }, | |
1227 | /* 52 */ | |
1228 | { (void *)PyObject_AsCharBuffer, 52, "PyObject_AsCharBuffer" }, | |
1229 | { (void *)PyObject_AsReadBuffer, 52, "PyObject_AsReadBuffer" }, | |
1230 | { (void *)PyObject_AsWriteBuffer, 52, "PyObject_AsWriteBuffer" }, | |
1231 | /* 18 */ | |
1232 | { (void *)PyNumber_Check, 18, "PyNumber_Check" }, | |
1233 | /* 17 */ | |
1234 | { (void *)PyNumber_Add, 17, "PyNumber_Add" }, | |
1235 | { (void *)PyNumber_Subtract, 17, "PyNumber_Subtract" }, | |
1236 | { (void *)PyNumber_Multiply, 17, "PyNumber_Multiply" }, | |
1237 | { (void *)PyNumber_Divide, 17, "PyNumber_Divide" }, | |
1238 | { (void *)PyNumber_Remainder, 17, "PyNumber_Remainder" }, | |
1239 | { (void *)PyNumber_Divmod, 17, "PyNumber_Divmod" }, | |
1240 | /* 42 */ | |
1241 | { (void *)PyNumber_Power, 42, "PyNumber_Power" }, | |
1242 | /* 14 */ | |
1243 | { (void *)PyNumber_Negative, 14, "PyNumber_Negative" }, | |
1244 | { (void *)PyNumber_Positive, 14, "PyNumber_Positive" }, | |
1245 | { (void *)PyNumber_Absolute, 14, "PyNumber_Absolute" }, | |
1246 | { (void *)PyNumber_Invert, 14, "PyNumber_Invert" }, | |
1247 | /* 17 */ | |
1248 | { (void *)PyNumber_Lshift, 17, "PyNumber_Lshift" }, | |
1249 | { (void *)PyNumber_Rshift, 17, "PyNumber_Rshift" }, | |
1250 | { (void *)PyNumber_And, 17, "PyNumber_And" }, | |
1251 | { (void *)PyNumber_Xor, 17, "PyNumber_Xor" }, | |
1252 | { (void *)PyNumber_Or, 17, "PyNumber_Or" }, | |
1253 | /* 14 */ | |
1254 | { (void *)PyNumber_Int, 14, "PyNumber_Int" }, | |
1255 | { (void *)PyNumber_Long, 14, "PyNumber_Long" }, | |
1256 | { (void *)PyNumber_Float, 14, "PyNumber_Float" }, | |
1257 | /* 17 */ | |
1258 | { (void *)PyNumber_InPlaceAdd, 17, "PyNumber_InPlaceAdd" }, | |
1259 | { (void *)PyNumber_InPlaceSubtract, 17, "PyNumber_InPlaceSubtract" }, | |
1260 | { (void *)PyNumber_InPlaceMultiply, 17, "PyNumber_InPlaceMultiply" }, | |
1261 | { (void *)PyNumber_InPlaceDivide, 17, "PyNumber_InPlaceDivide" }, | |
1262 | { (void *)PyNumber_InPlaceRemainder, 17, "PyNumber_InPlaceRemainder" }, | |
1263 | { (void *)PyNumber_InPlaceLshift, 17, "PyNumber_InPlaceLshift" }, | |
1264 | { (void *)PyNumber_InPlaceRshift, 17, "PyNumber_InPlaceRshift" }, | |
1265 | { (void *)PyNumber_InPlaceAnd, 17, "PyNumber_InPlaceAnd" }, | |
1266 | { (void *)PyNumber_InPlaceXor, 17, "PyNumber_InPlaceXor" }, | |
1267 | { (void *)PyNumber_InPlaceOr, 17, "PyNumber_InPlaceOr" }, | |
1268 | /* 42 */ | |
1269 | { (void *)PyNumber_InPlacePower, 42, "PyNumber_InPlacePower" }, | |
1270 | /* 18 */ | |
1271 | { (void *)PySequence_Check, 18, "PySequence_Check" }, | |
1272 | { (void *)PySequence_Size, 18, "PySequence_Size" }, | |
1273 | { (void *)PySequence_Length, 18, "PySequence_Length" }, | |
1274 | /* 17 */ | |
1275 | { (void *)PySequence_Concat, 17, "PySequence_Concat" }, | |
1276 | /* 40 */ | |
1277 | { (void *)PySequence_Repeat, 40, "PySequence_Repeat" }, | |
1278 | { (void *)PySequence_GetItem, 40, "PySequence_GetItem" }, | |
1279 | /* 13 */ | |
1280 | { (void *)PySequence_GetSlice, 13, "PySequence_GetSlice" }, | |
1281 | /* 41 */ | |
1282 | { (void *)PySequence_SetItem, 41, "PySequence_SetItem" }, | |
1283 | /* 20 */ | |
1284 | { (void *)PySequence_DelItem, 20, "PySequence_DelItem" }, | |
1285 | /* 53 */ | |
1286 | { (void *)PySequence_SetSlice, 53, "PySequence_SetSlice" }, | |
1287 | /* 54 */ | |
1288 | { (void *)PySequence_DelSlice, 54, "PySequence_DelSlice" }, | |
1289 | /* 14 */ | |
1290 | { (void *)PySequence_Tuple, 14, "PySequence_Tuple" }, | |
1291 | { (void *)PySequence_List, 14, "PySequence_List" }, | |
1292 | /* 16 */ | |
1293 | { (void *)PySequence_Fast, 16, "PySequence_Fast" }, | |
1294 | /* 19 */ | |
1295 | { (void *)PySequence_Count, 19, "PySequence_Count" }, | |
1296 | { (void *)PySequence_Contains, 19, "PySequence_Contains" }, | |
1297 | { (void *)PySequence_In, 19, "PySequence_In" }, | |
1298 | { (void *)PySequence_Index, 19, "PySequence_Index" }, | |
1299 | /* 17 */ | |
1300 | { (void *)PySequence_InPlaceConcat, 17, "PySequence_InPlaceConcat" }, | |
1301 | /* 22 */ | |
1302 | { (void *)PySequence_InPlaceRepeat, 22, "PySequence_InPlaceRepeat" }, | |
1303 | /* 18 */ | |
1304 | { (void *)PyMapping_Check, 18, "PyMapping_Check" }, | |
1305 | { (void *)PyMapping_Size, 18, "PyMapping_Size" }, | |
1306 | { (void *)PyMapping_Length, 18, "PyMapping_Length" }, | |
1307 | /* 16 */ | |
1308 | { (void *)PyMapping_HasKeyString, 16, "PyMapping_HasKeyString" }, | |
1309 | /* 19 */ | |
1310 | { (void *)PyMapping_HasKey, 19, "PyMapping_HasKey" }, | |
1311 | /* 16 */ | |
1312 | { (void *)PyMapping_GetItemString, 16, "PyMapping_GetItemString" }, | |
1313 | /* 41 */ | |
1314 | { (void *)PyMapping_SetItemString, 41, "PyMapping_SetItemString" }, | |
1315 | ||
1316 | /* End */ | |
1317 | { NULL, 0 } | |
1318 | }; | |
1319 | ||
1320 | value pygetfuncarray( value unit ) { | |
1321 | CAMLparam1(unit); | |
1322 | CAMLlocal2(retv,tuplev); | |
1323 | int i; | |
1324 | int total_funcs; | |
1325 | ||
1326 | for( i = 0; the_python_func_table[i].func; i++ ) ; total_funcs = i; | |
1327 | ||
1328 | retv = alloc(total_funcs,0); | |
1329 | ||
1330 | for( i = 0; i < total_funcs; i++ ) { | |
1331 | tuplev = alloc_tuple( 3 ); | |
1332 | Store_field(tuplev,0,funcwrap((void *)the_python_func_table[i].func)); | |
1333 | Store_field(tuplev,1,Val_int(the_python_func_table[i].format)); | |
1334 | Store_field(tuplev,2,Val_int(i)); | |
1335 | Store_field(retv,i,tuplev); | |
1336 | } | |
1337 | ||
1338 | CAMLreturn(retv); | |
1339 | } | |
1340 | ||
1341 | enum PycamlTypeLabels { | |
1342 | TupleType = 0, | |
1343 | StringType, | |
1344 | IntType, | |
1345 | FloatType, | |
1346 | ListType, | |
1347 | NoneType, | |
1348 | CallableType, | |
1349 | ModuleType, | |
1350 | ClassType, | |
1351 | TypeType, | |
1352 | DictType, | |
1353 | NullType, | |
1354 | OtherType | |
1355 | }; | |
1356 | ||
1357 | value pytype( value obj ) { | |
1358 | CAMLparam1(obj); | |
1359 | PyObject *pobj = pyunwrap( obj ); | |
1360 | if( !pobj ) CAMLreturn(NullType); | |
1361 | else if( PyTuple_Check( pobj ) ) CAMLreturn(Val_int(TupleType)); | |
1362 | else if( PyString_Check( pobj ) ) CAMLreturn(Val_int(StringType)); | |
1363 | else if( PyInt_Check( pobj ) ) CAMLreturn(Val_int(IntType)); | |
1364 | else if( PyFloat_Check( pobj ) ) CAMLreturn(Val_int(FloatType)); | |
1365 | else if( PyList_Check( pobj ) ) CAMLreturn(Val_int(ListType)); | |
1366 | else if( pobj == Py_None ) CAMLreturn(Val_int(NoneType)); | |
1367 | else if( PyCallable_Check( pobj ) ) CAMLreturn(Val_int(CallableType)); | |
1368 | else if( PyModule_Check( pobj ) ) CAMLreturn(Val_int(ModuleType)); | |
1369 | else if( PyClass_Check( pobj ) ) CAMLreturn(Val_int(ClassType)); | |
1370 | else if( PyType_Check( pobj ) ) CAMLreturn(Val_int(TypeType)); | |
1371 | else if( PyDict_Check( pobj ) ) CAMLreturn(Val_int(DictType)); | |
1372 | else CAMLreturn(Val_int(OtherType)); | |
1373 | } | |
1374 | ||
1375 | value pynull( value unit ) { | |
1376 | CAMLparam1(unit); | |
1377 | CAMLreturn(pywrap(NULL)); | |
1378 | } | |
1379 | ||
1380 | value pynone( value unit ) { | |
1381 | CAMLparam1(unit); | |
1382 | CAMLreturn(pywrap(Py_None)); | |
1383 | } | |
1384 | ||
1385 | value pytuple_fromarray( value array ) { | |
1386 | CAMLparam1(array); | |
1387 | PyObject *tuple = PyTuple_New(Wosize_val(array)); | |
1388 | PyObject *elt; | |
1389 | int i; | |
1390 | int x; | |
1391 | ||
1392 | for( i = 0; i < Wosize_val(array); i++ ) { | |
1393 | elt = pyunwrap(Field(array,i)); | |
1394 | Py_INCREF(elt); /* PyTuple_SetItem will steal a reference */ | |
1395 | x = PyTuple_SetItem(tuple,i,elt); | |
1396 | } | |
1397 | ||
1398 | CAMLreturn(pywrap(tuple)); | |
1399 | } | |
1400 | ||
1401 | value pytuple_toarray( value array ) { | |
1402 | CAMLparam1(array); | |
1403 | PyObject *obj = pyunwrap(array); | |
1404 | int i; | |
1405 | CAMLlocal1(rv); | |
1406 | ||
1407 | rv = alloc_tuple( PySequence_Size(obj) ); | |
1408 | ||
1409 | for( i = 0; i < PySequence_Size(obj); i++ ) | |
1410 | Store_field(rv,i,pywrap(PySequence_GetItem(obj,i))); | |
1411 | ||
1412 | CAMLreturn(rv); | |
1413 | } | |
1414 | ||
1415 | value pywrap_closure( value closure ) { | |
1416 | CAMLparam1(closure); | |
1417 | PyMethodDef ml; | |
1418 | PyObject *obj; | |
1419 | PyMethodDef *ml_def; | |
1420 | ml.ml_name = "anonymous_closure"; | |
1421 | ml.ml_meth = pycall_callback; | |
1422 | ml.ml_flags = 1; | |
1423 | ml.ml_doc = "Anonymous closure"; | |
1424 | obj = camlwrap(closure,&ml,sizeof(ml)); | |
1425 | ml_def = (PyMethodDef *)caml_aux(obj); | |
1426 | CAMLreturn(pywrap(PyCFunction_New(ml_def,obj))); | |
1427 | } | |
1428 | ||
1429 | value pymodule_initmodule( value name, value funclist ) { | |
1430 | CAMLparam2(name,funclist); | |
1431 | int i; | |
1432 | PyMethodDef *methods = malloc( sizeof( PyMethodDef ) * | |
1433 | Wosize_val(funclist) ); | |
1434 | CAMLlocal1(item); | |
1435 | ||
1436 | PyImport_AddModule( String_val(name) ); | |
1437 | ||
1438 | for( i = 0; i < Wosize_val(funclist); i++ ) { | |
1439 | item = Field(funclist,i); | |
1440 | methods[i].ml_name = String_val(Field(item,0)); | |
1441 | methods[i].ml_meth = pywrap_closure(Field(item,1)); | |
1442 | methods[i].ml_flags = Int_val(Field(item,2)); | |
1443 | methods[i].ml_doc = String_val(Field(item,3)); | |
1444 | } | |
1445 | ||
1446 | Py_InitModule( String_val(name), methods ); | |
1447 | ||
1448 | free( methods ); | |
1449 | ||
1450 | CAMLreturn(Val_unit); | |
1451 | } | |
1452 | ||
1453 | value pycaml_setargs(value argv) { | |
1454 | CAMLparam1(argv); | |
1455 | char* cargv[1]; | |
1456 | ||
1457 | cargv[0] = String_val(argv); | |
1458 | ||
1459 | PySys_SetArgv(1, cargv); | |
1460 | ||
1461 | CAMLreturn0; | |
1462 | } | |
1463 | ||
1464 | value pytrue( value unit ) { | |
1465 | CAMLparam1(unit); | |
1466 | CAMLreturn(pywrap(Py_True)); | |
1467 | } | |
1468 | ||
1469 | value pyfalse(value unit) { | |
1470 | CAMLparam1(unit); | |
1471 | CAMLreturn(pywrap(Py_False)); | |
1472 | } |