def get_ctypes_ptr(typingctx, ctypes_typ=None): assert isinstance(ctypes_typ, types.ArrayCTypes) def codegen(context, builder, sig, args): in_carr, = args ctinfo = context.make_helper(builder, sig.args[0], in_carr) return ctinfo.data return types.voidptr(ctypes_typ), codegen
def asvoidp(tyctx, thing): sig = types.voidptr(thing) def codegen(cgctx, builder, sig, args): dm_thing = cgctx.data_model_manager[sig.args[0]] data_thing = dm_thing.as_data(builder, args[0]) ptr_thing = cgutils.alloca_once_value(builder, data_thing) return builder.bitcast(ptr_thing, cgutils.voidptr_t) return sig, codegen
def get_c_arr_ptr(typingctx, c_arr, ind_t=None): assert isinstance(c_arr, (types.CPointer, types.ArrayCTypes)) def codegen(context, builder, sig, args): in_arr, ind = args if isinstance(sig.args[0], types.ArrayCTypes): in_arr = builder.extract_value(in_arr, 0) return builder.bitcast(builder.gep(in_arr, [ind]), lir.IntType(8).as_pointer()) return types.voidptr(c_arr, ind_t), codegen
@box(CharType) def box_char(typ, val, c): """ """ fnty = lir.FunctionType(lir.IntType(8).as_pointer(), [lir.IntType(8)]) fn = c.builder.module.get_or_insert_function(fnty, name="get_char_ptr") c_str = c.builder.call(fn, [val]) pystr = c.pyapi.string_from_string_and_size( c_str, c.context.get_constant(types.intp, 1)) # TODO: delete ptr return pystr del_str = types.ExternalFunction("del_str", types.void(string_type)) _hash_str = types.ExternalFunction("_hash_str", types.int64(string_type)) get_c_str = types.ExternalFunction("get_c_str", types.voidptr(string_type)) @overload_method(StringType, 'c_str') def str_c_str(str_typ): return lambda s: get_c_str(s) @overload_method(StringType, 'join') def str_join(str_typ, iterable_typ): # TODO: more efficient implementation (e.g. C++ string buffer) def str_join_impl(sep_str, str_container): res = "" counter = 0 for s in str_container: if counter != 0: