> Hello.
> I'm trying to convert a jit_type_ubyte to int, but it gives me
> "segmentation fault".
> My machine: Debian 6.0 32 bits with the last libjit version.
>
> What's the problem?
>
> #include <stdio.h>
> #include <jit/jit.h>
>
> int main(void)
> { jit_int p_memory;
> char memory[65536];
> jit_context_t context;
> jit_type_t signature;
> jit_function_t function;
> jit_value_t tmp1,tmp2,tmp3,tmp4,tmp_index,ubyte_tmp1;
> jit_int index,constant_100000,p_result,result;
>
> index=3;
> memory[index]=0x56;
>
> /* result=memory[index]+10000*/
>
> /* Create a context to hold the JIT's primary state */
> context = jit_context_create();
>
> /* Lock the context while we build and compile the function */
> jit_context_build_start(context);
>
> /* Build the function signature */
> signature = jit_type_create_signature(jit_abi_cdecl,
> jit_type_void, 0, 0, 1);
>
> /* Create the function object */
> function = jit_function_create(context, signature);
> tmp1 = jit_value_create(function, jit_type_int);
> tmp2 = jit_value_create(function, jit_type_int);
> tmp3 = jit_value_create(function, jit_type_int);
> tmp4 = jit_value_create(function, jit_type_int);
> tmp_index = jit_value_create(function, jit_type_int);
> ubyte_tmp1=jit_value_create(function, jit_type_ubyte);
>
> p_memory=jit_value_create_nint_constant(function,jit_type_void_ptr,memory);/* p_memory=&memory*/
>
> p_result=jit_value_create_nint_constant(function,jit_type_void_ptr,
> &result); /* p_result=&result*/
>
> constant_100000=jit_value_create_nint_constant(function,jit_type_sys_int,(jit_int)(100000)); /*constant_100000=100000*/
>
> tmp_index=jit_value_create_nint_constant(function,jit_type_sys_int,(jit_int)(index)); /*tmp_index=index*/
> jit_insn_store(function, tmp1,p_memory);/* tmp1=p_memory*/
> jit_insn_store(function, tmp2,tmp_index); /* tmp2=index*/
>
>
> ubyte_tmp1=jit_insn_load_relative(function,tmp1,tmp2,jit_type_ubyte);/*ubyte_tmp1=memory(tmp1+tmp2) */
> tmp3=jit_insn_convert(function,
> ubyte_tmp1,jit_type_int,0);/*tmp3=(int)ubyte_tmp1*/ /*SEGMENT
> VIOLATION*/
> tmp4=jit_insn_add(function, tmp3,constant_100000); /*tmp4=tmp3
> +constant_100000*/
> jit_insn_store_relative(function,p_result,(jit_int)0,tmp4);/*
> memory(p_result+0)=tmp4*/
>
> /* Compile the function */
> jit_function_compile(function);
> jit_dump_function(stdout,function,"myfunct");
> /* Unlock the context */
> jit_context_build_end(context);
>
> /* Execute the function and print the result */
>
> jit_function_apply(function,0,0);
>
>
> /* Clean up */
> jit_context_destroy(context);
>
> /* Finished */
> printf("\nresult=%d\n",result);
> /* Finished */
> return 0;
> }
> _______________________________________________