Esempio n. 1
0
    def __init__(self, cfunc, callback):
        self.cfunc = cfunc
        self.callback = callback
        pointer = rffi.cast(rffi.VOIDP, clibffi.closureHeap.alloc())
        if cfunc.notready:
            cfunc.prepare_cif()
            cfunc.notready = False
        Mem.__init__(self, cfunc, pointer)

        closure_ptr = rffi.cast(clibffi.FFI_CLOSUREP, self.pointer)
        # hide the object
        gcref = rgc.cast_instance_to_gcref(self)
        raw = rgc.hide_nonmovable_gcref(gcref)
        unique_id = rffi.cast(rffi.VOIDP, raw)

        res = clibffi.c_ffi_prep_closure(closure_ptr, cfunc.cif.cif,
            invoke_callback, unique_id)

        if rffi.cast(lltype.Signed, res) != clibffi.FFI_OK:
            raise unwind(LError(u"libffi failed to build this callback"))
        if closure_ptr.c_user_data != unique_id:
            raise unwind(LError(u"ffi_prep_closure(): bad user_data"))

        # The function might be called in separate thread,
        # so allocate GIL here, just in case.
        rgil.allocate()
Esempio n. 2
0
def _newp_handle(space, w_ctype, w_x):
    # Allocate a handle as a nonmovable W_CDataHandle instance, which
    # we can cast to a plain CCHARP.  As long as the object is not freed,
    # we can cast the CCHARP back to a W_CDataHandle with reveal_gcref().
    new_cdataobj = objectmodel.instantiate(cdataobj.W_CDataHandle,
                                           nonmovable=True)
    gcref = rgc.cast_instance_to_gcref(new_cdataobj)
    _cdata = rgc.hide_nonmovable_gcref(gcref)
    _cdata = rffi.cast(rffi.CCHARP, _cdata)
    cdataobj.W_CDataHandle.__init__(new_cdataobj, space, _cdata, w_ctype, w_x)
    return new_cdataobj
Esempio n. 3
0
def _newp_handle(space, w_ctype, w_x):
    # Allocate a handle as a nonmovable W_CDataHandle instance, which
    # we can cast to a plain CCHARP.  As long as the object is not freed,
    # we can cast the CCHARP back to a W_CDataHandle with reveal_gcref().
    new_cdataobj = objectmodel.instantiate(cdataobj.W_CDataHandle,
                                           nonmovable=True)
    gcref = rgc.cast_instance_to_gcref(new_cdataobj)
    _cdata = rgc.hide_nonmovable_gcref(gcref)
    _cdata = rffi.cast(rffi.CCHARP, _cdata)
    cdataobj.W_CDataHandle.__init__(new_cdataobj, space, _cdata, w_ctype, w_x)
    return new_cdataobj
Esempio n. 4
0
 def hide_object(self):
     gcref = rgc.cast_instance_to_gcref(self)
     raw = rgc.hide_nonmovable_gcref(gcref)
     return rffi.cast(rffi.VOIDP, raw)
Esempio n. 5
0
 def hide_object(self):
     gcref = rgc.cast_instance_to_gcref(self)
     raw = rgc.hide_nonmovable_gcref(gcref)
     return rffi.cast(rffi.VOIDP, raw)
Esempio n. 6
0
 def hide_object(PTR, obj):
     gcref = rgc.cast_instance_to_gcref(obj)
     raw = rgc.hide_nonmovable_gcref(gcref)
     return rffi.cast(PTR, raw)