def _new_array_type(space, w_ctptr, length): _setup_wref(rweakref.has_weakref_support()) if not isinstance(w_ctptr, ctypeptr.W_CTypePointer): raise oefmt(space.w_TypeError, "first arg must be a pointer ctype") arrays = w_ctptr._array_types if arrays is None: arrays = rweakref.RWeakValueDictionary(int, ctypearray.W_CTypeArray) w_ctptr._array_types = arrays else: ctype = arrays.get(length) if ctype is not None: return ctype # ctitem = w_ctptr.ctitem if ctitem.size < 0: raise oefmt(space.w_ValueError, "array item of unknown size: '%s'", ctitem.name) if length < 0: assert length == -1 arraysize = -1 extra = '[]' else: try: arraysize = ovfcheck(length * ctitem.size) except OverflowError: raise oefmt(space.w_OverflowError, "array size would overflow a ssize_t") extra = '[%d]' % length # ctype = ctypearray.W_CTypeArray(space, w_ctptr, length, arraysize, extra) arrays.set(length, ctype) return ctype
def _build_function_type(space, fargs, fresult, ellipsis, abi): from pypy.module._cffi_backend import ctypefunc # if ((fresult.size < 0 and not isinstance(fresult, ctypevoid.W_CTypeVoid)) or isinstance(fresult, ctypearray.W_CTypeArray)): if (isinstance(fresult, ctypestruct.W_CTypeStructOrUnion) and fresult.size < 0): raise oefmt(space.w_TypeError, "result type '%s' is opaque", fresult.name) else: raise oefmt(space.w_TypeError, "invalid result type: '%s'", fresult.name) # fct = ctypefunc.W_CTypeFunc(space, fargs, fresult, ellipsis, abi) unique_cache = space.fromcache(UniqueCache) func_hash = _func_key_hash(unique_cache, fargs, fresult, ellipsis, abi) for weakdict in unique_cache.functions: if weakdict.get(func_hash) is None: weakdict.set(func_hash, fct) break else: weakdict = rweakref.RWeakValueDictionary(int, ctypefunc.W_CTypeFunc) unique_cache.functions.append(weakdict) weakdict.set(func_hash, fct) return fct
def _record_function_type(unique_cache, fct): from pypy.module._cffi_backend import ctypefunc # func_hash = _func_key_hash(unique_cache, fct.fargs, fct.ctitem, fct.ellipsis, fct.abi) for weakdict in unique_cache.functions: if weakdict.get(func_hash) is None: break else: weakdict = rweakref.RWeakValueDictionary(int, ctypefunc.W_CTypeFunc) unique_cache.functions.append(weakdict) weakdict.set(func_hash, fct)
def __init__(self): self.callback_id = 0 self.callbacks = rweakref.RWeakValueDictionary(int, W_CallbackPtr)
def __init__(self): self.next_id = 1 self.callbacks = rweakref.RWeakValueDictionary(int, Callback)
def print_error(self, operr, extra_line): space = self.space operr.write_unraisable(space, "cffi callback ", self.w_callable, with_traceback=True, extra_line=extra_line) def write_error_return_value(self, ll_res): fresult = self.getfunctype().ctitem if fresult.size > 0: misc._raw_memcopy(self.ll_error, ll_res, fresult.size) keepalive_until_here(self) # to keep self.ll_error alive global_callback_mapping = rweakref.RWeakValueDictionary(int, W_CDataCallback) def convert_from_object_fficallback(fresult, ll_res, w_res): space = fresult.space small_result = fresult.size < SIZE_OF_FFI_ARG if small_result and isinstance(fresult, W_CTypeVoid): if not space.is_w(w_res, space.w_None): raise OperationError( space.w_TypeError, space.wrap("callback with the return type 'void'" " must return None")) return # if small_result and fresult.is_primitive_integer: # work work work around a libffi irregularity: for integer return
def __init__(self, parent): self.indexes = {} self.static_data = {} self.dynamic_submaps = rweakref.RWeakValueDictionary(keyclass, CachingMap) self.static_submaps = {} self.parent = parent
def __init__(self, parent): self.indexes = {} self.other_maps = rweakref.RWeakValueDictionary(keyclass, Map) # NB: The parent pointer is needed to prevent the GC from collecting # the chain of parent maps which produced this one. self.parent = parent