Ejemplo n.º 1
0
        /// <summary>
        /// Returns the number of bytes of memory required to allocate the object.
        /// </summary>
        public static int __sizeof__(object self)
        {
            IPythonObject ipo = self as IPythonObject;
            int           res = AdjustPointerSize(8); // vtable, sync blk

            if (ipo != null)
            {
                res += AdjustPointerSize(12); // class, dict, slots
            }

            Type t = PythonTypeOps.GetFinalSystemType(DynamicHelpers.GetPythonType(self));

            res += GetTypeSize(t);

            return(res);
        }
Ejemplo n.º 2
0
        internal static Binding.FastBindResult <T> MakeGetBinding <T>(CodeContext codeContext, CallSite <T> site, IPythonObject self, Binding.PythonGetMemberBinder getBinder) where T : class
        {
            Type finalType = PythonTypeOps.GetFinalSystemType(self.PythonType.UnderlyingSystemType);

            if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(finalType) &&
                !(self is IFastGettable))
            {
                // very tricky, user is inheriting from a class which implements IDO, we
                // don't optimize this yet.
                return(new Binding.FastBindResult <T>());
            }
            return((Binding.FastBindResult <T>)(object) new Binding.MetaUserObject.FastGetBinderHelper(
                       codeContext,
                       (CallSite <Func <CallSite, object, CodeContext, object> >)(object) site,
                       self,
                       getBinder).GetBinding(codeContext, getBinder.Name));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a builtin function for the given declaring type and member infos.
        ///
        /// Given the same inputs this always returns the same object ensuring there's only 1 builtinfunction
        /// for each .NET method.
        ///
        /// This method takes both a cacheName and a pythonName.  The cache name is the real method name.  The pythonName
        /// is the name of the method as exposed to Python.
        /// </summary>
        internal static BuiltinFunction /*!*/ GetBuiltinFunction(Type /*!*/ type, string /*!*/ cacheName, string /*!*/ pythonName, FunctionType?funcType, params MemberInfo /*!*/[] /*!*/ mems)
        {
            BuiltinFunction res = null;

            if (mems.Length != 0)
            {
                FunctionType ft = funcType ?? GetMethodFunctionType(type, mems);
                type = GetBaseDeclaringType(type, mems);

                BuiltinFunctionKey cache = new BuiltinFunctionKey(type, new ReflectionCache.MethodBaseCache(cacheName, GetNonBaseHelperMethodInfos(mems)), ft);

                lock (_functions) {
                    if (!_functions.TryGetValue(cache, out res))
                    {
                        if (PythonTypeOps.GetFinalSystemType(type) == type)
                        {
                            IList <MethodInfo> overriddenMethods = NewTypeMaker.GetOverriddenMethods(type, cacheName);

                            if (overriddenMethods.Count > 0)
                            {
                                List <MemberInfo> newMems = new List <MemberInfo>(mems);

                                foreach (MethodInfo mi in overriddenMethods)
                                {
                                    newMems.Add(mi);
                                }

                                mems = newMems.ToArray();
                            }
                        }

                        _functions[cache] = res = BuiltinFunction.MakeMethod(pythonName, ReflectionUtils.GetMethodInfos(mems), type, ft);
                    }
                }
            }

            return(res);
        }