@@ -26,17 +26,33 @@ public class Runtime {
2626 /// the responsibility of the caller to have acquired the GIL
2727 /// before calling any of these methods.
2828 /// </summary>
29+ #if ( UCS4 )
30+ public const int UCS = 4 ;
31+ #endif
32+ #if ( UCS2 )
33+ public const int UCS = 2 ;
34+ #endif
35+ #if ! ( UCS2 || UCS4 )
36+ #error You must define either UCS2 or UCS4!
37+ #endif
38+
2939#if ( PYTHON24 )
30- internal const string dll = "python24" ;
40+ public const string dll = "python24" ;
41+ public const string pyversion = "2.4" ;
42+ public const int pyversionnumber = 24 ;
3143#endif
3244#if ( PYTHON25 )
33- internal const string dll = "python25" ;
45+ public const string dll = "python25" ;
46+ public const string pyversion = "2.5" ;
47+ public const int pyversionnumber = 25 ;
3448#endif
3549#if ( PYTHON26 )
36- internal const string dll = "python26" ;
50+ public const string dll = "python26" ;
51+ public const string pyversion = "2.6" ;
52+ public const int pyversionnumber = 26 ;
3753#endif
3854#if ! ( PYTHON24 || PYTHON25 || PYTHON26 )
39- #error You must define either PYTHON24 or PYTHON25 !
55+ #error You must define either PYTHON24, PYTHON25 or PYTHON26 !
4056#endif
4157 internal static bool wrap_exceptions ;
4258 internal static bool is32bit ;
@@ -117,7 +133,7 @@ internal static void Initialize() {
117133 // of the Python runtime that do not allow new-style classes to
118134 // be used as exceptions (Python versions 2.4 and lower).
119135
120- #if ( PYTHON25 )
136+ #if ( PYTHON25 || PYTHON26 )
121137 wrap_exceptions = false ;
122138#else
123139 IntPtr m = PyImport_ImportModule ( "exceptions" ) ;
@@ -131,7 +147,6 @@ internal static void Initialize() {
131147 Runtime . Decref ( m ) ;
132148#endif
133149
134-
135150 // Initialize modules that depend on the runtime class.
136151 AssemblyManager . Initialize ( ) ;
137152 PyCLRMetaType = MetaType . Initialize ( ) ;
@@ -227,6 +242,10 @@ internal static IntPtr ExtendTuple(IntPtr t, params IntPtr[] args) {
227242 }
228243
229244 internal static Type [ ] PythonArgsToTypeArray ( IntPtr arg ) {
245+ return PythonArgsToTypeArray ( arg , false ) ;
246+ }
247+
248+ internal static Type [ ] PythonArgsToTypeArray ( IntPtr arg , bool mangleObjects ) {
230249 // Given a PyObject * that is either a single type object or a
231250 // tuple of (managed or unmanaged) type objects, return a Type[]
232251 // containing the CLR Type objects that map to those types.
@@ -246,6 +265,9 @@ internal static Type[] PythonArgsToTypeArray(IntPtr arg) {
246265
247266 for ( int i = 0 ; i < n ; i ++ ) {
248267 IntPtr op = Runtime . PyTuple_GetItem ( args , i ) ;
268+ if ( mangleObjects && ( ! Runtime . PyType_Check ( op ) ) ) {
269+ op = Runtime . PyObject_TYPE ( op ) ;
270+ }
249271 ManagedType mt = ManagedType . GetManagedObject ( op ) ;
250272
251273 if ( mt is ClassBase ) {
@@ -575,15 +597,20 @@ internal unsafe static extern IntPtr
575597
576598 internal unsafe static IntPtr
577599 PyObject_TYPE( IntPtr op ) {
578- void * p = ( void * ) op ;
579- if ( ( void * ) 0 == p) {
580- return IntPtr . Zero ;
600+ void * p = ( void * ) op ;
601+ if ( ( void * ) 0 == p) {
602+ return IntPtr . Zero ;
581603 }
604+ #if ( Py_DEBUG )
605+ int n = 3 ;
606+ #else
607+ int n = 1 ;
608+ #endif
582609 if ( is32bit ) {
583- return new IntPtr ( ( void * ) ( * ( ( uint * ) p + 1 ) ) ) ;
610+ return new IntPtr ( ( void * ) ( * ( ( uint * ) p + n ) ) ) ;
584611 }
585612 else {
586- return new IntPtr( ( void * ) ( * ( ( ulong * ) p + 1 ) ) ) ;
613+ return new IntPtr( ( void * ) ( * ( ( ulong * ) p + n ) ) ) ;
587614 }
588615 }
589616
@@ -1385,6 +1412,10 @@ internal unsafe static extern int
13851412 // Python type object API
13861413 //====================================================================
13871414
1415+ internal static bool PyType_Check ( IntPtr ob ) {
1416+ return PyObject_TypeCheck( ob, Runtime . PyTypeType ) ;
1417+ }
1418+
13881419 [ DllImport ( Runtime . dll , CallingConvention = CallingConvention . Cdecl,
13891420 ExactSpelling = true, CharSet = CharSet . Ansi ) ]
13901421 internal unsafe static extern bool
0 commit comments