GetBoundArgTuple() static private method

static private GetBoundArgTuple ( IntPtr obj, IntPtr args ) : IntPtr
obj System.IntPtr
args System.IntPtr
return System.IntPtr
示例#1
0
        //====================================================================
        // Metatype __call__ implementation. This is needed to ensure correct
        // initialization (__init__ support), because the tp_call we inherit
        // from PyType_Type won't call __init__ for metatypes it doesnt know.
        //====================================================================

        public static IntPtr tp_call(IntPtr tp, IntPtr args, IntPtr kw)
        {
            IntPtr func = Marshal.ReadIntPtr(tp, TypeOffset.tp_new);

            if (func == IntPtr.Zero)
            {
                return(Exceptions.RaiseTypeError("invalid object"));
            }

            IntPtr obj = NativeCall.Call_3(func, tp, args, kw);

            if (obj == IntPtr.Zero)
            {
                return(IntPtr.Zero);
            }

            IntPtr py__init__ = Runtime.PyString_FromString("__init__");
            IntPtr type       = Runtime.PyObject_TYPE(obj);
            IntPtr init       = Runtime._PyType_Lookup(type, py__init__);

            Runtime.Decref(py__init__);
            Runtime.PyErr_Clear();

            if (init != IntPtr.Zero)
            {
                IntPtr bound = Runtime.GetBoundArgTuple(obj, args);
                if (bound == IntPtr.Zero)
                {
                    Runtime.Decref(obj);
                    return(IntPtr.Zero);
                }

                IntPtr result = Runtime.PyObject_Call(init, bound, kw);
                Runtime.Decref(bound);

                if (result == IntPtr.Zero)
                {
                    Runtime.Decref(obj);
                    return(IntPtr.Zero);
                }

                Runtime.Decref(result);
            }

            return(obj);
        }