Пример #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._Array TryCheckWCharArray(object o)
        {
            CTypes._Array array = o as CTypes._Array;
            if (array != null)
            {
                CTypes.SimpleType elemType = ((CTypes.ArrayType)array.NativeType).ElementType as CTypes.SimpleType;
                if (elemType != null && elemType._type == CTypes.SimpleTypeKind.WChar)
                {
                    return(array);
                }
            }

            return(null);
        }