def setcontents(self, value): if not isinstance(value, self._type_): raise TypeError("expected %s instead of %s" % (self._type_.__name__, type(value).__name__)) self._objects = {keepalive_key(1): value} if value._ensure_objects() is not None: self._objects[keepalive_key(0)] = value._objects value = value._buffer self._buffer[0] = value
def setcontents(self, value): if not isinstance(value, self._type_): raise TypeError("expected %s instead of %s" % ( self._type_.__name__, type(value).__name__)) self._objects = {keepalive_key(1):value} if value._ensure_objects() is not None: self._objects[keepalive_key(0)] = value._objects value = value._buffer self._buffer[0] = value
def __init__(self, argument=None): self.callable = None self.name = None self._objects = {keepalive_key(0): self} if isinstance(argument, int): self._buffer = _rawffi.Array('P').fromaddress(argument, 1) # XXX finish this one, we need to be able to jump there somehow elif callable(argument): self.callable = argument argtypes = [arg._ffiargshape for arg in self._argtypes_] restype = self._restype_._ffiletter self._ptr = _rawffi.CallbackPtr(argument, argtypes, restype) self._needs_free = True self._buffer = self._ptr.byptr() elif isinstance(argument, tuple) and len(argument) == 2: import ctypes self.name, self.dll = argument if isinstance(self.dll, str): self.dll = ctypes.CDLL(self.dll) # we need to check dll anyway self._getfuncptr([], ctypes.c_int) elif argument is None: return # needed for test.. else: raise TypeError("Unknown constructor %s" % (argument, ))
def __init__(self, argument=None): self.callable = None self.name = None self._objects = {keepalive_key(0):self} if isinstance(argument, int): self._buffer = _rawffi.Array('P').fromaddress(argument, 1) # XXX finish this one, we need to be able to jump there somehow elif callable(argument): self.callable = argument argtypes = [arg._ffiargshape for arg in self._argtypes_] restype = self._restype_._ffiletter self._ptr = _rawffi.CallbackPtr(argument, argtypes, restype) self._needs_free = True self._buffer = self._ptr.byptr() elif isinstance(argument, tuple) and len(argument) == 2: import ctypes self.name, self.dll = argument if isinstance(self.dll, str): self.dll = ctypes.CDLL(self.dll) # we need to check dll anyway self._getfuncptr([], ctypes.c_int) elif argument is None: return # needed for test.. else: raise TypeError("Unknown constructor %s" % (argument,))
def __init__(self, argument=None): self.name = None self._objects = {keepalive_key(0): self} self._needs_free = True if isinstance(argument, (int, long)): ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._ptr = _rawffi.FuncPtr(argument, ffiargs, ffires) self._buffer = self._ptr.byptr() elif callable(argument): self.callable = argument ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._ptr = _rawffi.CallbackPtr( self._wrap_callable(argument, self.argtypes), ffiargs, ffires) self._buffer = self._ptr.byptr() elif isinstance(argument, tuple) and len(argument) == 2: import ctypes self.name, self.dll = argument if isinstance(self.dll, str): self.dll = ctypes.CDLL(self.dll) # we need to check dll anyway ptr = self._getfuncptr([], ctypes.c_int) self._buffer = ptr.byptr() elif argument is None: # this is needed for casts self._buffer = _rawffi.Array('P')(1) return else: raise TypeError("Unknown constructor %s" % (argument, ))
def __set__(self, obj, value): fieldtype = self.ctype cobj = fieldtype.from_param(value) if ensure_objects(cobj) is not None: key = keepalive_key(self.num) store_reference(obj, key, cobj._objects) arg = cobj._get_buffer_value() if fieldtype._fficompositesize is not None: from ctypes import memmove dest = obj._buffer.fieldaddress(self.name) memmove(dest, arg, fieldtype._fficompositesize) else: obj._buffer.__setattr__(self.name, arg)
def __init__(self, *args): self.name = None self._objects = {keepalive_key(0): self} self._needs_free = True argument = None if len(args) == 1: argument = args[0] if isinstance(argument, (int, long)): # direct construction from raw address ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._ptr = _rawffi.FuncPtr(argument, ffiargs, ffires, self._flags_) self._buffer = self._ptr.byptr() elif callable(argument): # A callback into python self.callable = argument ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._ptr = _rawffi.CallbackPtr( self._wrap_callable(argument, self.argtypes), ffiargs, ffires, self._flags_) self._buffer = self._ptr.byptr() elif isinstance(argument, tuple) and len(argument) == 2: # function exported from a shared library import ctypes self.name, self.dll = argument if isinstance(self.dll, str): self.dll = ctypes.CDLL(self.dll) # we need to check dll anyway ptr = self._getfuncptr([], ctypes.c_int) self._buffer = ptr.byptr() elif (sys.platform == 'win32' and len(args) >= 2 and isinstance(args[0], (int, long))): # A COM function call, by index ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._com_index = args[0] + 0x1000 self.name = args[1] if len(args) > 2: self._paramflags = args[2] # XXX ignored iid = args[3] elif len(args) == 0: # Empty function object. # this is needed for casts self._buffer = _rawffi.Array('P')(1) return else: raise TypeError("Unknown constructor %s" % (args, ))
def __init__(self, *args): self.name = None self._objects = {keepalive_key(0):self} self._needs_free = True argument = None if len(args) == 1: argument = args[0] if isinstance(argument, (int, long)): # direct construction from raw address ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._ptr = _rawffi.FuncPtr(argument, ffiargs, ffires, self._flags_) self._buffer = self._ptr.byptr() elif callable(argument): # A callback into python self.callable = argument ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._ptr = _rawffi.CallbackPtr(self._wrap_callable(argument, self.argtypes), ffiargs, ffires, self._flags_) self._buffer = self._ptr.byptr() elif isinstance(argument, tuple) and len(argument) == 2: # function exported from a shared library import ctypes self.name, self.dll = argument if isinstance(self.dll, str): self.dll = ctypes.CDLL(self.dll) # we need to check dll anyway ptr = self._getfuncptr([], ctypes.c_int) self._buffer = ptr.byptr() elif (sys.platform == 'win32' and len(args) >= 2 and isinstance(args[0], (int, long))): # A COM function call, by index ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._com_index = args[0] + 0x1000 self.name = args[1] if len(args) > 2: self._paramflags = args[2] # XXX ignored iid = args[3] elif len(args) == 0: # Empty function object. # this is needed for casts self._buffer = _rawffi.Array('P')(1) return else: raise TypeError("Unknown constructor %s" % (args,))
def __setattr__(self, name, value): try: fieldtype = self._fieldtypes[name].ctype except KeyError: return _CData.__setattr__(self, name, value) if ensure_objects(value) is not None: key = keepalive_key(getattr(self.__class__, name).num) store_reference(self, key, value._objects) arg = fieldtype._CData_value(value) if fieldtype._fficompositesize is not None: from ctypes import memmove dest = self._buffer.fieldaddress(name) memmove(dest, arg, fieldtype._fficompositesize) else: self._buffer.__setattr__(name, arg)
def __setattr__(self, name, value): try: fieldtype = self._fieldtypes[name].ctype except KeyError: raise AttributeError(name) if getattr(value, '_objects', None): key = keepalive_key(getattr(self.__class__, name).offset) store_reference(self, key, value._objects) arg = fieldtype._CData_value(value) if isinstance(fieldtype._ffishape, tuple): from ctypes import memmove dest = self._buffer.fieldaddress(name) memmove(dest, arg._buffer.buffer, fieldtype._ffishape[0]) else: self._buffer.__setattr__(name, arg)
def __set__(self, obj, value): fieldtype = self.ctype cobj = fieldtype.from_param(value) key = keepalive_key(self.num) if issubclass(fieldtype, _Pointer) and isinstance(cobj, Array): # if our value is an Array we need the whole thing alive store_reference(obj, key, cobj) elif ensure_objects(cobj) is not None: store_reference(obj, key, cobj._objects) arg = cobj._get_buffer_value() if fieldtype._fficompositesize is not None: from ctypes import memmove dest = obj._buffer.fieldaddress(self.name) memmove(dest, arg, fieldtype._fficompositesize) else: obj._buffer.__setattr__(self.name, arg)
def __setattr__(self, name, value): try: fieldtype = self._fieldtypes[name].ctype except KeyError: raise AttributeError(name) if ensure_objects(value) is not None: key = keepalive_key(getattr(self.__class__, name).num) store_reference(self, key, value._objects) arg = fieldtype._CData_value(value) if fieldtype._fficompositesize is not None: from ctypes import memmove dest = self._buffer.buffer memmove(dest, arg, fieldtype._fficompositesize) else: buf = self._ffiarrays[name].fromaddress(self._buffer.buffer, 1) buf[0] = arg
def __setattr__(self, name, value): try: field = self._fieldtypes[name] except KeyError: return _CData.__setattr__(self, name, value) fieldtype = field.ctype cobj = fieldtype.from_param(value) if ensure_objects(cobj) is not None: key = keepalive_key(field.num) store_reference(self, key, cobj._objects) arg = cobj._get_buffer_value() if fieldtype._fficompositesize is not None: from ctypes import memmove dest = self._buffer.fieldaddress(name) memmove(dest, arg, fieldtype._fficompositesize) else: self._buffer.__setattr__(name, arg)
def __setattr__(self, name, value): try: field = self._fieldtypes[name] except KeyError: raise AttributeError(name) fieldtype = field.ctype cobj = fieldtype.from_param(value) if ensure_objects(cobj) is not None: key = keepalive_key(field.num) store_reference(self, key, cobj._objects) arg = cobj._get_buffer_value() if fieldtype._fficompositesize is not None: from ctypes import memmove dest = self._buffer.buffer memmove(dest, arg, fieldtype._fficompositesize) else: buf = self._ffiarrays[name].fromaddress(self._buffer.buffer, 1) buf[0] = arg
def __set__(self, obj, value): if self.inside_anon_field is not None: setattr(self.inside_anon_field.__get__(obj), self.name, value) return fieldtype = self.ctype cobj = fieldtype.from_param(value) key = keepalive_key(self.num) if issubclass(fieldtype, _Pointer) and isinstance(cobj, Array): # if our value is an Array we need the whole thing alive store_reference(obj, key, cobj) elif ensure_objects(cobj) is not None: store_reference(obj, key, cobj._objects) arg = cobj._get_buffer_value() if fieldtype._fficompositesize_ is not None: from ctypes import memmove dest = obj._buffer.fieldaddress(self.name) memmove(dest, arg, fieldtype._fficompositesize_) elif not isinstance(obj, _CData): raise (TypeError, 'not a ctype instance') else: obj._buffer.__setattr__(self.name, arg)
def __init__(self, *args): self.name = None self._objects = {keepalive_key(0):self} self._needs_free = True # Empty function object -- this is needed for casts if not args: self._set_address(0) return argsl = list(args) argument = argsl.pop(0) # Direct construction from raw address if isinstance(argument, (int, long)) and not argsl: self._set_address(argument) restype = self._restype_ if restype is None: import ctypes restype = ctypes.c_int if self._argtypes_ is None: self._argtypes_ = [] self._ptr = self._getfuncptr_fromaddress(self._argtypes_, restype) self._check_argtypes_for_fastpath() return # A callback into python if callable(argument) and not argsl: self.callable = argument ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) if self._restype_ is None: ffires = None self._ptr = _rawffi.CallbackPtr(self._wrap_callable(argument, self.argtypes), ffiargs, ffires, self._flags_) self._buffer = self._ptr.byptr() return # Function exported from a shared library if isinstance(argument, tuple) and len(argument) == 2: import ctypes self.name, dll = argument if isinstance(dll, str): self.dll = ctypes.CDLL(self.dll) else: self.dll = dll if argsl: self.paramflags = argsl.pop(0) if argsl: raise TypeError("Unknown constructor %s" % (args,)) # We need to check dll anyway ptr = self._getfuncptr([], ctypes.c_int) self._set_address(ptr.getaddr()) return # A COM function call, by index if (sys.platform == 'win32' and isinstance(argument, (int, long)) and argsl): ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._com_index = argument + 0x1000 self.name = argsl.pop(0) if argsl: self.paramflags = argsl.pop(0) if argsl: self._com_iid = argsl.pop(0) if argsl: raise TypeError("Unknown constructor %s" % (args,)) return raise TypeError("Unknown constructor %s" % (args,))
def __init__(self, *args): self.name = None self._objects = {keepalive_key(0): self} self._needs_free = True # Empty function object -- this is needed for casts if not args: self._set_address(0) return argsl = list(args) argument = argsl.pop(0) # Direct construction from raw address if isinstance(argument, int) and not argsl: self._set_address(argument) restype = self._restype_ if restype is None: import ctypes restype = ctypes.c_int if self._argtypes_ is None: self._argtypes_ = [] self._ptr = self._getfuncptr_fromaddress(self._argtypes_, restype) return # A callback into python if callable(argument) and not argsl: self.callable = argument ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) if self._restype_ is None: ffires = None self._ptr = _rawffi.CallbackPtr( self._wrap_callable(argument, self.argtypes), ffiargs, ffires, self._flags_) self._buffer = self._ptr.byptr() return # Function exported from a shared library if isinstance(argument, tuple) and len(argument) == 2: import ctypes self.name, dll = argument if isinstance(dll, str): self.dll = ctypes.CDLL(self.dll) else: self.dll = dll if argsl: self.paramflags = argsl.pop(0) if argsl: raise TypeError("Unknown constructor %s" % (args, )) # We need to check dll anyway ptr = self._getfuncptr([], ctypes.c_int) self._set_address(ptr.getaddr()) return # A COM function call, by index if (sys.platform == 'win32' and isinstance(argument, int) and argsl): ffiargs, ffires = self._ffishapes(self._argtypes_, self._restype_) self._com_index = argument + 0x1000 self.name = argsl.pop(0) if argsl: self.paramflags = argsl.pop(0) if argsl: self._com_iid = argsl.pop(0) if argsl: raise TypeError("Unknown constructor %s" % (args, )) return raise TypeError("Unknown constructor %s" % (args, ))