-
Notifications
You must be signed in to change notification settings - Fork 17
/
JyNI.c
executable file
·2587 lines (2360 loc) · 93.2 KB
/
JyNI.c
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
/*
* Copyright of JyNI:
* Copyright (c) 2013, 2014, 2015, 2016, 2017 Stefan Richthofer.
* All rights reserved.
*
*
* Copyright of Python and Jython:
* Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
* 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017
* Python Software Foundation.
* All rights reserved.
*
*
* This file is part of JyNI.
*
* JyNI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* JyNI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with JyNI. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* JyNI.c
*
* Created on: 14.03.2013, 00:49:46
* Author: Stefan Richthofer
*/
#include <JyNI.h>
#include <JyAlloc.h>
#include <JySync.h>
#include <code_JyNI.h>
//#include <JyNI_JyNI.h>
#include "frameobject_JyNI.h"
#include "importdl.h"
//#include <dlfcn.h>
//#include "stringlib/string_format.h"
const char* excPrefix = "exceptions.";
//jlong JyNIDebugMode = 0;
TypeMapEntry builtinTypes[builtinTypeCount];
//static TypeMapEntry specialPyInstance;
#define builtinExceptionCount 50
//PyTypeObject* builtinExceptions[builtinExceptionCount];
ExceptionMapEntry builtinExceptions[builtinExceptionCount];
int (*PyOS_InputHook)(void) = NULL;
int Py_DebugFlag; /* Needed by parser.c */
int Py_VerboseFlag; /* Needed by import.c */
int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */
int Py_InspectFlag; /* Needed to determine whether to exit at SystemExit */
int Py_NoSiteFlag; /* Suppress 'import site' */
int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */
int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */
int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */
int Py_UnicodeFlag = 0; /* Needed by compile.c */
int Py_OptimizeFlag = 0; /* Originally hosted in compile.c */
int Py_IgnoreEnvironmentFlag = 0; /* e.g. PYTHONPATH, PYTHONHOME */
/* _XXX Py_QnewFlag should go away in 2.3. It's true iff -Qnew is passed,
on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
true divisions (which they will be in 2.3). */
int _Py_QnewFlag = 0;
int Py_NoUserSiteDirectory = 0; /* for -s and site.py */
int Py_HashRandomizationFlag = 0; /* for -R and PYTHONHASHSEED */
/*
* Class: JyNI_JyNI
* Method: loadModule
* Signature: (Ljava/lang/String;Ljava/lang/String;J)Lorg/python/core/PyModule;
*/
jobject JyNI_loadModule(JNIEnv *env, jclass class, jstring moduleName, jstring modulePath, jlong tstate)
{
const char* utf_string;
jobject er;
VLA_DECL(char, mName);
VLA_DECL(char, mPath);
// jputs("JyNI_loadModule...");
// JyNI_jprintJ(moduleName);
// jputsLong(tstate);
RE_ENTER_JyNI
if (PyErr_Occurred()) jputs("PyErrOccured01 (beginning of JyNI_loadModule)");//this should never happen!
utf_string = (*env)->GetStringUTFChars(env, moduleName, NULL);
//"+1" for 0-termination:
VLA(char, mName, strlen(utf_string)+1);
strcpy(mName, utf_string);
(*env)->ReleaseStringUTFChars(env, moduleName, utf_string);
if (!(*env)->IsSameObject(env, modulePath, NULL)) {
FILE *fp;
utf_string = (*env)->GetStringUTFChars(env, modulePath, NULL);
//"+1" for 0-termination:
VLA(char, mPath, strlen(utf_string)+1);
strcpy(mPath, utf_string);
(*env)->ReleaseStringUTFChars(env, moduleName, utf_string);
fp = fopen(mPath, "r" PY_STDIOTEXTMODE);
if (fp == NULL)
//PyErr_SetFromErrno(PyExc_IOError);
jputs("some error happened opening the file");
er = _PyImport_LoadDynamicModuleJy(mName, mPath, fp);
if (fclose(fp)) jputs("Some error occurred on file close");
} else
// Attempt to load a module statically linked into JyNI.so:
er = _PyImport_LoadDynamicModuleJy(mName, NULL, NULL);
RE_LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: clearPyCPeer
* Signature: (JJ)V
*/
void JyNI_clearPyCPeer(JNIEnv *env, jclass class, jlong objectHandle, jlong refHandle)
{
/* No ENTER_JyNI/LEAVE_JyNI necessary here, because no code is executed that
* might contain Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS.
*/
//jputs("JyNI_clearPyCPeer: acquire lock");
PyEval_AcquireLock();
if (objectHandle) Py_DECREF((PyObject*) objectHandle);
if (refHandle) (*env)->DeleteWeakGlobalRef(env, (jweak) refHandle);
else {
JyObject* jy = AS_JY((PyObject*) objectHandle);
(*env)->DeleteWeakGlobalRef(env, jy->jy);
}
PyEval_ReleaseLock();
//jputs("JyNI_clearPyCPeer: release lock");
//maybe check for ref-count == 0 here and free non-gc objects...
}
/*
* Class: JyNI_JyNI
* Method: JyNIDebugMessage
* Signature: (JJLjava/lang/String;)V
*/
void JyNI_JyNIDebugMessage(JNIEnv *env, jclass class, jlong mode, jlong value, jstring msg)
{
//for future use...
// JyNIDebugMode = mode;
}
/*
* Class: JyNI_JyNI
* Method: callPyCPeer
* Signature: (JLorg/python/core/PyObject;Lorg/python/core/PyObject;J)Lorg/python/core/PyObject;
*/
jobject JyNI_callPyCPeer(JNIEnv *env, jclass class, jlong peerHandle, jobject args, jobject kw, jlong tstate)
{
jobject er;
PyObject* peer = (PyObject*) peerHandle;
// puts(__FUNCTION__);
//note: here should be done sync
//(maybe sync-idea is obsolete anyway)
// jputsLong(peerHandle);
//jputs(Py_TYPE(peer)->tp_name);
// jputs(((PyTypeObject*) peer)->tp_name);
// int jdbg = strcmp(Py_TYPE(peer)->tp_name, "_ctypes.PyCFuncPtrType") == 0;
// if (!peer->ob_type) jputs("ob_type of peer is NULL");
ENTER_JyNI
// jputs("JyNI_call error before call?");
// jputsLong(PyErr_Occurred());
if (peer->ob_type->tp_call) {
PyObject* jargs = JyNI_PyObject_FromJythonPyObject(args);
// if (jdbg) {
// jputsLong(jargs);
// jputsLong(PyTuple_GET_SIZE(jargs));
// jputsLong(PyTuple_GET_ITEM(jargs, 0));
// }
// if (Py_TYPE(peer) == &PyCFunction_Type) {
// jputsLong(((PyCFunctionObject*) peer)->m_ml);
// jputsLong(((PyCFunctionObject*) peer)->m_self);
//// jputs(((PyCFunctionObject*) peer)->m_ml->ml_name);
// }
PyObject* jkw = JyNI_PyObject_FromJythonPyObject(kw);
// jputs("before call");
// jputsPy(peer);
PyObject* jres = peer->ob_type->tp_call(peer, jargs, jkw);
er = JyNI_JythonPyObject_FromPyObject(jres);
Py_XDECREF(jargs);
Py_XDECREF(jkw);
// puts("decref result....");
// printf("%lld\n", jres);
Py_XDECREF(jres);
} else {
// PyErr_Format(PyExc_TypeError, "'%.200s' object is not callable",
// peer->ob_type->tp_name);
er = NULL;
}
LEAVE_JyNI
// jputs("JyNI_callPyCPeer done");
return er;
}
/*
* Class: JyNI_JyNI
* Method: getAttrString
* Signature: (JLjava/lang/String;J)Lorg/python/core/PyObject;
*/
jobject JyNI_getAttrString(JNIEnv *env, jclass class, jlong handle, jstring name, jlong tstate)
{
PyObject* jres;
jobject er;
cstr_decl(cName);
//printf("JyNI_getAttrString %i\n", tstate);
// jputs("JyNI_getAttrString");
// jputsLong(handle);
if (handle == 0) return NULL;
cstr_from_jstring(cName, name);
// jputs(cName);
// jboolean jdbg = strcmp(cName, "__array_interface__") == 0;
// if (jdbg) jputs(__FUNCTION__);
// if (jdbg) jputs(Py_TYPE((PyObject*) handle)->tp_name);
RE_ENTER_JyNI
//jint ensresult = (*env)->EnsureLocalCapacity(env, 100);
//jputs("ensresult:");
//jputsLong(ensresult);
//jputs("JyNI_getAttrString-Handle:");
//jputsLong(handle);
jres = PyObject_GetAttrString((PyObject*) handle, cName);
// jputs("JyNI_getAttrString-Result:");
//jputsLong(jres);
er = JyNI_JythonPyObject_FromPyObject(jres);//PyObject_GetAttrString((PyObject*) handle, cName));
Py_XDECREF(jres);
RE_LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: setAttrString
* Signature: (JLjava/lang/String;Lorg/python/core/PyObject;J)I
*/
jint JyNI_setAttrString(JNIEnv *env, jclass class, jlong handle, jstring name, jobject value, jlong tstate)
{
PyObject* vl;
cstr_decl(cName);
jint er;
if (handle == 0) return 0;
cstr_from_jstring(cName, name);
ENTER_JyNI
vl = JyNI_PyObject_FromJythonPyObject(value);
er = PyObject_SetAttrString((PyObject*) handle, cName, vl);
Py_XDECREF(vl);
LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: repr
* Signature: (JJ)Lorg/python/core/PyObject;
*/
jobject JyNI_repr(JNIEnv *env, jclass class, jlong handle, jlong tstate)
{
PyObject* res;
jobject er;
RE_ENTER_JyNI
res = PyObject_Repr((PyObject*) handle);
er = JyNI_JythonPyObject_FromPyObject(res);
Py_XDECREF(res);
RE_LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: getItem
* Signature: (JLorg/python/core/PyObject;J)Lorg/python/core/PyObject;
*/
jobject JyNI_getItem
(JNIEnv *env, jclass class, jlong handle, jobject key, jlong tstate)
{
PyObject* pkey, * res;
jobject er;
// jputs(__FUNCTION__);
// if (handle) jputs(Py_TYPE((PyObject*) handle)->tp_name);
// else jputs("Handle is NULL");
ENTER_JyNI
// jputsLong(__LINE__);
pkey = JyNI_PyObject_FromJythonPyObject(key);
// jputsLong(__LINE__);
// if (pkey) jputs(Py_TYPE(pkey)->tp_name);
// else jputs("pkey is NULL");
res = PyObject_GetItem((PyObject*) handle, pkey);
// jputsLong(__LINE__);
// if (res) jputs(Py_TYPE(res)->tp_name);
// else jputs("res is NULL");
er = JyNI_JythonPyObject_FromPyObject(res);
Py_XDECREF(pkey);
Py_XDECREF(res);
LEAVE_JyNI
// jputsLong(__LINE__);
return er;
}
/*
* Class: JyNI_JyNI
* Method: setItem
* Signature: (JLorg/python/core/PyObject;Lorg/python/core/PyObject;J)I
*/
jint JyNI_setItem
(JNIEnv *env, jclass class, jlong handle, jobject key, jobject value, jlong tstate)
{
PyObject* pkey, * pval;
jint er;
// jputs(__FUNCTION__);
ENTER_JyNI
pkey = JyNI_PyObject_FromJythonPyObject(key);
pval = JyNI_PyObject_FromJythonPyObject(value);
er = PyObject_SetItem((PyObject*) handle, pkey, pval);
Py_XDECREF(pkey);
Py_XDECREF(pval);
LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: delItem
* Signature: (JLorg/python/core/PyObject;J)I
*/
jint JyNI_delItem
(JNIEnv *env, jclass class, jlong handle, jobject key, jlong tstate)
{
PyObject* pkey;
jint er;
ENTER_JyNI
pkey = JyNI_PyObject_FromJythonPyObject(key);
er = PyObject_DelItem((PyObject*) handle, pkey);
Py_XDECREF(pkey);
LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: PyObjectLength
* Signature: (JJ)I
*/
jint JyNI_PyObjectLength
(JNIEnv *env, jclass class, jlong handle, jlong tstate)
{
jint er;
ENTER_JyNI
er = PyObject_Size((PyObject*) handle);
LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: descr_get
* Signature: (JLorg/python/core/PyObject;Lorg/python/core/PyObject;J)Lorg/python/core/PyObject;
*/
jobject JNICALL JyNI_descr_get
(jlong self, jobject obj, jobject type, jlong tstate)
{
jobject res;
ENTER_JyNI
if (Py_TYPE((PyObject*) self)->tp_descr_get) {
PyObject* pyobj = JyNI_PyObject_FromJythonPyObject(obj);
PyObject* pytype = JyNI_PyObject_FromJythonPyObject(type);
PyObject* pyres = Py_TYPE((PyObject*) self)->tp_descr_get((PyObject*) self, pyobj, pytype);
res = JyNI_JythonPyObject_FromPyObject(pyres);
Py_XDECREF(pyobj);
Py_XDECREF(pytype);
Py_XDECREF(pyres);
} else
res = NULL;
LEAVE_JyNI
return res;
}
/*
* Class: JyNI_JyNI
* Method: descr_set
* Signature: (JLorg/python/core/PyObject;Lorg/python/core/PyObject;J)I
*/
jint JNICALL JyNI_descr_set
(jlong self, jobject obj, jobject value, jlong tstate)
{
jint res;
ENTER_JyNI
if (Py_TYPE((PyObject*) self)->tp_descr_set) {
PyObject* pyobj = JyNI_PyObject_FromJythonPyObject(obj);
PyObject* pyval = JyNI_PyObject_FromJythonPyObject(value);
res = Py_TYPE((PyObject*) self)->tp_descr_set((PyObject*) self, pyobj, pyval);
Py_XDECREF(pyobj);
Py_XDECREF(pyval);
} else
res = JyNI_JyNI_NATIVE_INT_METHOD_NOT_IMPLEMENTED;
LEAVE_JyNI
return res;
}
/*
* Class: JyNI_JyNI
* Method: PyObjectAsString
* Signature: (JJ)Ljava/lang/String;
*/
jstring JyNI_PyObjectAsString(JNIEnv *env, jclass class, jlong handle, jlong tstate)
{
PyStringObject* ps;
jstring er;
// jputs("JyNI_PyObjectAsString");
if (!((PyObject*) handle)->ob_refcnt) return NULL;
RE_ENTER_JyNI
ps = (PyStringObject*) PyObject_Str((PyObject*) handle);
// jputsPy(ps);
er = JyNI_jstring_FromPyStringObject(env, ps);
Py_XDECREF(ps);
RE_LEAVE_JyNI
return er;
}
/*
* Class: JyNI_JyNI
* Method: PyObjectAsPyString
* Signature: (JJ)Lorg/python/core/PyString;
*/
jobject JyNI_PyObjectAsPyString(JNIEnv *env, jclass class, jlong handle, jlong tstate)
{
jobject er;
// jputs("JyNI_PyObjectAsPyString");
ENTER_JyNI
{
PyObject* res = PyObject_Str((PyObject*) handle);
er = JyNI_JythonPyObject_FromPyObject(res);
Py_XDECREF(res);
}
LEAVE_JyNI
// jputs("JyNI_PyObjectAsPyString done");
return er;
}
/*
* Class: JyNI_JyNI
* Method: lookupFromHandle
* Signature: (J)Lorg/python/core/PyObject;
*/
jobject JyNIlookupFromHandle(JNIEnv *env, jclass class, jlong handle)
{
/*Note: If this method crashes the JVM, it is most likely because
* it was called with an already freed handle.
*/
JyObject* jop;
if (!handle) return NULL;
if (Is_Static_PyObject((PyObject*) handle)) return NULL;
jop = AS_JY((PyObject*) handle);
if (jop->flags & JY_INITIALIZED_FLAG_MASK) return jop->jy;
return NULL;
}
/*
* Class: JyNI_JyNI
* Method: currentNativeRefCount
* Signature: (J)I
*/
jint JyNIcurrentNativeRefCount(JNIEnv *env, jclass class, jlong handle)
{
return (jint) ((PyObject*) handle)->ob_refcnt;
}
/*
* Class: JyNI_JyNI
* Method: nativeIncref
* Signature: (JJ)I
*/
void JyNI_nativeIncref(jlong handle, jlong tstate)
{
RE_ENTER_JyNI
Py_INCREF((PyObject*) handle);
RE_LEAVE_JyNI
}
/*
* Class: JyNI_JyNI
* Method: nativeDecref
* Signature: (JJ)I
*/
void JyNI_nativeDecref(jlong handle, jlong tstate)
{
RE_ENTER_JyNI
Py_DECREF((PyObject*) handle);
RE_LEAVE_JyNI
}
/*
* Class: JyNI_JyNI
* Method: getNativeTypeName
* Signature: (J)Ljava/lang/String;
*/
jstring JyNIgetNativeTypeName(JNIEnv *env, jclass class, jlong handle)
{
if (handle) {
return (*env)->NewStringUTF(env, Py_TYPE((PyObject*) handle)->tp_name);
} else
return NULL;
}
/*
* Class: JyNI_JyNI
* Method: releaseWeakReferent
* Signature: (JJ)V
*/
void JyNI_releaseWeakReferent(JNIEnv *env, jclass class, jlong handle, jlong tstate)
{
ENTER_JyNI
decWeakRefCount(AS_JY((PyObject*) handle));
Py_DECREF(handle);
LEAVE_JyNI
}
/*
* Class: JyNI_JyNI
* Method: PyCFunction_getSelf
* Signature: (JJ)Lorg/python/core/PyObject;
*/
jobject JyNI_PyCFunction_getSelf(jlong handle, jlong tstate)
{
jobject jres;
// jputs(__FUNCTION__);
env(NULL);
RE_ENTER_JyNI
jres = JyNI_JythonPyObject_FromPyObject(
((PyCFunctionObject*) handle)->m_self);
RE_LEAVE_JyNI
return jres;
}
/*
* Class: JyNI_JyNI
* Method: PyCFunction_getModule
* Signature: (JJ)Lorg/python/core/PyObject;
*/
jobject JyNI_PyCFunction_getModule(jlong handle, jlong tstate)
{
jobject jres;
RE_ENTER_JyNI
jres = JyNI_JythonPyObject_FromPyObject(
((PyCFunctionObject*) handle)->m_module);
RE_LEAVE_JyNI
return jres;
}
/*
* Class: JyNI_JyNI
* Method: JyNI_CMethodDef_bind
* Signature: (JJ)Lorg/python/core/PyObject;
*/
jobject JyNI_CMethodDef_bind(jlong handle, jobject bindTo, jlong tstate)
{
jobject jres;
RE_ENTER_JyNI
{
PyObject* self = JyNI_PyObject_FromJythonPyObject(bindTo);
PyObject* res = PyCFunction_New((PyMethodDef*) handle, self);
jres = JyNI_JythonPyObject_FromPyObject(res);
Py_DECREF(res);
Py_DECREF(self);
}
RE_LEAVE_JyNI
return jres;
}
//PySys_GetObject creates new object
/*Builtin types not relevant for Jython (?):
EncodingMapType,
wrappertype,
cmpwrapper_type,
sortwrapper_type,
Long_InfoType,
FloatInfoType,
_struct_sequence_template
PyGetSetDescr_Type;
PyMemberDescr_Type;
PyWrapperDescr_Type;
// PyDictIterKey_Type;
// PyDictIterValue_Type;
// PyDictIterItem_Type;
// PyDictKeys_Type;
// PyDictItems_Type;
// PyDictValues_Type;
// PyReversed_Type;
PyFormatterIter_Type;
PyFieldNameIter_Type;
//Types currently not cared for, but of potential relevance:
PyListIter_Type
PyListRevIter_Type
// PyClassMethod_Type
// PyStaticMethod_Type
PyClassMethodDescr_Type
PyDictProxy_Type
PyProperty_Type
PyBaseString_Type
// PySeqIter_Type
// PyRange_Type
// Pyrangeiter_Type
PyTupleIter_Type
// PySetIter_Type
// PyEnum_Type
// PyGen_Type
// PyFrame_Type
// PySuper_Type
// PyBuffer_Type
// PyMemoryView_Type
PyBaseObject_Type
// PyCallIter_Type
//maybe we can later support this via PyArray:
PyByteArrayIter_Type;
*/
inline void initBuiltinTypes()
{
/*
* JyNI GC-Notes:
*
* CStubs' heads should not contain links to gc-heads unless
* it is only partly truncated and a gc-relevant native
* PyObject-reference remains. Only a link to the PyObject
* should exist.
*
* SimpleGCHeads should be replaced by ordinary ones to save
* re-creation time if native objects are passed to Java.
*
* If weak refs are used to track collection of heads, the
* handle must be contained in the ref, maybe it's feasible
* to have it *only* there.
*
* Non-traversable native objects only need gc-heads in
* GIL-free mode.
*
* Mirrored objects may have gc-heads even in GIL-mode to
* let a SoftReference cache the Java-side object.
* Traversable mirrored objects must have their gchead
* track references of the native object. The mirrored
* Java-PyObject shall be SoftReferenced.
*
* Special-case PyList:
* Let JyList implement TraversableGCHead and PyObjectGCHead.
* Basically the situation is the same as with PyCPeerGC, but
* with JyList fulfilling the role of gc-head. The JyList should
* also cause an incref to the native counterpart. This replaces
* the current immortality incref in JySync.c.
* Maintain a SoftReference to the PyList and gc-head links
* to all native traversable elements.
* Further reason whether
* - to use element-access to check if heads are up to date
* - to use gc-heads as cache of natively saved objects, i.e.
* saving some JNI-calls.
*
* Special-case PyCell:
* Like PyList, but only with one element.
*
* Special-case PySet/PyFrozenSet:
* Note that size-field sync currently might not be thread-safe.
* Todo: Use native setter to inject the JySet into the PySet.
* GC-situation is like CStub. Consider to not even mark it as
* special case, but let it be treated in line with ordinary
* CStubs/truncated objects.
*
* Later the collect_generations-method will also look for objects
* inserted for tracking into the ordinary gc-head-list. This is in
* case an extension uses the old _PyObject_GC_TRACK-macro (not used
* by JyNI any more).
*/
// int i;
// for (i = 0; i < builtinTypeCount; ++i)
// {
// builtinTypes[i].py_type = NULL;
// builtinTypes[i].jy_class = NULL;
// builtinTypes[i].flags = 0;
// builtinTypes[i].sync = NULL;
// builtinTypes[i].truncate_trailing = 0;
// builtinTypes[i].type_name = NULL;
// }
builtinTypes[TME_INDEX_Type].py_type = &PyType_Type;
builtinTypes[TME_INDEX_Type].jy_class = pyTypeClass;
//builtinTypes[TME_INDEX_Type].flags = JY_TRUNCATE_FLAG_MASK;
//builtinTypes[TME_INDEX_Type].truncate_trailing = sizeof(PyTypeObject)-sizeof(PyVarObject);
//builtinTypes[TME_INDEX_Type].truncate_trailing = sizeof(PyTypeObject)-sizeof(PyObject);
//In fact, the trailing is so large that actually nothing is truncated.
//This currently serves testing purposes. We are still checking out,
//which fields are crucial and which are not. Although the only macros that
//access PyType directly just need tp_flags, there are several direct accesses to
//tp_-variables throughout CPython source.
builtinTypes[TME_INDEX_Type].sync = malloc(sizeof(SyncFunctions));
//builtinTypes[TME_INDEX_Type].sync->py2jy = (py2jySync) JySync_JyType_From_PyType;
builtinTypes[TME_INDEX_Type].sync->jy2py = (jy2pySync) JySync_PyType_From_JyType;
builtinTypes[TME_INDEX_NotImplemented].py_type = &PyNotImplemented_Type; //(_Py_NotImplementedStruct.ob_type);
builtinTypes[TME_INDEX_NotImplemented].jy_class = pyNotImplementedClass;
//builtinTypes[TME_INDEX_NotImplemented].flags = 0;
builtinTypes[TME_INDEX_None].py_type = &PyNone_Type;//(_Py_NoneStruct.ob_type);
builtinTypes[TME_INDEX_None].jy_class = pyNoneClass;
//builtinTypes[TME_INDEX_None].flags = 0;
builtinTypes[TME_INDEX_File].py_type = &PyFile_Type;
builtinTypes[TME_INDEX_File].jy_class = pyFileClass;
builtinTypes[TME_INDEX_File].flags = JY_TRUNCATE_FLAG_MASK;
PyFile_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
//In JyNI no GC-type since it is fully truncated.
builtinTypes[TME_INDEX_Module].py_type = &PyModule_Type;
builtinTypes[TME_INDEX_Module].jy_class = pyModuleClass;
builtinTypes[TME_INDEX_Module].flags = JY_TRUNCATE_FLAG_MASK;
PyModule_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Cell].py_type = &PyCell_Type;
builtinTypes[TME_INDEX_Cell].jy_class = pyCellClass;
//builtinTypes[TME_INDEX_Cell].flags = JY_GC_FIXED_SIZE; //JY_GC_SINGLE_LINK | JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Cell].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Cell].sync->py2jy = (py2jySync) JySync_JyCell_From_PyCell;
builtinTypes[TME_INDEX_Cell].sync->jy2py = (jy2pySync) JySync_PyCell_From_JyCell;
PyCell_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Class].py_type = &PyClass_Type;
builtinTypes[TME_INDEX_Class].jy_class = pyClassClass;
builtinTypes[TME_INDEX_Class].flags = JySYNC_ON_INIT_FLAGS;// | JY_GC_FIXED_SIZE; // 6 links
builtinTypes[TME_INDEX_Class].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Class].sync->jyInit = (jyInitSync) JySync_Init_JyClass_From_PyClass;
builtinTypes[TME_INDEX_Class].sync->pyInit = (pyInitSync) JySync_Init_PyClass_From_JyClass;
PyClass_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Instance].py_type = &PyInstance_Type;
builtinTypes[TME_INDEX_Instance].jy_class = pyInstanceClass;
builtinTypes[TME_INDEX_Instance].flags = JySYNC_ON_INIT_FLAGS;// | JY_GC_FIXED_SIZE; // 2 links
builtinTypes[TME_INDEX_Instance].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Instance].sync->jyInit = (jyInitSync) JySync_Init_JyInstance_From_PyInstance;
builtinTypes[TME_INDEX_Instance].sync->pyInit = (pyInitSync) JySync_Init_PyInstance_From_JyInstance;
PyInstance_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
// specialPyInstance.py_type = &PyInstance_Type;
// specialPyInstance.jy_class = pyInstanceClass;
// specialPyInstance.flags = JySYNC_ON_INIT_FLAGS;// | JY_GC_FIXED_SIZE; // 2 links
// specialPyInstance.sync = malloc(sizeof(SyncFunctions));
// specialPyInstance.sync->pyInit = (pyInitSync) JySync_Init_Special_PyInstance;
builtinTypes[TME_INDEX_Method].py_type = &PyMethod_Type;
builtinTypes[TME_INDEX_Method].jy_class = pyMethodClass;
builtinTypes[TME_INDEX_Method].flags = JySYNC_ON_INIT_FLAGS;// | JY_GC_FIXED_SIZE; // 3 links
builtinTypes[TME_INDEX_Method].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Method].sync->jyInit = (jyInitSync) JySync_Init_JyMethod_From_PyMethod;
builtinTypes[TME_INDEX_Method].sync->pyInit = (pyInitSync) JySync_Init_PyMethod_From_JyMethod;
PyMethod_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
//Note: PyFunction is actually truncated in the sense that JyNI does not populate
//all fields. However no memory can be saved because e.g. the last field func_module
//is mirrored. This is needed e.g. for the PyFunction_GET_MODULE-macro.
//In order to let the gcmodule get this right as a partly CStub, we still mark it
//truncated and supply full length as truncate_trailing.
builtinTypes[TME_INDEX_Function].py_type = &PyFunction_Type;
builtinTypes[TME_INDEX_Function].jy_class = pyFunctionClass;
//builtinTypes[TME_INDEX_Function].flags = JY_GC_FIXED_SIZE; // 5 (8) links
//This variant currently fails with delegation. Todo: Fix this.
//builtinTypes[TME_INDEX_Function].flags = JY_TRUNCATE_FLAG_MASK;
//builtinTypes[TME_INDEX_Function].truncate_trailing = 9*sizeof(PyObject*);
builtinTypes[TME_INDEX_Function].sync = malloc(sizeof(SyncFunctions));
//builtinTypes[TME_INDEX_Function].sync->jyInit = NULL;//(jyInitSync) JySync_Init_JyFunction_From_PyFunction;
//builtinTypes[TME_INDEX_Function].sync->pyInit = (pyInitSync) JySync_Init_PyFunction_From_JyFunction;
builtinTypes[TME_INDEX_Function].sync->jy2py = (jy2pySync) JySync_PyFunction_From_JyFunction;
PyFunction_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_ClassMethod].py_type = &PyClassMethod_Type;
builtinTypes[TME_INDEX_ClassMethod].jy_class = pyClassMethodClass;
builtinTypes[TME_INDEX_ClassMethod].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_ClassMethod].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_ClassMethod].sync->jyInit = (jyInitSync) JySync_Init_JyClassMethod_From_PyClassMethod;
builtinTypes[TME_INDEX_ClassMethod].sync->pyInit = (pyInitSync) JySync_Init_PyClassMethod_From_JyClassMethod;
PyClassMethod_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_StaticMethod].py_type = &PyStaticMethod_Type;
builtinTypes[TME_INDEX_StaticMethod].jy_class = pyStaticMethodClass;
builtinTypes[TME_INDEX_StaticMethod].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_StaticMethod].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_StaticMethod].sync->jyInit = (jyInitSync) JySync_Init_JyStaticMethod_From_PyStaticMethod;
builtinTypes[TME_INDEX_StaticMethod].sync->pyInit = (pyInitSync) JySync_Init_PyStaticMethod_From_JyStaticMethod;
PyStaticMethod_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_CFunction].py_type = &PyCFunction_Type;
builtinTypes[TME_INDEX_CFunction].jy_class = pyBuiltinCallableClass;//pyCFunctionClass;
builtinTypes[TME_INDEX_CFunction].flags = JySYNC_ON_INIT_FLAGS;// | JY_CPEER_FLAG_MASK;
builtinTypes[TME_INDEX_CFunction].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_CFunction].sync->jyInit = (jyInitSync) JySync_Init_JyCFunction_From_PyCFunction;
builtinTypes[TME_INDEX_CFunction].sync->pyInit = (pyInitSync) JySync_Init_PyCFunction_From_JyBuiltinCallable;
PyStaticMethod_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_MethodDescr].py_type = &PyMethodDescr_Type;
builtinTypes[TME_INDEX_MethodDescr].jy_class = pyMethodDescrClass;
builtinTypes[TME_INDEX_MethodDescr].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_MethodDescr].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_MethodDescr].sync->jyInit = (jyInitSync) JySync_Init_JyMethodDescr_From_PyMethodDescr;
builtinTypes[TME_INDEX_MethodDescr].sync->pyInit = (pyInitSync) JySync_Init_PyMethodDescr_From_JyMethodDescr;
PyMethodDescr_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
/* builtinTypes[TME_INDEX_ClassMethodDescr].py_type = &PyClassMethodDescr_Type;
builtinTypes[TME_INDEX_ClassMethodDescr].jy_class = pyClassMethodDescrClass;
builtinTypes[TME_INDEX_ClassMethodDescr].flags = 0;
PyClassMethodDescr_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;*/
builtinTypes[TME_INDEX_DictProxy].py_type = &PyDictProxy_Type;
builtinTypes[TME_INDEX_DictProxy].jy_class = pyDictProxyClass;
builtinTypes[TME_INDEX_DictProxy].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_DictProxy].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_DictProxy].sync->jyInit = (jyInitSync) JySync_Init_JyDictProxy_From_PyDictProxy;
builtinTypes[TME_INDEX_DictProxy].sync->pyInit = (pyInitSync) JySync_Init_PyDictProxy_From_JyDictProxy;
PyDictProxy_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Property].py_type = &PyProperty_Type;
builtinTypes[TME_INDEX_Property].jy_class = pyPropertyClass;
builtinTypes[TME_INDEX_Property].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Property].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Property].sync->jyInit = (jyInitSync) JySync_Init_JyProperty_From_PyProperty;
builtinTypes[TME_INDEX_Property].sync->pyInit = (pyInitSync) JySync_Init_PyProperty_From_JyProperty;
PyProperty_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Bool].py_type = &PyBool_Type;
builtinTypes[TME_INDEX_Bool].jy_class = pyBooleanClass;
//builtinTypes[TME_INDEX_Bool].flags = 0;
builtinTypes[TME_INDEX_Float].py_type = &PyFloat_Type;
builtinTypes[TME_INDEX_Float].jy_class = pyFloatClass;
builtinTypes[TME_INDEX_Float].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Float].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Float].sync->jyInit = (jyInitSync) JySync_Init_JyFloat_From_PyFloat;
builtinTypes[TME_INDEX_Float].sync->pyInit = (pyInitSync) JySync_Init_PyFloat_From_JyFloat;
PyFloat_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Int].py_type = &PyInt_Type;
builtinTypes[TME_INDEX_Int].jy_class = pyIntClass;
builtinTypes[TME_INDEX_Int].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Int].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Int].sync->jyInit = (jyInitSync) JySync_Init_JyInt_From_PyInt;
builtinTypes[TME_INDEX_Int].sync->pyInit = (pyInitSync) JySync_Init_PyInt_From_JyInt;
PyInt_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
//for computational efficiency we mirror PyLong, although it could also be wrapped
//later we are going to offer both options by a configuration-parameter in JyNI.
builtinTypes[TME_INDEX_Long].py_type = &PyLong_Type;
builtinTypes[TME_INDEX_Long].jy_class = pyLongClass;
builtinTypes[TME_INDEX_Long].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Long].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Long].sync->jyInit = (jyInitSync) JySync_Init_JyLong_From_PyLong;
builtinTypes[TME_INDEX_Long].sync->pyInit = (pyInitSync) JySync_Init_PyLong_From_JyLong;
PyLong_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Complex].py_type = &PyComplex_Type;
builtinTypes[TME_INDEX_Complex].jy_class = pyComplexClass;
builtinTypes[TME_INDEX_Complex].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Complex].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Complex].sync->jyInit = (jyInitSync) JySync_Init_JyComplex_From_PyComplex;
builtinTypes[TME_INDEX_Complex].sync->pyInit = (pyInitSync) JySync_Init_PyComplex_From_JyComplex;
PyComplex_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Unicode].py_type = &PyUnicode_Type;
builtinTypes[TME_INDEX_Unicode].jy_class = pyUnicodeClass;
builtinTypes[TME_INDEX_Unicode].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Unicode].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Unicode].sync->jyInit = (jyInitSync) JySync_Init_JyUnicode_From_PyUnicode;
builtinTypes[TME_INDEX_Unicode].sync->pyInit = (pyInitSync) JySync_Init_PyUnicode_From_JyUnicode;
PyUnicode_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_String].py_type = &PyString_Type;
builtinTypes[TME_INDEX_String].jy_class = pyStringClass;
builtinTypes[TME_INDEX_String].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_String].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_String].sync->jyInit = (jyInitSync) JySync_Init_JyString_From_PyString;
builtinTypes[TME_INDEX_String].sync->pyInit = (pyInitSync) JySync_Init_PyString_From_JyString;
PyString_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Weakref_Ref].py_type = &_PyWeakref_RefType;
builtinTypes[TME_INDEX_Weakref_Ref].jy_class = pyWeakReferenceClass;
builtinTypes[TME_INDEX_Weakref_Ref].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Weakref_Ref].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Weakref_Ref].sync->jyInit = (jyInitSync) JySync_Init_JyWeakReference_From_PyWeakReference;
builtinTypes[TME_INDEX_Weakref_Ref].sync->pyInit = (pyInitSync) JySync_Init_PyWeakReference_From_JyWeakReference;
_PyWeakref_RefType.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Weakref_Proxy].py_type = &_PyWeakref_ProxyType;
builtinTypes[TME_INDEX_Weakref_Proxy].jy_class = pyWeakProxyClass;
builtinTypes[TME_INDEX_Weakref_Proxy].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Weakref_Proxy].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Weakref_Proxy].sync->jyInit = (jyInitSync) JySync_Init_JyWeakProxy_From_PyWeakProxy;
builtinTypes[TME_INDEX_Weakref_Proxy].sync->pyInit = (pyInitSync) JySync_Init_PyWeakProxy_From_JyWeakProxy;
_PyWeakref_ProxyType.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_Weakref_CallableProxy].py_type = &_PyWeakref_CallableProxyType;
builtinTypes[TME_INDEX_Weakref_CallableProxy].jy_class = pyWeakCallableProxyClass;
builtinTypes[TME_INDEX_Weakref_CallableProxy].flags = JySYNC_ON_INIT_FLAGS;
builtinTypes[TME_INDEX_Weakref_CallableProxy].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Weakref_CallableProxy].sync->jyInit =
(jyInitSync) JySync_Init_JyWeakCallableProxy_From_PyWeakCallableProxy;
builtinTypes[TME_INDEX_Weakref_CallableProxy].sync->pyInit =
(pyInitSync) JySync_Init_PyWeakCallableProxy_From_JyWeakCallableProxy;
_PyWeakref_CallableProxyType.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
/* builtinTypes[TME_INDEX_BaseString].py_type = &PyBaseString_Type;
builtinTypes[TME_INDEX_BaseString].jy_class = pyBaseStringClass;
builtinTypes[TME_INDEX_BaseString].flags = 0;
PyBaseStringType.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;*/
builtinTypes[TME_INDEX_SeqIter].py_type = &PySeqIter_Type;
builtinTypes[TME_INDEX_SeqIter].jy_class = pySequenceIterClass;
builtinTypes[TME_INDEX_SeqIter].flags = JY_TRUNCATE_FLAG_MASK;
PySeqIter_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
/* builtinTypes[TME_INDEX_Range].py_type = &PyRange_Type;
builtinTypes[TME_INDEX_Range].jy_class = pyXRangeClass;
builtinTypes[TME_INDEX_Range].flags = 0;
PyRange_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_rangeiter].py_type = &Pyrangeiter_Type; //jython uses PySequenceIter. Map this to PySeqIter_Typ
builtinTypes[TME_INDEX_rangeiter].jy_class = pySequenceIterClass;
builtinTypes[TME_INDEX_rangeiter].flags = 0;
Pyrangeiter_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;*/
builtinTypes[TME_INDEX_Tuple].py_type = &PyTuple_Type;
builtinTypes[TME_INDEX_Tuple].jy_class = pyTupleClass;
builtinTypes[TME_INDEX_Tuple].jy_subclass = pyTupleCPeerClass;
builtinTypes[TME_INDEX_Tuple].flags = JySYNC_ON_INIT_FLAGS;// | JY_GC_FIXED_SIZE;// | GC_NO_INITIAL_EXPLORE; // Py_SIZE(o) links
builtinTypes[TME_INDEX_Tuple].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_Tuple].sync->jyInit = (jyInitSync) JySync_Init_JyTuple_From_PyTuple;
builtinTypes[TME_INDEX_Tuple].sync->pyInit = (pyInitSync) JySync_Init_PyTuple_From_JyTuple;
PyTuple_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
/* builtinTypes[TME_INDEX_TupleIter].py_type = &PyTupleIter_Type; //jython uses PyFastSequenceIter. Map this to PySeqIter_Type
builtinTypes[TME_INDEX_TupleIter].jy_class = pyFastSequenceIterClass;
builtinTypes[TME_INDEX_TupleIter].flags = 0;
PyTupleIter_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;*/
builtinTypes[TME_INDEX_List].py_type = &PyList_Type;
builtinTypes[TME_INDEX_List].jy_class = pyListClass;
builtinTypes[TME_INDEX_List].flags = JySYNC_ON_INIT_FLAGS | GC_CRITICAL | JY_GC_VAR_SIZE;
// | JY_GC_SPECIAL_CASE | GC_NO_INITIAL_EXPLORE;
builtinTypes[TME_INDEX_List].sync = malloc(sizeof(SyncFunctions));
builtinTypes[TME_INDEX_List].sync->jyInit = (jyInitSync) JySync_Init_JyList_From_PyList;
builtinTypes[TME_INDEX_List].sync->pyInit = (pyInitSync) JySync_Init_PyList_From_JyList;
PyList_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
/* builtinTypes[TME_INDEX_ListIter].py_type = &PyListIter_Type; //jython uses PyFastSequenceIter. Map this to PySeqIter_Type
builtinTypes[TME_INDEX_ListIter].jy_class = pyFastSequenceIterClass;
builtinTypes[TME_INDEX_ListIter].flags = 0;
PyListIter_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
builtinTypes[TME_INDEX_ListRevIter].py_type = &PyListRevIter_Type; //jython uses PyReversedIterator.
builtinTypes[TME_INDEX_ListRevIter].jy_class = pyReversedIteratorClass;
builtinTypes[TME_INDEX_ListRevIter].flags = 0;
PyListRevIter_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;*/
/* In JyNI no GC-type since it is fully truncated. */
// Todo: What about subtype/subclass?
builtinTypes[TME_INDEX_Dict].py_type = &PyDict_Type;
builtinTypes[TME_INDEX_Dict].jy_class = pyDictClass;
builtinTypes[TME_INDEX_Dict].jy_subclass = pyDictCPeerClass;
builtinTypes[TME_INDEX_Dict].flags = JY_TRUNCATE_FLAG_MASK;
PyDict_Type.tp_flags |= Jy_TPFLAGS_DYN_OBJECTS;
/* In the CPython->Java lookup direction, this is
overwritten by the previous entry with pyDictClass.
However, it ensures that pyStringMapClass has a valid
entry if the other lookup direction is done.
Native PyDict methods are implemented in a way that is
agnostic about whether PyDictionary or PyStringMap is used
on Java/Jython-side.
Would be GC-relevant, but is fully truncated. */
builtinTypes[TME_INDEX_StringMap].py_type = &PyDict_Type;
builtinTypes[TME_INDEX_StringMap].jy_class = pyStringMapClass;