Beispiel #1
0
        //====================================================================
        // OverloadMapper dealloc implementation.
        //====================================================================

        public static new void tp_dealloc(IntPtr ob)
        {
            OverloadMapper self = (OverloadMapper)GetManagedObject(ob);

            Runtime.Decref(self.target);
            ExtensionType.FinalizeObject(self);
        }
Beispiel #2
0
        /// <summary>
        /// MethodBinding __getattribute__ implementation.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var self = (MethodBinding)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            string name = Runtime.GetManagedString(key);

            switch (name)
            {
            case "__doc__":
                IntPtr doc = self.m.GetDocString();
                Runtime.XIncref(doc);
                return(doc);

            // FIXME: deprecate __overloads__ soon...
            case "__overloads__":
            case "Overloads":
                var om = new OverloadMapper(self.m, self.target);
                return(om.pyHandle);

            default:
                return(Runtime.PyObject_GenericGetAttr(ob, key));
            }
        }
Beispiel #3
0
        //====================================================================
        // Implement explicit overload selection using subscript syntax ([]).
        //====================================================================

        public static IntPtr mp_subscript(IntPtr tp, IntPtr idx)
        {
            OverloadMapper self = (OverloadMapper)GetManagedObject(tp);

            // Note: if the type provides a non-generic method with N args
            // and a generic method that takes N params, then we always
            // prefer the non-generic version in doing overload selection.

            Type[] types = Runtime.PythonArgsToTypeArray(idx);
            if (types == null)
            {
                return(Exceptions.RaiseTypeError("type(s) expected"));
            }

            MethodInfo mi = MethodBinder.MatchSignature(self.m.info, types);

            if (mi == null)
            {
                string e = "No match found for signature";
                return(Exceptions.RaiseTypeError(e));
            }

            MethodBinding mb = new MethodBinding(self.m, self.target);

            mb.info = mi;
            Runtime.Incref(mb.pyHandle);
            return(mb.pyHandle);
        }
Beispiel #4
0
        //====================================================================
        // MethodBinding __getattribute__ implementation.
        //====================================================================

        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            MethodBinding self = (MethodBinding)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            string name = Runtime.GetManagedString(key);

            if (name == "__doc__")
            {
                IntPtr doc = self.m.GetDocString();
                Runtime.Incref(doc);
                return(doc);
            }

            if (name == "__overloads__")
            {
                OverloadMapper om = new OverloadMapper(self.m, self.target);
                Runtime.Incref(om.pyHandle);
                return(om.pyHandle);
            }

            return(Runtime.PyObject_GenericGetAttr(ob, key));
        }
Beispiel #5
0
        //====================================================================
        // OverloadMapper  __repr__ implementation.
        //====================================================================

        public static IntPtr tp_repr(IntPtr op)
        {
            OverloadMapper self = (OverloadMapper)GetManagedObject(op);
            IntPtr         doc  = self.m.GetDocString();

            Runtime.XIncref(doc);
            return(doc);
        }
Beispiel #6
0
        /// <summary>
        /// MethodBinding __getattribute__ implementation.
        /// </summary>
        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            var self = (MethodBinding)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            string name = InternString.GetManagedString(key);

            switch (name)
            {
            case "__doc__":
                IntPtr doc = self.m.GetDocString();
                Runtime.XIncref(doc);
                return(doc);

            // FIXME: deprecate __overloads__ soon...
            case "__overloads__":
            case "Overloads":
                var om = new OverloadMapper(self.m, self.target);
                return(om.pyHandle);

            case "__signature__" when Runtime.InspectModule is not null:
                var sig = self.Signature;
                if (sig is null)
                {
                    return(Runtime.PyObject_GenericGetAttr(ob, key));
                }
                return(sig.NewReferenceOrNull().DangerousMoveToPointerOrNull());

            case "__name__":
                return(self.m.GetName().DangerousMoveToPointerOrNull());

            default:
                return(Runtime.PyObject_GenericGetAttr(ob, key));
            }
        }
Beispiel #7
0
        //====================================================================
        // MethodBinding __getattribute__ implementation. 
        //====================================================================

        public static IntPtr tp_getattro(IntPtr ob, IntPtr key) {
            MethodBinding self = (MethodBinding)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key)) {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return IntPtr.Zero;
            }

            string name = Runtime.GetManagedString(key);
            if (name == "__doc__") {
                IntPtr doc = self.m.GetDocString();
                Runtime.Incref(doc);
                return doc;
            }

            // XXX deprecate __overloads__ soon...
            if (name == "__overloads__" || name == "Overloads") {
                OverloadMapper om = new OverloadMapper(self.m, self.target);
                Runtime.Incref(om.pyHandle);
                return om.pyHandle;            
            }

            return Runtime.PyObject_GenericGetAttr(ob, key);
        }