def callback(ll_args, ll_res, ll_userdata): userdata = rffi.cast(USERDATA_P, ll_userdata) callback_ptr = global_counter.get(userdata.addarg) w_callable = callback_ptr.w_callable argtypes = callback_ptr.argtypes must_leave = False space = callback_ptr.space try: must_leave = space.threadlocals.try_enter_thread(space) args_w = [None] * len(argtypes) for i in range(len(argtypes)): argtype = argtypes[i] if isinstance(argtype, W_Structure): args_w[i] = argtype.fromaddress( space, rffi.cast(rffi.SIZE_T, ll_args[i])) else: # XXX other types? args_w[i] = space.wrap(rffi.cast(rffi.ULONG, ll_args[i])) w_res = space.call(w_callable, space.newtuple(args_w)) if callback_ptr.result is not None: # don't return void unwrap_value(space, write_ptr, ll_res, 0, callback_ptr.result, w_res) except OperationError, e: tbprint(space, space.wrap(e.get_traceback()), space.wrap(e.errorstr(space))) # force the result to be zero if callback_ptr.result is not None: resshape = letter2tp(space, callback_ptr.result) for i in range(resshape.size): ll_res[i] = '\x00'
def setitem(self, space, num, w_value): if not self.ll_buffer: raise segfault_exception(space, "setting element of freed array") if num >= self.length or num < 0: raise OperationError(space.w_IndexError, space.w_None) unwrap_value(space, write_ptr, self.ll_buffer, num, self.shape.itemcode, w_value)
def callback(ll_args, ll_res, ll_userdata): userdata = rffi.cast(USERDATA_P, ll_userdata) callback_ptr = global_counter.get(userdata.addarg) w_callable = callback_ptr.w_callable argtypes = callback_ptr.argtypes space = callback_ptr.space try: args_w = [None] * len(argtypes) for i in range(len(argtypes)): argtype = argtypes[i] if isinstance(argtype, W_Structure): args_w[i] = argtype.fromaddress( space, rffi.cast(rffi.SIZE_T, ll_args[i])) else: # XXX other types? args_w[i] = space.wrap(rffi.cast(rffi.ULONG, ll_args[i])) w_res = space.call(w_callable, space.newtuple(args_w)) if callback_ptr.result is not None: # don't return void unwrap_value(space, write_ptr, ll_res, 0, callback_ptr.result, w_res) except OperationError, e: tbprint(space, space.wrap(e.get_traceback()), space.wrap(e.errorstr(space))) # force the result to be zero if callback_ptr.result is not None: resshape = letter2tp(space, callback_ptr.result) for i in range(resshape.size): ll_res[i] = '\x00'
def descr_call(self, space, length, w_items=None, autofree=False): result = self.allocate(space, length, autofree) if not space.is_none(w_items): items_w = space.unpackiterable(w_items) iterlength = len(items_w) if iterlength > length: raise oefmt(space.w_ValueError, "too many items for specified array length") for num in range(iterlength): w_item = items_w[num] unwrap_value(space, write_ptr, result.ll_buffer, num, self.itemcode, w_item) return space.wrap(result)
def descr_call(self, space, length, w_items=None, autofree=False): result = self.allocate(space, length, autofree) if not space.is_none(w_items): items_w = space.unpackiterable(w_items) iterlength = len(items_w) if iterlength > length: raise oefmt(space.w_ValueError, "too many items for specified array length") for num in range(iterlength): w_item = items_w[num] unwrap_value(space, write_ptr, result.ll_buffer, num, self.itemcode, w_item) return result
def callback(ll_args, ll_res, ll_userdata): userdata = rffi.cast(USERDATA_P, ll_userdata) callback_ptr = global_counter.CallbackPtr_by_number[userdata.addarg] w_callable = callback_ptr.w_callable res = rffi.cast(rffi.VOIDPP, ll_res) argtypes = callback_ptr.args space = callback_ptr.space w_args = space.newlist([wrap_value(space, get_elem, ll_args[i], 0, letter2tp(space, argtypes[i])) for i in range(len(argtypes))]) w_res = space.call(w_callable, w_args) unwrap_value(space, push_elem, ll_res, 0, letter2tp(space, callback_ptr.result), w_res)
def descr_call(self, space, length, w_items=None, autofree=False): result = self.allocate(space, length, autofree) if not space.is_w(w_items, space.w_None): items_w = space.unpackiterable(w_items) iterlength = len(items_w) if iterlength > length: raise OperationError(space.w_ValueError, space.wrap("too many items for specified" " array length")) for num in range(iterlength): w_item = items_w[num] unwrap_value(space, push_elem, result.ll_buffer, num, self.itemcode, w_item) return space.wrap(result)
def descr_call(self, space, length, w_items=None, autofree=False): result = self.allocate(space, length, autofree) if not space.is_w(w_items, space.w_None): items_w = space.unpackiterable(w_items) iterlength = len(items_w) if iterlength > length: raise OperationError( space.w_ValueError, space.wrap("too many items for specified" " array length")) for num in range(iterlength): w_item = items_w[num] unwrap_value(space, push_elem, result.ll_buffer, num, self.itemcode, w_item) return space.wrap(result)
def callback(ll_args, ll_res, ll_userdata): userdata = rffi.cast(USERDATA_P, ll_userdata) callback_ptr = global_counter.CallbackPtr_by_number[userdata.addarg] w_callable = callback_ptr.w_callable res = rffi.cast(rffi.VOIDPP, ll_res) argtypes = callback_ptr.args space = callback_ptr.space try: w_args = space.newlist([space.wrap(rffi.cast(rffi.ULONG, ll_args[i])) for i in range(len(argtypes))]) w_res = space.call(w_callable, w_args) if callback_ptr.result != 'O': # don't return void unwrap_value(space, push_elem, ll_res, 0, letter2tp(space, callback_ptr.result), w_res) except OperationError, e: tbprint(space, space.wrap(e.application_traceback), space.wrap(e.errorstr(space)))
def callback(ll_args, ll_res, ll_userdata): userdata = rffi.cast(USERDATA_P, ll_userdata) callback_ptr = global_counter.get(userdata.addarg) w_callable = callback_ptr.w_callable argtypes = callback_ptr.argtypes must_leave = False space = callback_ptr.space try: must_leave = space.threadlocals.try_enter_thread(space) args_w = [None] * len(argtypes) for i in range(len(argtypes)): argtype = argtypes[i] if isinstance(argtype, W_Structure): args_w[i] = argtype.fromaddress( space, rffi.cast(rffi.SIZE_T, ll_args[i])) else: # XXX other types? args_w[i] = space.newint(rffi.cast(lltype.Unsigned, ll_args[i])) w_res = space.call(w_callable, space.newtuple(args_w)) if callback_ptr.result is not None: # don't return void ptr = ll_res letter = callback_ptr.result if BIGENDIAN: # take care of narrow integers! for int_type in unroll_narrow_integer_types: if int_type == letter: T = LL_TYPEMAP[int_type] n = rffi.sizeof(lltype.Signed) - rffi.sizeof(T) ptr = rffi.ptradd(ptr, n) break unwrap_value(space, write_ptr, ptr, 0, letter, w_res) except OperationError as e: tbprint(space, e.get_w_traceback(space), space.newtext(e.errorstr(space))) # force the result to be zero if callback_ptr.result is not None: resshape = letter2tp(space, callback_ptr.result) for i in range(resshape.size): ll_res[i] = '\x00' if must_leave: space.threadlocals.leave_thread(space)
def callback(ll_args, ll_res, ll_userdata): userdata = rffi.cast(USERDATA_P, ll_userdata) callback_ptr = global_counter.get(userdata.addarg) w_callable = callback_ptr.w_callable argtypes = callback_ptr.argtypes must_leave = False space = callback_ptr.space try: must_leave = space.threadlocals.try_enter_thread(space) args_w = [None] * len(argtypes) for i in range(len(argtypes)): argtype = argtypes[i] if isinstance(argtype, W_Structure): args_w[i] = argtype.fromaddress( space, rffi.cast(rffi.SIZE_T, ll_args[i])) else: # XXX other types? args_w[i] = space.wrap(rffi.cast(rffi.ULONG, ll_args[i])) w_res = space.call(w_callable, space.newtuple(args_w)) if callback_ptr.result is not None: # don't return void ptr = ll_res letter = callback_ptr.result if BIGENDIAN: # take care of narrow integers! for int_type in unroll_narrow_integer_types: if int_type == letter: T = LL_TYPEMAP[int_type] n = rffi.sizeof(lltype.Signed) - rffi.sizeof(T) ptr = rffi.ptradd(ptr, n) break unwrap_value(space, write_ptr, ptr, 0, letter, w_res) except OperationError as e: tbprint(space, space.wrap(e.get_traceback()), space.wrap(e.errorstr(space))) # force the result to be zero if callback_ptr.result is not None: resshape = letter2tp(space, callback_ptr.result) for i in range(resshape.size): ll_res[i] = '\x00' if must_leave: space.threadlocals.leave_thread(space)
def callback(ll_args, ll_res, ll_userdata): userdata = rffi.cast(USERDATA_P, ll_userdata) callback_ptr = global_counter.CallbackPtr_by_number[userdata.addarg] w_callable = callback_ptr.w_callable argtypes = callback_ptr.args space = callback_ptr.space try: w_args = space.newlist([space.wrap(rffi.cast(rffi.ULONG, ll_args[i])) for i in range(len(argtypes))]) w_res = space.call(w_callable, w_args) if callback_ptr.result != 'O': # don't return void unwrap_value(space, push_elem, ll_res, 0, callback_ptr.result, w_res) except OperationError, e: tbprint(space, space.wrap(e.application_traceback), space.wrap(e.errorstr(space))) # force the result to be zero if callback_ptr.result != 'O': _, size, _ = letter2tp(space, callback_ptr.result) for i in range(size): ll_res[i] = '\x00'
def setattr(self, space, attr, w_value): if not self.ll_buffer: raise segfault_exception(space, "accessing NULL pointer") i = self.shape.getindex(space, attr) _, tp, _ = self.shape.fields[i] unwrap_value(space, push_field, self, i, tp.itemcode, w_value)