Ejemplo n.º 1
0
 def ptr(self, space, name, w_argtypes, w_restype):
     """ Get a pointer for function name with provided argtypes
     and restype
     """
     # xxx refactor
     if space.is_w(w_restype, space.w_None):
         resshape = None
         ffi_restype = ffi_type_void
     elif space.is_true(space.isinstance(w_restype, space.w_str)):
         tp_letter = space.str_w(w_restype)
         if tp_letter == 'v':
             resshape = None
             ffi_restype = ffi_type_void
         else:
             from pypy.module._rawffi.array import get_array_cache
             cache = get_array_cache(space)
             resshape = cache.get_array_type(letter2tp(space, tp_letter))
             ffi_restype = self.get_type(tp_letter)
     else:
         from pypy.module._rawffi.structure import W_Structure
         resshape = space.interp_w(W_Structure, w_restype)
         ffi_restype = resshape.get_ffi_type()
             
     w = space.wrap
     w_argtypes = space.newtuple(space.unpackiterable(w_argtypes))
     w_key = space.newtuple([w(name), w_argtypes, w(resshape)])
     try:
         return space.getitem(self.w_cache, w_key)
     except OperationError, e:
         if e.match(space, space.w_KeyError):
             pass
         else:
             raise
Ejemplo n.º 2
0
 def byptr(self, space):
     from pypy.module._rawffi.array import get_array_cache
     array_of_ptr = get_array_cache(space).array_of_ptr
     array = array_of_ptr.allocate(space, 1)
     array.setitem(space, 0, self._getbuffer(space))
     if tracker.DO_TRACING:
         # XXX this is needed, because functions tend to live forever
         #     hence our testing is not performing that well
         del tracker.alloced[rffi.cast(lltype.Signed, array.ll_buffer)]
     return space.wrap(array)
Ejemplo n.º 3
0
 def byptr(self, space):
     from pypy.module._rawffi.array import get_array_cache
     array_of_ptr = get_array_cache(space).array_of_ptr
     array = array_of_ptr.allocate(space, 1)
     array.setitem(space, 0, self._getbuffer(space))
     if tracker.DO_TRACING:
         # XXX this is needed, because functions tend to live forever
         #     hence our testing is not performing that well
         del tracker.alloced[rffi.cast(lltype.Signed, array.ll_buffer)]
     return space.wrap(array)
Ejemplo n.º 4
0
 def getprimitive(self, space, letter, name):
     from pypy.module._rawffi.array import get_array_cache
     cache = get_array_cache(space)
     w_array = cache.get_array_type(letter2tp(space, letter))
     try:
         address_as_uint = rffi.cast(lltype.Unsigned,
                                     self.cdll.getaddressindll(name))
     except KeyError:
         raise OperationError(space.w_ValueError,
                              space.wrap("Cannot find symbol %s" % (name,)))
     return w_array.fromaddress(space, address_as_uint, 1)
Ejemplo n.º 5
0
def unpack_to_ffi_type(space, w_shape, shape=False):
    resshape = None
    if space.is_true(space.isinstance(w_shape, space.w_str)):
        letter = space.str_w(w_shape)
        ffi_type = _get_type_(space, letter)
        if shape:
            from pypy.module._rawffi.array import get_array_cache
            cache = get_array_cache(space)
            resshape = cache.get_array_type(letter2tp(space, letter))
    else:
        letter = 'V'
        w_shapetype, w_length = space.fixedview(w_shape, expected_length=2)
        from pypy.module._rawffi.structure import W_Structure
        resshape = space.interp_w(W_Structure, w_shapetype)
        ffi_type = resshape.get_ffi_type()
    return letter, ffi_type, resshape
Ejemplo n.º 6
0
def unpack_to_ffi_type(space, w_shape, shape=False):
    resshape = None
    if space.is_true(space.isinstance(w_shape, space.w_str)):
        letter = space.str_w(w_shape)
        ffi_type = _get_type_(space, letter)
        if shape:
            from pypy.module._rawffi.array import get_array_cache
            cache = get_array_cache(space)
            resshape = cache.get_array_type(letter2tp(space, letter))
    else:
        letter = 'V'
        w_shapetype, w_length = space.fixedview(w_shape, expected_length=2)
        from pypy.module._rawffi.structure import W_Structure
        resshape = space.interp_w(W_Structure, w_shapetype)
        ffi_type = resshape.get_ffi_type()
    return letter, ffi_type, resshape
Ejemplo n.º 7
0
 def byptr(self, space):
     from pypy.module._rawffi.array import get_array_cache
     array_of_ptr = get_array_cache(space).array_of_ptr
     array = array_of_ptr.allocate(space, 1)
     array.setitem(space, 0, space.wrap(self))
     return space.wrap(array)
Ejemplo n.º 8
0
 def byptr(self, space):
     from pypy.module._rawffi.array import get_array_cache
     array_of_ptr = get_array_cache(space).array_of_ptr
     array = array_of_ptr.allocate(space, 1)
     array.setitem(space, 0, space.wrap(self))
     return space.wrap(array)