Inheritance: CData, IDynamicMetaObjectProvider
コード例 #1
0
ファイル: ModuleOps.cs プロジェクト: slozier/ironpython3
        public static IntPtr /*!*/ GetFunctionPointerValue(object o, object type)
        {
            CTypes._CFuncPtr res = o as CTypes._CFuncPtr;
            if (res == null && PythonOps.TryGetBoundAttr(o, "_as_parameter_", out object asParam))
            {
                res = asParam as CTypes._CFuncPtr;
            }

            if (res == null || res.NativeType != type)
            {
                throw ArgumentError(type, ((PythonType)type).Name, o);
            }

            return(res.addr);
        }
コード例 #2
0
ファイル: ModuleOps.cs プロジェクト: kayur/ironpython
 public static bool CheckFunctionId(CTypes._CFuncPtr func, int id)
 {
     return(func.Id == id);
 }
コード例 #3
0
ファイル: ModuleOps.cs プロジェクト: wangpei421/ironpython2
        public static IntPtr GetPointer(object value)
        {
            if (value is int)
            {
                int iVal = (int)value;
                if (iVal >= 0)
                {
                    return(new IntPtr(iVal));
                }
            }

            if (value is BigInteger)
            {
                return(new IntPtr((long)(BigInteger)value));
            }

            if (value is Int64)
            {
                return(new IntPtr((Int64)value));
            }

            if (value == null)
            {
                return(IntPtr.Zero);
            }

            object asParam;

            if (PythonOps.TryGetBoundAttr(value, "_as_parameter_", out asParam))
            {
                return(GetPointer(asParam));
            }

            CTypes.SimpleCData sd = value as CTypes.SimpleCData;
            if (sd != null)
            {
                CTypes.SimpleType simpType = (CTypes.SimpleType)sd.NativeType;
                if (simpType._type == CTypes.SimpleTypeKind.WCharPointer ||
                    simpType._type == CTypes.SimpleTypeKind.CharPointer)
                {
                    return(sd.UnsafeAddress);
                }
                else if (simpType._type == CTypes.SimpleTypeKind.Pointer)
                {
                    return(sd._memHolder.ReadIntPtr(0));
                }
            }

            CTypes._Array arr = value as CTypes._Array;
            if (arr != null)
            {
                return(arr.UnsafeAddress);
            }

            CTypes._CFuncPtr func = value as CTypes._CFuncPtr;
            if (func != null)
            {
                return(func.UnsafeAddress);
            }

            CTypes.Pointer pointer = value as CTypes.Pointer;
            if (pointer != null)
            {
                return(pointer.UnsafeAddress);
            }

            throw PythonOps.TypeErrorForTypeMismatch("pointer", value);
        }