Release coccinelle-0.2.3rc2
[bpt/coccinelle.git] / pycaml / pycaml_ml.c
CommitLineData
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
17static void *getcustom( value v ) { return *((void **)Data_custom_val(v)); }
18
19static void pydecref( value v ) {
20 if( getcustom(v) ) { Py_DECREF((PyObject *)getcustom(v)); }
21}
22
23static 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
33static long pyhash( value v ) {
34 if( getcustom(v) ) return PyObject_Hash((PyObject *)getcustom(v));
35 else return 0;
36}
37
38static unsigned long pydeserialize( void *dst ) {
39 return 0;
40}
41
42struct custom_operations pyops = {
43 "PythonObject",
44 pydecref,
45 pycompare,
46 pyhash,
47 custom_serialize_default,
48 pydeserialize
49};
50
51struct custom_operations fnops = {
52 "FuncPointer",
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL
58};
59
60value 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
70value 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
78PyObject *pyunwrap( value v ) {
79 return *((PyObject **)Data_custom_val(v));
80}
81
82static void camldestr( void *v ) {
83 value *valptr = (value *)v;
84 remove_global_root(valptr);
85 free( v );
86}
87
88PyObject *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
96void *caml_aux( PyObject *obj ) {
97 value *v = (value *)PyCObject_AsVoidPtr( obj );
98 return (void *)v+sizeof(value);
99}
100
101PyObject *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
114typedef void (*type_1)( void );
115typedef void (*type_2)( int );
116typedef void (*type_3)( char * );
117typedef int (*type_4)( void );
118typedef int (*type_5)( char * );
119typedef int (*type_6)( FILE *, char * );
120typedef int (*type_7)( FILE *, char *, int );
121typedef char *(*type_8)( void );
122typedef PyObject* (*type_9)(char*, int, PyObject *, PyObject *);
123typedef PyObject* (*type_10)(FILE *, char*, int, PyObject *, PyObject *);
124typedef PyObject* (*type_11)(FILE *, char*, int, PyObject *, PyObject *, int );
125typedef PyObject* (*type_12)(char*, char*, int);
126typedef int (*type_13)(PyObject *, FILE *, int);
127typedef PyObject * (*type_14)(PyObject *);
128typedef PyObject * (*type_15)(PyObject *, PyObject *, int);
129typedef PyObject * (*type_16)(PyObject *, char *);
130typedef PyObject * (*type_17)(PyObject *, PyObject *);
131typedef int (*type_18)(PyObject *);
132typedef int (*type_19)(PyObject *, PyObject *);
133typedef int (*type_20)(PyObject *, PyObject *, int);
134typedef int (*type_21)(PyObject *, char *, PyObject *);
135typedef int (*type_22)(PyObject *, char *);
136typedef int (*type_23)(PyObject **, PyObject **);
137typedef int (*type_24)(PyObject *, PyObject *, PyObject *);
138typedef long (*type_25)(PyObject *);
139typedef char *(*type_26)(PyObject *);
140typedef void (*type_27)(PyObject **, PyObject *);
141typedef PyObject *(*type_28)(char *);
142typedef PyObject *(*type_29)(void);
143typedef void (*type_30)(PyObject *);
144typedef int (*type_31)(PyObject *, int *, PyObject **, PyObject **);
145typedef PyObject *(*type_32)(char*, char**, int);
146typedef PyObject *(*type_33)(Py_UNICODE*, int, int);
147typedef PyObject *(*type_34)(long);
148typedef long (*type_35)(void);
149typedef PyObject *(*type_36)(double);
150typedef double (*type_37)(PyObject *);
151typedef PyObject *(*type_38)(PyObject*, char**);
152typedef PyObject *(*type_39)(int size);
153typedef PyObject *(*type_40)(PyObject *, int);
154typedef int (*type_41)(PyObject *, int, PyObject *);
155typedef PyObject *(*type_42)(PyObject* start, PyObject* stop, PyObject* step);
156typedef int (*type_43)(PySliceObject *r, int length, int *start, int *stop, int *step);
157typedef PyObject *(*type_44)(long, long, long, int);
158typedef void (*type_45)(PyObject *, PyObject *);
159typedef void (*type_46)(PyObject *, const char *);
160typedef void (*type_47)(PyObject **, PyObject **, PyObject **);
161typedef void (*type_48)(PyObject *, PyObject *, PyObject *);
162typedef PyObject *(*type_49)(PyObject *, char *);
163typedef PyObject *(*type_50)(char *,PyObject *,char *);
164typedef PyObject *(*type_51)(char *,PyObject *,PyObject *,PyObject *);
165typedef int (*type_52)(PyObject *obj,const char **buffer,int *buffer_len);
166typedef int (*type_53)(PyObject *o, int i1, int i2, PyObject *v);
167typedef int (*type_54)(PyObject *o, int i1, int i2);
168
169value 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 */
501DL_IMPORT(void) Py_Initialize(void);
502DL_IMPORT(void) Py_Finalize(void);
503DL_IMPORT(void) PyErr_Print(void);
504/* 2 */
505DL_IMPORT(void) Py_Exit(int);
506DL_IMPORT(void) PyErr_PrintEx(int);
507/* 3 */
508DL_IMPORT(void) Py_SetProgramName(char *);
509DL_IMPORT(void) Py_SetPythonHome(char *);
510/* 4 */
511DL_IMPORT(int) Py_IsInitialized(void);
512/* 5 */
513DL_IMPORT(int) PyRun_SimpleString(char *);
514/* 6 */
515DL_IMPORT(int) PyRun_AnyFile(FILE *, char *);
516DL_IMPORT(int) PyRun_SimpleFile(FILE *, char *);
517DL_IMPORT(int) PyRun_InteractiveOne(FILE *, char *);
518DL_IMPORT(int) PyRun_InteractiveLoop(FILE *, char *);
519DL_IMPORT(int) Py_FdIsInteractive(FILE *, char *);
520/* 7 */
521DL_IMPORT(int) PyRun_AnyFileEx(FILE *, char *, int);
522DL_IMPORT(int) PyRun_SimpleFileEx(FILE *, char *, int);
523/* 8 */
524DL_IMPORT(char*) Py_GetProgramName(void);
525DL_IMPORT(char*) Py_GetPythonHome(void);
526DL_IMPORT(char*) Py_GetProgramFullPath(void);
527DL_IMPORT(char*) Py_GetPrefix(void);
528DL_IMPORT(char*) Py_GetExecPrefix(void);
529DL_IMPORT(char*) Py_GetPath(void);
530DL_IMPORT(char*) Py_GetVersion(void);
531DL_IMPORT(char*) Py_GetPlatform(void);
532DL_IMPORT(char*) Py_GetCopyright(void);
533DL_IMPORT(char*) Py_GetCompiler(void);
534DL_IMPORT(char*) Py_GetBuildInfo(void);
535/* 9 */
536DL_IMPORT(PyObject*) PyRun_String(char*, int, PyObject *, PyObject *);
537/* 10 */
538DL_IMPORT(PyObject*) PyRun_File(FILE *, char*, int, PyObject *, PyObject *);
539/* 11 */
540DL_IMPORT(PyObject*) PyRun_FileEx(FILE *, char*, int, PyObject *, PyObject *, int );
541/* 12 */
542DL_IMPORT(PyObject*) Py_CompileString(char*, char*, int); /* FUNCTION 30 */
543
544/* Generic operations on objects */
545/* 13 */
546extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int);
547/* 14 */
548extern DL_IMPORT(PyObject *) PyObject_Repr(PyObject *);
549extern DL_IMPORT(PyObject *) PyObject_Str(PyObject *);
550extern DL_IMPORT(PyObject *) PyObject_Unicode(PyObject *);
551/* 15 */
552extern DL_IMPORT(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
553/* 16 */
554extern DL_IMPORT(PyObject *) PyObject_GetAttrString(PyObject *, char *);
555/* 17 */
556extern DL_IMPORT(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
557extern DL_IMPORT(PyObject *) PyObject_CallObject(PyObject *, PyObject *);
558/* 18 */
559extern DL_IMPORT(int) PyObject_IsTrue(PyObject *);
560extern DL_IMPORT(int) PyObject_Not(PyObject *);
561extern DL_IMPORT(int) PyCallable_Check(PyObject *);
562/* 19 */
563extern DL_IMPORT(int) PyObject_Compare(PyObject *, PyObject *);
564extern DL_IMPORT(int) PyObject_HasAttr(PyObject *, PyObject *);
565/* 20 */
566extern DL_IMPORT(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
567/* 21 */
568extern DL_IMPORT(int) PyObject_SetAttrString(PyObject *, char *, PyObject *);
569/* 22 */
570extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *);
571/* 23 */
572extern DL_IMPORT(int) PyNumber_Coerce(PyObject **, PyObject **);
573extern DL_IMPORT(int) PyNumber_CoerceEx(PyObject **, PyObject **);
574/* 24 */
575extern DL_IMPORT(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
576/* 25 */
577extern DL_IMPORT(long) PyObject_Hash(PyObject *);
578
579/* Strings */
580/* 18 */
581extern DL_IMPORT(int) PyString_Size(PyObject *);
582/* 26 */
583extern DL_IMPORT(char *) PyString_AsString(PyObject *);
584/* 27 */
585extern DL_IMPORT(void) PyString_Concat(PyObject **, PyObject *);
586extern DL_IMPORT(void) PyString_ConcatAndDel(PyObject **, PyObject *);
587/* 28 */
588extern DL_IMPORT(PyObject *) PyString_FromString(const char *);
589/* 17 */
590extern DL_IMPORT(PyObject *) PyString_Format(PyObject *, PyObject *);
591
592/* Dictionaries */
593/* 29 */
594extern DL_IMPORT(PyObject *) PyDict_New(void);
595/* 17 */
596extern DL_IMPORT(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);
597/* 24 */
598extern DL_IMPORT(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);
599/* 19 */
600extern DL_IMPORT(int) PyDict_DelItem(PyObject *mp, PyObject *key);
601/* 30 */
602extern DL_IMPORT(void) PyDict_Clear(PyObject *mp);
603/* 31 */
604extern DL_IMPORT(int) PyDict_Next
605 (PyObject *mp, int *pos, PyObject **key, PyObject **value);
606/* 14 */
607extern DL_IMPORT(PyObject *) PyDict_Keys(PyObject *mp);
608extern DL_IMPORT(PyObject *) PyDict_Values(PyObject *mp);
609extern DL_IMPORT(PyObject *) PyDict_Items(PyObject *mp);
610extern DL_IMPORT(PyObject *) PyDict_Copy(PyObject *mp);
611/* 18 */
612extern DL_IMPORT(int) PyDict_Size(PyObject *mp);
613/* 16 */
614extern DL_IMPORT(PyObject *) PyDict_GetItemString(PyObject *dp, char *key);
615/* 22 */
616extern DL_IMPORT(int) PyDict_DelItemString(PyObject *dp, char *key);
617/* 21 */
618extern DL_IMPORT(int) PyDict_SetItemString(PyObject *dp, char *key, PyObject *item);
619
620/* Integer */
621/* 32 */
622extern DL_IMPORT(PyObject *) PyInt_FromString(char*, char**, int);
623/* 33 */
624extern DL_IMPORT(PyObject *) PyInt_FromUnicode(Py_UNICODE*, int, int);
625/* 34 */
626extern DL_IMPORT(PyObject *) PyInt_FromLong(long);
627/* 25 */
628extern DL_IMPORT(long) PyInt_AsLong(PyObject *);
629/* 35 */
630extern DL_IMPORT(long) PyInt_GetMax(void);
631/* Long */
632/* 34 */
633extern DL_IMPORT(PyObject *) PyLong_FromLong(long);
634/* 36 */
635extern DL_IMPORT(PyObject *) PyLong_FromDouble(double);
636/* 25 */
637extern DL_IMPORT(long) PyLong_AsLong(PyObject *);
638
639/* Float */
640/* 36 */
641extern DL_IMPORT(PyObject *) PyFloat_FromDouble(double);
642/* 37 */
643extern DL_IMPORT(double) PyFloat_AsDouble(PyObject *);
644
645/* Modules */
646/* 28 */
647extern DL_IMPORT(PyObject *) PyModule_New(char *);
648/* 14 */
649extern DL_IMPORT(PyObject *) PyModule_GetDict(PyObject *);
650/* 26 */
651extern DL_IMPORT(char *) PyModule_GetName(PyObject *);
652extern DL_IMPORT(char *) PyModule_GetFilename(PyObject *);
653
654/* 39 */
655extern DL_IMPORT(PyObject *) PyTuple_New(int size);
656/* 18 */
657extern DL_IMPORT(int) PyTuple_Size(PyObject *);
658extern DL_IMPORT(int) PyTuple_Check(PyObject *);
659/* 40 */
660extern DL_IMPORT(PyObject *) PyTuple_GetItem(PyObject *, int);
661/* 41 */
662extern DL_IMPORT(int) PyTuple_SetItem(PyObject *, int, PyObject *);
663/* 13 */
664extern DL_IMPORT(PyObject *) PyTuple_GetSlice(PyObject *, int, int);
665
666/* 42 */
667DL_IMPORT(PyObject *) PySlice_New(PyObject* start, PyObject* stop, PyObject* step);
668/* 43 */
669DL_IMPORT(int) PySlice_GetIndices(PySliceObject *r, int length, int *start, int *stop, int *step);
670/* 44 */
671DL_IMPORT(PyObject *) PyRange_New(long, long, long, int);
672
673/* Error handling definitions */
674
675/* 30 */
676DL_IMPORT(void) PyErr_SetNone(PyObject *);
677/* 45 */
678DL_IMPORT(void) PyErr_SetObject(PyObject *, PyObject *);
679/* 46 */
680DL_IMPORT(void) PyErr_SetString(PyObject *, const char *);
681/* 29 */
682DL_IMPORT(PyObject *) PyErr_Occurred(void);
683/* 1 */
684DL_IMPORT(void) PyErr_Clear(void);
685/* 47 */
686DL_IMPORT(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
687/* 48 */
688DL_IMPORT(void) PyErr_Restore(PyObject *, PyObject *, PyObject *);
689
690/* Error testing and normalization */
691/* 19 */
692DL_IMPORT(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *);
693/* 18 */
694DL_IMPORT(int) PyErr_ExceptionMatches(PyObject *);
695/* 47 */
696DL_IMPORT(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
697
698/* Classes */
699/* 42 */
700extern DL_IMPORT(PyObject *) PyClass_New(PyObject *, PyObject *, PyObject *);
701/* 42 */
702extern DL_IMPORT(PyObject *) PyInstance_New(PyObject *, PyObject *,
703 PyObject *);
704/* 17 */
705extern DL_IMPORT(PyObject *) PyInstance_NewRaw(PyObject *, PyObject *);
706/* 42 */
707extern DL_IMPORT(PyObject *) PyMethod_New(PyObject *, PyObject *, PyObject *);
708/* 14 */
709extern DL_IMPORT(PyObject *) PyMethod_Function(PyObject *);
710extern DL_IMPORT(PyObject *) PyMethod_Self(PyObject *);
711extern DL_IMPORT(PyObject *) PyMethod_Class(PyObject *);
712
713/* Module */
714/* 28 */
715extern DL_IMPORT(PyObject *) PyModule_New(char *);
716/* 14 */
717extern DL_IMPORT(PyObject *) PyModule_GetDict(PyObject *);
718/* 26 */
719extern DL_IMPORT(char *) PyModule_GetName(PyObject *);
720extern DL_IMPORT(char *) PyModule_GetFilename(PyObject *);
721/* 35 */
722DL_IMPORT(long) PyImport_GetMagicNumber(void);
723/* 49 */
724DL_IMPORT(PyObject *) PyImport_ExecCodeModule(char *name, PyObject *co);
725/* 50 */
726DL_IMPORT(PyObject *) PyImport_ExecCodeModuleEx(char *name, PyObject *co, char *pathname);
727/* 29 */
728DL_IMPORT(PyObject *) PyImport_GetModuleDict(void);
729/* 28 */
730DL_IMPORT(PyObject *) PyImport_AddModule(char *name);
731DL_IMPORT(PyObject *) PyImport_ImportModule(char *name);
732/* 51 */
733DL_IMPORT(PyObject *) PyImport_ImportModuleEx(char *name, PyObject *globals, PyObject *locals, PyObject *fromlist);
734/* 28 */
735DL_IMPORT(PyObject *) PyImport_Import(PyObject *name);
736/* 14 */
737DL_IMPORT(PyObject *) PyImport_ReloadModule(PyObject *m);
738/* 1 */
739DL_IMPORT(void) PyImport_Cleanup(void);
740/* 5 */
741DL_IMPORT(int) PyImport_ImportFrozenModule(char *);
742
743/* Interface to random parts in ceval.c */
744/* 42 */
745DL_IMPORT(PyObject *) PyEval_CallObjectWithKeywords(PyObject *, PyObject *, PyObject *);
746/* 17 */
747DL_IMPORT(PyObject *) PyEval_CallObject(PyObject *, PyObject *);
748
749/* 29 */
750DL_IMPORT(PyObject *) PyEval_GetBuiltins(void);
751DL_IMPORT(PyObject *) PyEval_GetGlobals(void);
752DL_IMPORT(PyObject *) PyEval_GetLocals(void);
753DL_IMPORT(PyObject *) PyEval_GetFrame(void);
754/* 4 */
755DL_IMPORT(int) PyEval_GetRestricted(void);
756
757/* Abstract layer */
758/* 14 */
759DL_IMPORT(PyObject *) PyObject_Type(PyObject *o);
760/* 18 */
761DL_IMPORT(int) PyObject_Size(PyObject *o);
762/* 17 */
763DL_IMPORT(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
764/* 24 */
765DL_IMPORT(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v);
766/* 17 */
767DL_IMPORT(int) PyObject_DelItem(PyObject *o, PyObject *key);
768/* 52 */
769DL_IMPORT(int) PyObject_AsCharBuffer(PyObject *obj,const char **buffer,int *buffer_len);
770DL_IMPORT(int) PyObject_AsReadBuffer(PyObject *obj,const void **buffer,int *buffer_len);
771DL_IMPORT(int) PyObject_AsWriteBuffer(PyObject *obj,void **buffer,int *buffer_len);
772/* 18 */
773DL_IMPORT(int) PyNumber_Check(PyObject *o);
774/* 17 */
775DL_IMPORT(PyObject *) PyNumber_Add(PyObject *o1, PyObject *o2);
776DL_IMPORT(PyObject *) PyNumber_Subtract(PyObject *o1, PyObject *o2);
777DL_IMPORT(PyObject *) PyNumber_Multiply(PyObject *o1, PyObject *o2);
778DL_IMPORT(PyObject *) PyNumber_Divide(PyObject *o1, PyObject *o2);
779DL_IMPORT(PyObject *) PyNumber_Remainder(PyObject *o1, PyObject *o2);
780DL_IMPORT(PyObject *) PyNumber_Divmod(PyObject *o1, PyObject *o2);
781/* 42 */
782DL_IMPORT(PyObject *) PyNumber_Power(PyObject *o1, PyObject *o2,PyObject *o3);
783/* 14 */
784DL_IMPORT(PyObject *) PyNumber_Negative(PyObject *o);
785DL_IMPORT(PyObject *) PyNumber_Positive(PyObject *o);
786DL_IMPORT(PyObject *) PyNumber_Absolute(PyObject *o);
787DL_IMPORT(PyObject *) PyNumber_Invert(PyObject *o);
788/* 17 */
789DL_IMPORT(PyObject *) PyNumber_Lshift(PyObject *o1, PyObject *o2);
790DL_IMPORT(PyObject *) PyNumber_Rshift(PyObject *o1, PyObject *o2);
791DL_IMPORT(PyObject *) PyNumber_And(PyObject *o1, PyObject *o2);
792DL_IMPORT(PyObject *) PyNumber_Xor(PyObject *o1, PyObject *o2);
793DL_IMPORT(PyObject *) PyNumber_Or(PyObject *o1, PyObject *o2);
794/* 14 */
795DL_IMPORT(PyObject *) PyNumber_Int(PyObject *o);
796DL_IMPORT(PyObject *) PyNumber_Long(PyObject *o);
797DL_IMPORT(PyObject *) PyNumber_Float(PyObject *o);
798/* 17 */
799DL_IMPORT(PyObject *) PyNumber_InPlaceAdd(PyObject *o1, PyObject *o2);
800DL_IMPORT(PyObject *) PyNumber_InPlaceSubtract(PyObject *o1, PyObject *o2);
801DL_IMPORT(PyObject *) PyNumber_InPlaceMultiply(PyObject *o1, PyObject *o2);
802DL_IMPORT(PyObject *) PyNumber_InPlaceDivide(PyObject *o1, PyObject *o2);
803DL_IMPORT(PyObject *) PyNumber_InPlaceRemainder(PyObject *o1, PyObject *o2);
804DL_IMPORT(PyObject *) PyNumber_InPlaceLshift(PyObject *o1, PyObject *o2);
805DL_IMPORT(PyObject *) PyNumber_InPlaceRshift(PyObject *o1, PyObject *o2);
806DL_IMPORT(PyObject *) PyNumber_InPlaceAnd(PyObject *o1, PyObject *o2);
807DL_IMPORT(PyObject *) PyNumber_InPlaceXor(PyObject *o1, PyObject *o2);
808DL_IMPORT(PyObject *) PyNumber_InPlaceOr(PyObject *o1, PyObject *o2);
809/* 42 */
810DL_IMPORT(PyObject *) PyNumber_InPlacePower(PyObject *o1, PyObject *o2,PyObject *o3);
811/* 18 */
812DL_IMPORT(int) PySequence_Check(PyObject *o);
813DL_IMPORT(int) PySequence_Size(PyObject *o);
814DL_IMPORT(int) PySequence_Length(PyObject *o);
815/* 17 */
816DL_IMPORT(PyObject *) PySequence_Concat(PyObject *o1, PyObject *o2);
817/* 40 */
818DL_IMPORT(PyObject *) PySequence_Repeat(PyObject *o, int count);
819DL_IMPORT(PyObject *) PySequence_GetItem(PyObject *o, int i);
820/* 13 */
821DL_IMPORT(PyObject *) PySequence_GetSlice(PyObject *o, int i1, int i2);
822/* 41 */
823DL_IMPORT(int) PySequence_SetItem(PyObject *o, int i, PyObject *v);
824/* 20 */
825DL_IMPORT(int) PySequence_DelItem(PyObject *o, int i);
826/* 53 */
827DL_IMPORT(int) PySequence_SetSlice(PyObject *o, int i1, int i2, PyObject *v);
828/* 54 */
829DL_IMPORT(int) PySequence_DelSlice(PyObject *o, int i1, int i2);
830/* 14 */
831DL_IMPORT(PyObject *) PySequence_Tuple(PyObject *o);
832DL_IMPORT(PyObject *) PySequence_List(PyObject *o);
833/* 16 */
834DL_IMPORT(PyObject *) PySequence_Fast(PyObject *o, const char* m);
835/* 19 */
836DL_IMPORT(int) PySequence_Count(PyObject *o, PyObject *value);
837DL_IMPORT(int) PySequence_Contains(PyObject *o, PyObject *value);
838DL_IMPORT(int) PySequence_In(PyObject *o, PyObject *value);
839DL_IMPORT(int) PySequence_Index(PyObject *o, PyObject *value);
840/* 17 */
841DL_IMPORT(PyObject *) PySequence_InPlaceConcat(PyObject *o1, PyObject *o2);
842/* 22 */
843DL_IMPORT(PyObject *) PySequence_InPlaceRepeat(PyObject *o, int count);
844/* 18 */
845DL_IMPORT(int) PyMapping_Check(PyObject *o);
846DL_IMPORT(int) PyMapping_Size(PyObject *o);
847DL_IMPORT(int) PyMapping_Length(PyObject *o);
848/* 16 */
849DL_IMPORT(int) PyMapping_HasKeyString(PyObject *o, char *key);
850/* 19 */
851DL_IMPORT(int) PyMapping_HasKey(PyObject *o, PyObject *key);
852/* 16 */
853DL_IMPORT(PyObject *) PyMapping_GetItemString(PyObject *o, char *key);
854/* 41 */
855DL_IMPORT(int) PyMapping_SetItemString(PyObject *o, char *key, PyObject *value);
856
857
858#ifdef MAYBE_RUN
859DL_IMPORT(void) init_exceptions(void);
860DL_IMPORT(void) fini_exceptions(void);
861DL_IMPORT(void) _PyImport_Init(void);
862DL_IMPORT(void) _PyImport_Fini(void);
863DL_IMPORT(void) PyMethod_Fini(void);
864DL_IMPORT(void) PyFrame_Fini(void);
865DL_IMPORT(void) PyCFunction_Fini(void);
866DL_IMPORT(void) PyTuple_Fini(void);
867DL_IMPORT(void) PyString_Fini(void);
868DL_IMPORT(void) PyInt_Fini(void);
869DL_IMPORT(void) PyFloat_Fini(void);
870DL_IMPORT(PyObject*) _PyBuiltin_Init(void);
871DL_IMPORT(PyObject*) _PySys_Init(void);
872DL_IMPORT(struct symtable *) Py_SymtableString(char*, char*, int);
873DL_IMPORT(struct _node *) PyParser_SimpleParseString(char*, int);
874DL_IMPORT(struct _node *) PyParser_SimpleParseFile(FILE *, char*, int);
875DL_IMPORT(int) Py_AtExit(void (*func)(void));
876DL_IMPORT(void) Py_EndInterpreter(PyThreadState *);
877DL_IMPORT(PyThreadState *) Py_NewInterpreter(void);
878DL_IMPORT(int) (*PyOS_InputHook)(void);
879DL_IMPORT(int) PyOS_CheckStack(void);
880DL_IMPORT(char) *(*PyOS_ReadlineFunctionPointer)(char*);
881DL_IMPORT(PyOS_sighandler_t) PyOS_getsig(int);
882DL_IMPORT(PyOS_sighandler_t) PyOS_setsig(int, PyOS_sighandler_t);
883DL_IMPORT(void) PyOS_FiniInterrupts(void);
884DL_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
892int PyRun_SimpleString_redo(const char* command) { return PyRun_SimpleStringFlags(command, NULL); }
893
894#undef PyRun_AnyFile
895#define PyRun_AnyFile PyRun_AnyFile_redo
896int 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
900int 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
904int 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
908int 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
912int 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
916int 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
920PyObject* 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
924PyObject* 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
928PyObject* 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
932PyObject* 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
936PyObject* 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
940int PyTuple_Check(PyObject* op) { return PyObject_TypeCheck(op, &PyTuple_Type); }
941/* END HST FIXUP */
942
943/* Value -> Pyobject */
944
945value pywrapvalue( value cb ) {
946 CAMLparam1(cb);
947 CAMLreturn(pywrap(camlwrap(cb,NULL,0)));
948}
949
950value 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
959typedef struct _python_func_table {
960 void *func;
961 int format;
962 char *desc;
963} python_func_table;
964
965python_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
1320value 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
1341enum 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
1357value 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
1375value pynull( value unit ) {
1376 CAMLparam1(unit);
1377 CAMLreturn(pywrap(NULL));
1378}
1379
1380value pynone( value unit ) {
1381 CAMLparam1(unit);
1382 CAMLreturn(pywrap(Py_None));
1383}
1384
1385value 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
1401value 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
1415value 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
1429value 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
1453value 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
1464value pytrue( value unit ) {
1465 CAMLparam1(unit);
1466 CAMLreturn(pywrap(Py_True));
1467}
1468
1469value pyfalse(value unit) {
1470 CAMLparam1(unit);
1471 CAMLreturn(pywrap(Py_False));
1472}