def buff_w(space, w_self, view, flags): w_obj = w_self if view: #like PyObject_GetBuffer flags = widen(flags) buf = space.buffer_w(w_obj, flags) try: view.c_buf = rffi.cast(rffi.VOIDP, buf.get_raw_address()) view.c_obj = make_ref(space, w_obj) except ValueError: s = buf.as_str() w_s = space.newbytes(s) view.c_obj = make_ref(space, w_s) view.c_buf = rffi.cast( rffi.VOIDP, rffi.str2charp(s, track_allocation=False)) rffi.setintfield(view, 'c_readonly', 1) ret = fill_Py_buffer(space, buf, view) return ret return 0
def buff_w(space, w_self, view, flags): args = Arguments(space, [space.newint(flags)]) w_obj = space.call_args(space.get(buff_fn, w_self), args) if view: #like PyObject_GetBuffer flags = widen(flags) buf = space.buffer_w(w_obj, flags) try: view.c_buf = rffi.cast(rffi.VOIDP, buf.get_raw_address()) view.c_obj = make_ref(space, w_obj) except ValueError: w_s = space.newbytes(buf.as_str()) view.c_obj = make_ref(space, w_s) view.c_buf = rffi.cast(rffi.VOIDP, rffi.str2charp( space.str_w(w_s), track_allocation=False)) rffi.setintfield(view, 'c_readonly', 1) ret = fill_Py_buffer(space, buf, view) return ret return 0
def buff_w(space, w_self, c_view, flags): args = Arguments(space, [space.newint(flags)]) w_obj = space.call_args(space.get(buff_fn, w_self), args) if c_view: #like PyObject_GetBuffer flags = widen(flags) buf = space.buffer_w(w_obj, flags) try: c_view.c_buf = rffi.cast(rffi.VOIDP, buf.get_raw_address()) c_view.c_obj = make_ref(space, w_obj) except ValueError: s = buf.as_str() w_s = space.newbytes(s) c_view.c_obj = make_ref(space, w_s) c_view.c_buf = rffi.cast( rffi.VOIDP, rffi.str2charp(s, track_allocation=False)) rffi.setintfield(c_view, 'c_readonly', 1) ret = fill_Py_buffer(space, buf, c_view) return ret return 0