Пример #1
0
 def parse_string_to_type(self, string, consider_fn_as_fnptr):
     # This cannot be made @elidable because it calls general space
     # functions (indirectly, e.g. via the new_xxx_type() functions).
     # The get_string_to_type() function above is elidable, and we
     # hope that in almost all cases, get_string_to_type() has already
     # found an answer.
     try:
         x = self.types_dict[string]
     except KeyError:
         info = self.ctxobj.info
         index = parse_c_type.parse_c_type(info, string)
         if index < 0:
             raise self._ffi_bad_type(string)
         x = realize_c_type.realize_c_type_or_func(
             self, self.ctxobj.info.c_output, index)
         assert x is not None
         if isinstance(x, realize_c_type.W_RawFuncType):
             x.unwrap_as_fnptr(self)      # force it here
         self.types_dict[string] = x
     #
     if isinstance(x, W_CType):
         return x
     else:
         assert isinstance(x, realize_c_type.W_RawFuncType)
         if consider_fn_as_fnptr:
             return x.unwrap_as_fnptr_in_elidable()
         else:
             raise x.unexpected_fn_type(self)
Пример #2
0
def parse(input):
    OUTPUT_SIZE = 100
    out = lltype.malloc(rffi.VOIDPP.TO, OUTPUT_SIZE, flavor='raw',
                        track_allocation=False)
    info = lltype.malloc(parse_c_type.PINFO.TO, flavor='raw', zero=True,
                        track_allocation=False)
    info.c_ctx = ctx
    info.c_output = out
    rffi.setintfield(info, 'c_output_size', OUTPUT_SIZE)
    for j in range(OUTPUT_SIZE):
        out[j] = rffi.cast(rffi.VOIDP, -424242)
    res = parse_c_type.parse_c_type(info, input.encode('ascii'))
    if res < 0:
        raise ParseError(rffi.charp2str(info.c_error_message).decode('ascii'),
                         rffi.getintfield(info, 'c_error_location'))
    assert 0 <= res < OUTPUT_SIZE
    result = []
    for j in range(OUTPUT_SIZE):
        if out[j] == rffi.cast(rffi.VOIDP, -424242):
            assert res < j
            break
        i = rffi.cast(rffi.SIGNED, out[j])
        if j == res:
            result.append('->')
        result.append(i)
    return result
Пример #3
0
def parse(input):
    OUTPUT_SIZE = 100
    out = lltype.malloc(rffi.VOIDPP.TO,
                        OUTPUT_SIZE,
                        flavor='raw',
                        track_allocation=False)
    info = lltype.malloc(parse_c_type.PINFO.TO,
                         flavor='raw',
                         zero=True,
                         track_allocation=False)
    info.c_ctx = ctx
    info.c_output = out
    rffi.setintfield(info, 'c_output_size', OUTPUT_SIZE)
    for j in range(OUTPUT_SIZE):
        out[j] = rffi.cast(rffi.VOIDP, -424242)
    res = parse_c_type.parse_c_type(info, input.encode('ascii'))
    if res < 0:
        raise ParseError(
            rffi.charp2str(info.c_error_message).decode('ascii'),
            rffi.getintfield(info, 'c_error_location'))
    assert 0 <= res < OUTPUT_SIZE
    result = []
    for j in range(OUTPUT_SIZE):
        if out[j] == rffi.cast(rffi.VOIDP, -424242):
            assert res < j
            break
        i = rffi.cast(rffi.SIGNED, out[j])
        if j == res:
            result.append('->')
        result.append(i)
    return result
Пример #4
0
 def parse_string_to_type(self, string, consider_fn_as_fnptr):
     # This cannot be made @elidable because it calls general space
     # functions (indirectly, e.g. via the new_xxx_type() functions).
     # The get_string_to_type() function above is elidable, and we
     # hope that in almost all cases, get_string_to_type() has already
     # found an answer.
     try:
         x = self.types_dict[string]
     except KeyError:
         info = self.ctxobj.info
         index = parse_c_type.parse_c_type(info, string)
         if index < 0:
             num_spaces = rffi.getintfield(info, 'c_error_location')
             raise oefmt(self.w_FFIError, "%s\n%s\n%s^",
                         rffi.charp2str(info.c_error_message),
                         string,
                         " " * num_spaces)
         x = realize_c_type.realize_c_type_or_func(
             self, self.ctxobj.info.c_output, index)
         assert x is not None
         if isinstance(x, realize_c_type.W_RawFuncType):
             x.unwrap_as_fnptr(self)      # force it here
         self.types_dict[string] = x
     #
     if isinstance(x, W_CType):
         return x
     else:
         assert isinstance(x, realize_c_type.W_RawFuncType)
         if consider_fn_as_fnptr:
             return x.unwrap_as_fnptr_in_elidable()
         else:
             raise x.unexpected_fn_type(self)