예제 #1
0
def HPyNumber_Check(space, ctx, h):
    # XXX: write proper tests
    w_obj = handles.deref(space, h)
    if (space.lookup(w_obj, '__int__') or space.lookup(w_obj, '__float__')
            or 0):  # XXX in py3.8: space.lookup(w_obj, '__index__')):
        return API.int(1)
    return API.int(0)
예제 #2
0
def HPy_RichCompareBool(space, ctx, v, w, op):
    w_o1 = handles.deref(space, v)
    w_o2 = handles.deref(space, w)
    # Quick result when objects are the same.
    # Guarantees that identity implies equality.
    if space.is_w(w_o1, w_o2):
        opid = rffi.cast(lltype.Signed, op)
        if opid == llapi.HPy_EQ:
            return API.int(1)
        if opid == llapi.HPy_NE:
            return API.int(0)
    w_result = rich_compare(space, w_o1, w_o2, op)
    return API.int(space.is_true(w_result))
예제 #3
0
def HPyList_Append(space, ctx, h_list, h_item):
    w_list = handles.deref(space, h_list)
    # XXX the tests should check what happens in this case
    assert isinstance(w_list, W_ListObject)
    w_item = handles.deref(space, h_item)
    w_list.append(w_item)
    return API.int(0)
예제 #4
0
def hpy_err_Occurred_rpy(space):
    if we_are_translated():
        # this function should never been called after translation. We can't
        # simply put an assert else the annotator complains that the function
        # returns Void, hack hack hack
        if NonConstant(False):
            return API.int(-42)
        assert False
    #
    # this is a bit of a hack: it will never aim to be correct in 100% of
    # cases, but since it's used only for tests, it's enough.  If an
    # exception was raised by an HPy call, it must be stored in
    # ll2ctypes._callback_exc_info, waiting to be properly re-raised as
    # soon as we exit the C code, by
    # ll2ctypes:get_ctypes_trampoline:invoke_via_ctypes
    res = ll2ctypes._callback_exc_info is not None
    return API.int(res)
예제 #5
0
def HPy_SetItem(space, ctx, h_obj, h_key, h_val):
    w_obj = handles.deref(space, h_obj)
    w_key = handles.deref(space, h_key)
    w_val = handles.deref(space, h_val)
    space.setitem(w_obj, w_key, w_val)
    return API.int(0)
예제 #6
0
def HPy_GetItem_s(space, ctx, h_obj, key):
    w_obj = handles.deref(space, h_obj)
    w_key = API.ccharp2text(space, key)
    w_res = space.getitem(w_obj, w_key)
    return handles.new(space, w_res)
예제 #7
0
def HPy_SetAttr_s(space, ctx, h_obj, name, h_value):
    w_obj = handles.deref(space, h_obj)
    w_name = API.ccharp2text(space, name)
    w_value = handles.deref(space, h_value)
    operation.setattr(space, w_obj, w_name, w_value)
    return API.int(0)
예제 #8
0
def _HasAttr(space, w_obj, w_name):
    try:
        w_res = operation.hasattr(space, w_obj, w_name)
        return API.int(space.is_true(w_res))
    except OperationError:
        return API.int(0)
예제 #9
0
def HPy_HasAttr_s(space, ctx, h_obj, name):
    w_obj = handles.deref(space, h_obj)
    w_name = API.ccharp2text(space, name)
    return _HasAttr(space, w_obj, w_name)
예제 #10
0
def HPy_GetAttr_s(space, ctx, h_obj, name):
    w_obj = handles.deref(space, h_obj)
    w_name = API.ccharp2text(space, name)
    w_res = space.getattr(w_obj, w_name)
    return handles.new(space, w_res)
예제 #11
0
def HPy_SetItem_s(space, ctx, h_obj, key, h_val):
    w_obj = handles.deref(space, h_obj)
    w_key = API.ccharp2text(space, key)
    w_val = handles.deref(space, h_val)
    space.setitem(w_obj, w_key, w_val)
    return API.int(0)
예제 #12
0
def HPy_SetItem_i(space, ctx, h_obj, idx, h_val):
    w_obj = handles.deref(space, h_obj)
    w_key = space.newint(idx)
    w_val = handles.deref(space, h_val)
    space.setitem(w_obj, w_key, w_val)
    return API.int(0)
예제 #13
0
def HPy_IsTrue(space, ctx, h_obj):
    w_obj = handles.deref(space, h_obj)
    return API.int(space.is_true(w_obj))
예제 #14
0
def HPyTracker_Add(space, ctx, ht, h):
    w_tracker = handles.deref(space, ht)
    assert isinstance(w_tracker, W_Tracker)
    w_tracker.add(h)
    return API.int(0)
예제 #15
0
def HPyUnicode_Check(space, ctx, h):
    w_obj = handles.deref(space, h)
    w_obj_type = space.type(w_obj)
    res = (space.is_w(w_obj_type, space.w_unicode)
           or space.issubtype_w(w_obj_type, space.w_unicode))
    return API.int(res)
예제 #16
0
def HPyBytes_Check(space, ctx, h):
    w_obj = handles.deref(space, h)
    w_obj_type = space.type(w_obj)
    res = (space.is_w(w_obj_type, space.w_bytes) or
           space.issubtype_w(w_obj_type, space.w_bytes))
    return API.int(res)