-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
python.cxx
5263 lines (4715 loc) · 184 KB
/
python.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
* included with the SWIG source code as distributed by the SWIG developers
* and at http://www.swig.org/legal.html.
*
* python.cxx
*
* Python language module for SWIG.
* ----------------------------------------------------------------------------- */
#include "swigmod.h"
#include "cparse.h"
static int treduce = SWIG_cparse_template_reduce(0);
#include <ctype.h>
#define PYSHADOW_MEMBER 0x2
#define WARN_PYTHON_MULTIPLE_INH 405
static String *const_code = 0;
static String *module = 0;
static String *package = 0;
static String *mainmodule = 0;
static String *interface = 0;
static String *global_name = 0;
static int shadow = 1;
static int use_kw = 0;
static int director_method_index = 0;
static int builtin = 0;
static File *f_begin = 0;
static File *f_runtime = 0;
static File *f_runtime_h = 0;
static File *f_header = 0;
static File *f_wrappers = 0;
static File *f_directors = 0;
static File *f_directors_h = 0;
static File *f_init = 0;
static File *f_shadow_py = 0;
static String *f_shadow = 0;
static String *f_shadow_begin = 0;
static Hash *f_shadow_imports = 0;
static String *f_shadow_builtin_imports = 0;
static String *f_shadow_stubs = 0;
static Hash *builtin_getset = 0;
static Hash *class_members = 0;
static File *f_builtins = 0;
static String *builtin_tp_init = 0;
static String *builtin_methods = 0;
static String *builtin_default_unref = 0;
static String *methods;
static String *class_name;
static String *shadow_indent = 0;
static int in_class = 0;
static int classic = 0;
static int modern = 0;
static int new_repr = 1;
static int no_header_file = 0;
static int max_bases = 0;
static int builtin_bases_needed = 0;
static int py3 = 0;
/* C++ Support + Shadow Classes */
static int have_constructor;
static int have_repr;
static String *real_classname;
/* Thread Support */
static int threads = 0;
static int nothreads = 0;
static int classptr = 0;
/* Other options */
static int shadowimport = 1;
static int buildnone = 0;
static int nobuildnone = 0;
static int safecstrings = 0;
static int dirvtable = 0;
static int proxydel = 1;
static int fastunpack = 0;
static int fastproxy = 0;
static int fastquery = 0;
static int fastinit = 0;
static int olddefs = 0;
static int modernargs = 0;
static int aliasobj0 = 0;
static int castmode = 0;
static int extranative = 0;
static int outputtuple = 0;
static int nortti = 0;
static int relativeimport = 0;
/* flags for the make_autodoc function */
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
AUTODOC_DTOR,
AUTODOC_STATICFUNC,
AUTODOC_FUNC,
AUTODOC_METHOD
};
static const char *usage1 = (char *) "\
Python Options (available with -python)\n\
-aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\
-buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\
-builtin - Create new python built-in types, rather than proxy classes, for better performance\n\
-castmode - Enable the casting mode, which allows implicit cast between types in python\n\
-classic - Use classic classes only\n\
-classptr - Generate shadow 'ClassPtr' as in older swig versions\n\
-cppcast - Enable C++ casting operators (default) \n\
-dirvtable - Generate a pseudo virtual table for directors for faster dispatch \n\
-extranative - Return extra native C++ wraps for std containers when possible \n\
-fastinit - Use fast init mechanism for classes (default)\n\
-fastunpack - Use fast unpack mechanism to parse the argument functions \n\
-fastproxy - Use fast proxy mechanism for member methods \n\
-fastquery - Use fast query mechanism for types \n\
-globals <name> - Set <name> used to access C global variable [default: 'cvar']\n\
-interface <lib>- Set the lib name to <lib>\n\
-keyword - Use keyword arguments\n\
-modern - Use modern python features only, without compatibility code\n\
-modernargs - Use \"modern\" args mechanism to pack/unpack the function arguments\n";
static const char *usage2 = (char *) "\
-newrepr - Use more informative version of __repr__ in proxy classes (default) \n\
-newvwm - New value wrapper mode, use only when everything else fails \n\
-noaliasobj0 - Don't generate an obj0 alias when using fastunpack (default) \n\
-nobuildnone - Access Py_None directly (default in non-Windows systems)\n\
-nocastmode - Disable the casting mode (default)\n\
-nocppcast - Disable C++ casting operators, useful for generating bugs\n\
-nodirvtable - Don't use the virtual table feature, resolve the python method each time (default)\n\
-noexcept - No automatic exception handling\n\
-noextranative - Don't use extra native C++ wraps for std containers when possible (default) \n\
-nofastinit - Use traditional init mechanism for classes \n\
-nofastunpack - Use traditional UnpackTuple method to parse the argument functions (default) \n\
-nofastproxy - Use traditional proxy mechanism for member methods (default) \n\
-nofastquery - Use traditional query mechanism for types (default) \n\
-noh - Don't generate the output header file\n\
-nomodern - Don't use modern python features which are not backwards compatible \n\
-nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n";
static const char *usage3 = (char *) "\
-noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\
-nooutputtuple - Use a PyList for appending output values (default) \n\
-noproxy - Don't generate proxy classes \n\
-noproxydel - Don't generate the redundant __del__ method \n\
-noproxyimport - Don't insert proxy import statements derived from the %import directive \n\
-nortti - Disable the use of the native C++ RTTI with directors\n\
-nosafecstrings - Avoid extra strings copies when possible (default)\n\
-nothreads - Disable thread support for the entire interface\n\
-olddefs - Keep the old method definitions even when using fastproxy\n\
-oldrepr - Use shorter and old version of __repr__ in proxy classes\n\
-outputtuple - Use a PyTuple for outputs instead of a PyList (use carefully with legacy interfaces) \n\
-proxydel - Generate a __del__ method even though it is now redundant (default) \n\
-relativeimport - Use relative python imports \n\
-safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\
-threads - Add thread support for all the interface\n\
-O - Enable the following optimization options: \n\
-modern -fastdispatch -nosafecstrings -fvirtual -noproxydel \n\
-fastproxy -fastinit -fastunpack -fastquery -modernargs -nobuildnone \n\
-py3 - Generate code with Python 3 specific features:\n\
Function annotation \n\
\n";
static String *getSlot(Node *n = NULL, const char *key = NULL) {
static String *slot_default = NewString("0");
String *val = key && *key ? Getattr(n, key) : NULL;
return val ? val : slot_default;
}
static void printSlot(File *f, const String *slotval, const char *slotname, const char *functype = NULL) {
String *slotval_override = functype ? NewStringf("(%s) %s", functype, slotval) : 0;
if (slotval_override)
slotval = slotval_override;
int len = Len(slotval);
int fieldwidth = len > 40 ? 0 : 40 - len;
Printf(f, " %s, %*s/* %s */\n", slotval, fieldwidth, "", slotname);
Delete(slotval_override);
}
static String *getClosure(String *functype, String *wrapper, int funpack = 0) {
static const char *functypes[] = {
"unaryfunc", "SWIGPY_UNARYFUNC_CLOSURE",
"destructor", "SWIGPY_DESTRUCTOR_CLOSURE",
"inquiry", "SWIGPY_INQUIRY_CLOSURE",
"getiterfunc", "SWIGPY_UNARYFUNC_CLOSURE",
"binaryfunc", "SWIGPY_BINARYFUNC_CLOSURE",
"ternaryfunc", "SWIGPY_TERNARYFUNC_CLOSURE",
"ternarycallfunc", "SWIGPY_TERNARYCALLFUNC_CLOSURE",
"lenfunc", "SWIGPY_LENFUNC_CLOSURE",
"ssizeargfunc", "SWIGPY_SSIZEARGFUNC_CLOSURE",
"ssizessizeargfunc", "SWIGPY_SSIZESSIZEARGFUNC_CLOSURE",
"ssizeobjargproc", "SWIGPY_SSIZEOBJARGPROC_CLOSURE",
"ssizessizeobjargproc", "SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE",
"objobjargproc", "SWIGPY_OBJOBJARGPROC_CLOSURE",
"reprfunc", "SWIGPY_REPRFUNC_CLOSURE",
"hashfunc", "SWIGPY_HASHFUNC_CLOSURE",
"iternextfunc", "SWIGPY_ITERNEXT_CLOSURE",
NULL
};
static const char *funpack_functypes[] = {
"unaryfunc", "SWIGPY_UNARYFUNC_CLOSURE",
"destructor", "SWIGPY_DESTRUCTOR_CLOSURE",
"inquiry", "SWIGPY_INQUIRY_CLOSURE",
"getiterfunc", "SWIGPY_UNARYFUNC_CLOSURE",
"ternaryfunc", "SWIGPY_TERNARYFUNC_CLOSURE",
"ternarycallfunc", "SWIGPY_TERNARYCALLFUNC_CLOSURE",
"lenfunc", "SWIGPY_LENFUNC_CLOSURE",
"ssizeargfunc", "SWIGPY_FUNPACK_SSIZEARGFUNC_CLOSURE",
"ssizessizeargfunc", "SWIGPY_SSIZESSIZEARGFUNC_CLOSURE",
"ssizeobjargproc", "SWIGPY_SSIZEOBJARGPROC_CLOSURE",
"ssizessizeobjargproc", "SWIGPY_SSIZESSIZEOBJARGPROC_CLOSURE",
"objobjargproc", "SWIGPY_OBJOBJARGPROC_CLOSURE",
"reprfunc", "SWIGPY_REPRFUNC_CLOSURE",
"hashfunc", "SWIGPY_HASHFUNC_CLOSURE",
"iternextfunc", "SWIGPY_ITERNEXT_CLOSURE",
NULL
};
if (!functype)
return NULL;
char *c = Char(functype);
int i;
if (funpack) {
for (i = 0; funpack_functypes[i] != NULL; i += 2) {
if (!strcmp(c, funpack_functypes[i]))
return NewStringf("%s(%s)", funpack_functypes[i + 1], wrapper);
}
} else {
for (i = 0; functypes[i] != NULL; i += 2) {
if (!strcmp(c, functypes[i]))
return NewStringf("%s(%s)", functypes[i + 1], wrapper);
}
}
return NULL;
}
class PYTHON:public Language {
public:
PYTHON() {
/* Add code to manage protected constructors and directors */
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
"if ( $comparison ) { /* subclassed */\n",
" $director_new \n",
"} else {\n", " SWIG_SetErrorMsg(PyExc_RuntimeError,\"accessing abstract class or protected constructor\"); \n", " SWIG_fail;\n", "}\n", NIL);
director_multiple_inheritance = 1;
director_language = 1;
}
/* ------------------------------------------------------------
* Thread Implementation
* ------------------------------------------------------------ */
int threads_enable(Node *n) const {
return threads && !GetFlagAttr(n, "feature:nothread");
}
int initialize_threads(String *f_init) {
if (!threads) {
return SWIG_OK;
}
Printf(f_init, "\n");
Printf(f_init, "/* Initialize threading */\n");
Printf(f_init, "SWIG_PYTHON_INITIALIZE_THREADS;\n");
return SWIG_OK;
}
virtual void thread_begin_block(Node *n, String *f) {
if (!GetFlag(n, "feature:nothreadblock")) {
String *bb = Getattr(n, "feature:threadbeginblock");
if (bb) {
Append(f, bb);
} else {
Append(f, "SWIG_PYTHON_THREAD_BEGIN_BLOCK;\n");
}
}
}
virtual void thread_end_block(Node *n, String *f) {
if (!GetFlag(n, "feature:nothreadblock")) {
String *eb = Getattr(n, "feature:threadendblock");
if (eb) {
Append(f, eb);
} else {
Append(f, "SWIG_PYTHON_THREAD_END_BLOCK;\n");
}
}
}
virtual void thread_begin_allow(Node *n, String *f) {
if (!GetFlag(n, "feature:nothreadallow")) {
String *bb = Getattr(n, "feature:threadbeginallow");
Append(f, "{\n");
if (bb) {
Append(f, bb);
} else {
Append(f, "SWIG_PYTHON_THREAD_BEGIN_ALLOW;\n");
}
}
}
virtual void thread_end_allow(Node *n, String *f) {
if (!GetFlag(n, "feature:nothreadallow")) {
String *eb = Getattr(n, "feature:threadendallow");
Append(f, "\n");
if (eb) {
Append(f, eb);
} else {
Append(f, "SWIG_PYTHON_THREAD_END_ALLOW;");
}
Append(f, "\n}");
}
}
/* ------------------------------------------------------------
* main()
* ------------------------------------------------------------ */
virtual void main(int argc, char *argv[]) {
int cppcast = 1;
SWIG_library_directory("python");
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i], "-interface") == 0) {
if (argv[i + 1]) {
interface = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
/* end added */
} else if (strcmp(argv[i], "-globals") == 0) {
if (argv[i + 1]) {
global_name = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if ((strcmp(argv[i], "-shadow") == 0) || ((strcmp(argv[i], "-proxy") == 0))) {
shadow = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-new_repr") == 0) || (strcmp(argv[i], "-newrepr") == 0)) {
new_repr = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-old_repr") == 0) || (strcmp(argv[i], "-oldrepr") == 0)) {
new_repr = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-classptr") == 0) {
classptr = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-noproxy") == 0)) {
shadow = 0;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-noproxyimport") == 0)) {
shadowimport = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-keyword") == 0) {
use_kw = 1;
SWIG_cparse_set_compact_default_args(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-classic") == 0) {
classic = 1;
modernargs = 0;
modern = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-cppcast") == 0) {
cppcast = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nocppcast") == 0) {
cppcast = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-outputtuple") == 0) {
outputtuple = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nooutputtuple") == 0) {
outputtuple = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nortti") == 0) {
nortti = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-threads") == 0) {
threads = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nothreads") == 0) {
/* Turn off thread suppor mode */
nothreads = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-safecstrings") == 0) {
safecstrings = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nosafecstrings") == 0) {
safecstrings = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-buildnone") == 0) {
buildnone = 1;
nobuildnone = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nobuildnone") == 0) {
buildnone = 0;
nobuildnone = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-dirvtable") == 0) {
dirvtable = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nodirvtable") == 0) {
dirvtable = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-fastunpack") == 0) {
fastunpack = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nofastunpack") == 0) {
fastunpack = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-fastproxy") == 0) {
fastproxy = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nofastproxy") == 0) {
fastproxy = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-fastquery") == 0) {
fastquery = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nofastquery") == 0) {
fastquery = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-fastinit") == 0) {
fastinit = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nofastinit") == 0) {
fastinit = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-olddefs") == 0) {
olddefs = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noolddefs") == 0) {
olddefs = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-castmode") == 0) {
castmode = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nocastmode") == 0) {
castmode = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-extranative") == 0) {
extranative = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noextranative") == 0) {
extranative = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-modernargs") == 0) {
modernargs = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nomodernargs") == 0) {
modernargs = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-aliasobj0") == 0) {
aliasobj0 = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noaliasobj0") == 0) {
aliasobj0 = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-proxydel") == 0) {
proxydel = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noproxydel") == 0) {
proxydel = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-modern") == 0) {
classic = 0;
modern = 1;
modernargs = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-nomodern") == 0) {
modern = 0;
modernargs = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noh") == 0) {
no_header_file = 1;
Swig_mark_arg(i);
} else if ((strcmp(argv[i], "-new_vwm") == 0) || (strcmp(argv[i], "-newvwm") == 0)) {
/* Turn on new value wrapper mpde */
Swig_value_wrapper_mode(1);
no_header_file = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-O") == 0) {
classic = 0;
modern = 1;
safecstrings = 0;
buildnone = 0;
nobuildnone = 1;
classptr = 0;
proxydel = 0;
fastunpack = 1;
fastproxy = 1;
fastinit = 1;
fastquery = 1;
modernargs = 1;
Wrapper_fast_dispatch_mode_set(1);
Wrapper_virtual_elimination_mode_set(1);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-help") == 0) {
fputs(usage1, stdout);
fputs(usage2, stdout);
fputs(usage3, stdout);
} else if (strcmp(argv[i], "-py3") == 0) {
py3 = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-builtin") == 0) {
builtin = 1;
Preprocessor_define("SWIGPYTHON_BUILTIN", 0);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-relativeimport") == 0) {
relativeimport = 1;
Swig_mark_arg(i);
}
}
}
if (py3) {
/* force disable features that not compatible with Python 3.x */
classic = 0;
}
if (cppcast) {
Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
}
if (!global_name)
global_name = NewString("cvar");
Preprocessor_define("SWIGPYTHON 1", 0);
SWIG_typemap_lang("python");
SWIG_config_file("python.swg");
allow_overloading();
}
/* ------------------------------------------------------------
* top()
* ------------------------------------------------------------ */
virtual int top(Node *n) {
/* check if directors are enabled for this module. note: this
* is a "master" switch, without which no director code will be
* emitted. %feature("director") statements are also required
* to enable directors for individual classes or methods.
*
* use %module(directors="1") modulename at the start of the
* interface file to enable director generation.
*/
String *mod_docstring = NULL;
{
Node *mod = Getattr(n, "module");
if (mod) {
Node *options = Getattr(mod, "options");
if (options) {
int dirprot = 0;
if (Getattr(options, "dirprot")) {
dirprot = 1;
}
if (Getattr(options, "nodirprot")) {
dirprot = 0;
}
if (Getattr(options, "directors")) {
allow_directors();
if (dirprot)
allow_dirprot();
}
if (Getattr(options, "threads")) {
threads = 1;
}
if (Getattr(options, "castmode")) {
castmode = 1;
}
if (Getattr(options, "nocastmode")) {
castmode = 0;
}
if (Getattr(options, "extranative")) {
extranative = 1;
}
if (Getattr(options, "noextranative")) {
extranative = 0;
}
if (Getattr(options, "outputtuple")) {
outputtuple = 1;
}
if (Getattr(options, "nooutputtuple")) {
outputtuple = 0;
}
mod_docstring = Getattr(options, "docstring");
package = Getattr(options, "package");
}
}
}
/* Set comparison with none for ConstructorToFunction */
setSubclassInstanceCheck(NewString("$arg != Py_None"));
/* Initialize all of the output files */
String *outfile = Getattr(n, "outfile");
String *outfile_h = !no_header_file ? Getattr(n, "outfile_h") : 0;
f_begin = NewFile(outfile, "w", SWIG_output_files());
if (!f_begin) {
FileErrorDisplay(outfile);
SWIG_exit(EXIT_FAILURE);
}
f_runtime = NewString("");
f_init = NewString("");
f_header = NewString("");
f_wrappers = NewString("");
f_directors_h = NewString("");
f_directors = NewString("");
builtin_getset = NewHash();
class_members = NewHash();
builtin_methods = NewString("");
builtin_default_unref = NewString("delete $self;");
if (builtin) {
f_builtins = NewString("");
}
if (directorsEnabled()) {
if (!no_header_file) {
f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
if (!f_runtime_h) {
FileErrorDisplay(outfile_h);
SWIG_exit(EXIT_FAILURE);
}
} else {
f_runtime_h = f_runtime;
}
}
/* Register file targets with the SWIG file handler */
Swig_register_filebyname("header", f_header);
Swig_register_filebyname("wrapper", f_wrappers);
Swig_register_filebyname("begin", f_begin);
Swig_register_filebyname("runtime", f_runtime);
Swig_register_filebyname("init", f_init);
Swig_register_filebyname("director", f_directors);
Swig_register_filebyname("director_h", f_directors_h);
const_code = NewString("");
methods = NewString("");
Swig_banner(f_begin);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIGPYTHON\n");
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
}
if (nothreads) {
Printf(f_runtime, "#define SWIG_PYTHON_NO_THREADS\n");
} else if (threads) {
Printf(f_runtime, "#define SWIG_PYTHON_THREADS\n");
}
if (safecstrings) {
Printf(f_runtime, "#define SWIG_PYTHON_SAFE_CSTRINGS\n");
}
if (buildnone) {
Printf(f_runtime, "#define SWIG_PYTHON_BUILD_NONE\n");
}
if (nobuildnone) {
Printf(f_runtime, "#define SWIG_PYTHON_NO_BUILD_NONE\n");
}
if (!dirvtable) {
Printf(f_runtime, "#define SWIG_PYTHON_DIRECTOR_NO_VTABLE\n");
}
if (outputtuple) {
Printf(f_runtime, "#define SWIG_PYTHON_OUTPUT_TUPLE\n");
}
if (nortti) {
Printf(f_runtime, "#ifndef SWIG_DIRECTOR_NORTTI\n");
Printf(f_runtime, "#define SWIG_DIRECTOR_NORTTI\n");
Printf(f_runtime, "#endif\n");
}
if (castmode) {
Printf(f_runtime, "#define SWIG_CASTRANK_MODE\n");
Printf(f_runtime, "#define SWIG_PYTHON_CAST_MODE\n");
}
if (extranative) {
Printf(f_runtime, "#define SWIG_PYTHON_EXTRA_NATIVE_CONTAINERS\n");
}
if (classic) {
Printf(f_runtime, "#define SWIG_PYTHON_CLASSIC\n");
}
if (builtin) {
Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n");
}
Printf(f_runtime, "\n");
Printf(f_header, "#if (PY_VERSION_HEX <= 0x02000000)\n");
Printf(f_header, "# if !defined(SWIG_PYTHON_CLASSIC)\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-classic' option\"\n");
Printf(f_header, "# endif\n");
Printf(f_header, "#endif\n");
if (modern) {
Printf(f_header, "#if (PY_VERSION_HEX <= 0x02020000)\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-nomodern' option\"\n");
Printf(f_header, "#endif\n");
}
if (modernargs) {
Printf(f_header, "#if (PY_VERSION_HEX <= 0x02020000)\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-nomodernargs' option\"\n");
Printf(f_header, "#endif\n");
}
if (fastunpack) {
Printf(f_header, "#ifndef METH_O\n");
Printf(f_header, "# error \"This python version requires swig to be run with the '-nofastunpack' option\"\n");
Printf(f_header, "#endif\n");
}
if (fastquery) {
Printf(f_header, "#ifdef SWIG_TypeQuery\n");
Printf(f_header, "# undef SWIG_TypeQuery\n");
Printf(f_header, "#endif\n");
Printf(f_header, "#define SWIG_TypeQuery SWIG_Python_TypeQuery\n");
}
/* Set module name */
module = Copy(Getattr(n, "name"));
mainmodule = Getattr(n, "name");
if (directorsEnabled()) {
Swig_banner(f_directors_h);
Printf(f_directors_h, "\n");
Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", module);
Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", module);
if (dirprot_mode()) {
Printf(f_directors_h, "#include <map>\n");
Printf(f_directors_h, "#include <string>\n\n");
}
Printf(f_directors, "\n\n");
Printf(f_directors, "/* ---------------------------------------------------\n");
Printf(f_directors, " * C++ director class methods\n");
Printf(f_directors, " * --------------------------------------------------- */\n\n");
if (outfile_h) {
String *filename = Swig_file_filename(outfile_h);
Printf(f_directors, "#include \"%s\"\n\n", filename);
Delete(filename);
}
}
/* If shadow classing is enabled, we're going to change the module name to "_module" */
if (shadow) {
String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module));
// If we don't have an interface then change the module name X to _X
if (interface)
module = interface;
else
Insert(module, 0, "_");
if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
Delete(filen);
filen = NULL;
f_shadow = NewString("");
f_shadow_begin = NewString("");
f_shadow_imports = NewHash();
f_shadow_builtin_imports = NewString("");
f_shadow_stubs = NewString("");
Swig_register_filebyname("shadow", f_shadow);
Swig_register_filebyname("python", f_shadow);
if (mod_docstring && Len(mod_docstring)) {
Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL);
Delete(mod_docstring);
mod_docstring = NULL;
}
Printv(f_shadow, "\nfrom sys import version_info\n", NULL);
if (!builtin && fastproxy) {
Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL);
Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
Printv(f_shadow, "else:\n", NULL);
Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
}
/* Import the C-extension module. This should be a relative import,
* since the shadow module may also have been imported by a relative
* import, and there is thus no guarantee that the C-extension is on
* sys.path. Relative imports must be explicitly specified from 2.6.0
* onwards (implicit relative imports will raise a DeprecationWarning
* in 2.6, and fail in 2.7 onwards), but the relative import syntax
* isn't available in python 2.4 or earlier, so we have to write some
* code conditional on the python version.
*/
Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL);
Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
Printv(f_shadow, tab8, "import imp\n", NULL);
Printv(f_shadow, tab8, "fp = None\n", NULL);
Printv(f_shadow, tab8, "try:\n", NULL);
Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
Printf(f_shadow, tab8 "except ImportError:\n");
/* At here, the module may already loaded, so simply import it. */
Printf(f_shadow, tab4 tab8 "import %s\n", module);
Printf(f_shadow, tab4 tab8 "return %s\n", module);
Printv(f_shadow, tab8 "if fp is not None:\n", NULL);
Printv(f_shadow, tab4 tab8 "try:\n", NULL);
Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
Printv(f_shadow, tab4 tab8, "finally:\n", NULL);
Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
Printv(f_shadow, tab4 tab8, "return _mod\n", NULL);
Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
Printv(f_shadow, "else:\n", NULL);
Printf(f_shadow, tab4 "import %s\n", module);
/* Delete the version_info symbol since we don't use it elsewhere in the
* module. */
Printv(f_shadow, "del version_info\n", NULL);
if (builtin) {
Printf(f_shadow, "from %s import *\n", module);
}
if (modern || !classic) {
Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL);
}
/* if (!modern) */
/* always needed, a class can be forced to be no-modern, such as an exception */
{
// Python-2.2 object hack
Printv(f_shadow,
"def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n",
tab4, "if (name == \"thisown\"): return self.this.own(value)\n",
tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n",
#ifdef USE_THISOWN
tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n",
#endif
tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n",
#ifdef USE_THISOWN
tab4, "if (not static) or (name == \"thisown\"):\n",
#else
tab4, "if (not static):\n",
#endif
tab4, tab4, "self.__dict__[name] = value\n",
tab4, "else:\n",
tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n",
"def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL);
Printv(f_shadow,
"def _swig_getattr(self,class_type,name):\n",
tab4, "if (name == \"thisown\"): return self.this.own()\n",
tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL);
Printv(f_shadow,
"def _swig_repr(self):\n",
tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n",
tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
if (!classic) {
/* Usage of types.ObjectType is deprecated.
* But don't sure wether this would broken old Python?
*/
Printv(f_shadow,
// "import types\n",
"try:\n",
// " _object = types.ObjectType\n",
" _object = object\n", " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
// "del types\n",
"\n\n", NIL);
}
}
if (modern) {
Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n",
#ifdef USE_THISOWN
tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
#else
tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
#endif
tab4, tab4, tab4, "set(self,name,value)\n",
tab4, tab4, "else:\n",
tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL);
}
if (directorsEnabled()) {
// Try loading weakref.proxy, which is only available in Python 2.1 and higher
Printv(f_shadow,
"try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
}
}
// Include some information in the code
Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\
------------------------------------------------*/\n", module);
Printf(f_header, "#if PY_VERSION_HEX >= 0x03000000\n");
Printf(f_header, "# define SWIG_init PyInit_%s\n\n", module);
Printf(f_header, "#else\n");
Printf(f_header, "# define SWIG_init init%s\n\n", module);
Printf(f_header, "#endif\n");
Printf(f_header, "#define SWIG_name \"%s\"\n", module);
Printf(f_wrappers, "#ifdef __cplusplus\n");
Printf(f_wrappers, "extern \"C\" {\n");
Printf(f_wrappers, "#endif\n");
Append(const_code, "static swig_const_info swig_const_table[] = {\n");
Append(methods, "static PyMethodDef SwigMethods[] = {\n");
/* the method exported for replacement of new.instancemethod in Python 3 */
add_pyinstancemethod_new();
if (builtin) {
SwigType *s = NewString("SwigPyObject");
SwigType_add_pointer(s);
SwigType_remember(s);
Delete(s);
}
/* emit code */
Language::top(n);
if (directorsEnabled()) {
// Insert director runtime into the f_runtime file (make it occur before %header section)
Swig_insert_file("director.swg", f_runtime);
}
/* Close language module */
Append(methods, "\t { NULL, NULL, 0, NULL }\n");
Append(methods, "};\n");
Printf(f_wrappers, "%s\n", methods);
if (builtin) {
Dump(f_builtins, f_wrappers);
}
SwigType_emit_type_table(f_runtime, f_wrappers);
Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n");
Printf(f_wrappers, "%s\n", const_code);
initialize_threads(f_init);
Printf(f_init, "#if PY_VERSION_HEX >= 0x03000000\n");
Printf(f_init, " return m;\n");
Printf(f_init, "#else\n");
Printf(f_init, " return;\n");
Printf(f_init, "#endif\n");
Printf(f_init, "}\n");
Printf(f_wrappers, "#ifdef __cplusplus\n");
Printf(f_wrappers, "}\n");
Printf(f_wrappers, "#endif\n");
if (shadow) {
Swig_banner_target_lang(f_shadow_py, "#");
if (!modern) {
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
}
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL);
Printv(f_shadow_py, f_shadow, "\n", NIL);
Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
Delete(f_shadow_py);
}
/* Close all of the files */
Dump(f_runtime, f_begin);
Dump(f_header, f_begin);
if (directorsEnabled()) {
Dump(f_directors_h, f_runtime_h);
Printf(f_runtime_h, "\n");