상속: CData, ICodeFormattable
예제 #1
0
        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 == 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.Pointer pointer = value as CTypes.Pointer;
            if (pointer != null)
            {
                return(pointer.UnsafeAddress);
            }

            throw PythonOps.TypeErrorForTypeMismatch("pointer", value);
        }
예제 #2
0
        public static CTypes.CData CheckSimpleCDataType(object o, object type)
        {
            CTypes.SimpleCData res = o as CTypes.SimpleCData;
            if (res == null && PythonOps.TryGetBoundAttr(o, "_as_parameter_", out object asParam))
            {
                res = asParam as CTypes.SimpleCData;
            }

            if (res != null && res.NativeType != type)
            {
                throw PythonOps.TypeErrorForTypeMismatch(((PythonType)type).Name, o);
            }

            return(res);
        }