[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Dotgnu-libjit] Convert a jit_type_ubyte to int = Segmentation fault
From: |
Klaus Treichel |
Subject: |
Re: [Dotgnu-libjit] Convert a jit_type_ubyte to int = Segmentation fault |
Date: |
Sat, 27 Aug 2011 17:14:38 +0200 |
Hi Manolo,
first fix the compiler warnings:
TestBugxxx.c: In function ‘main’:
TestBugxxx.c:36:5: warning: passing argument 3 of
‘jit_value_create_nint_constant’ makes integer from pointer without a
cast
/usr/local/include/jit/jit-value.h:57:13: note: expected ‘jit_nint’ but
argument is of type ‘char *’
TestBugxxx.c:36:13: warning: assignment makes integer from pointer
without a cast
TestBugxxx.c:37:5: warning: passing argument 3 of
‘jit_value_create_nint_constant’ makes integer from pointer without a
cast
/usr/local/include/jit/jit-value.h:57:13: note: expected ‘jit_nint’ but
argument is of type ‘jit_int *’
TestBugxxx.c:37:13: warning: assignment makes integer from pointer
without a cast
TestBugxxx.c:38:20: warning: assignment makes integer from pointer
without a cast
TestBugxxx.c:40:7: warning: passing argument 3 of ‘jit_insn_store’ makes
pointer from integer without a cast
/usr/local/include/jit/jit-insn.h:77:5: note: expected ‘jit_value_t’ but
argument is of type ‘jit_int’
TestBugxxx.c:42:7: warning: passing argument 3 of
‘jit_insn_load_relative’ makes integer from pointer without a cast
/usr/local/include/jit/jit-insn.h:79:13: note: expected ‘jit_nint’ but
argument is of type ‘jit_value_t’
TestBugxxx.c:44:5: warning: passing argument 3 of ‘jit_insn_add’ makes
pointer from integer without a cast
/usr/local/include/jit/jit-insn.h:98:13: note: expected ‘jit_value_t’
but argument is of type ‘jit_int’
TestBugxxx.c:45:5: warning: passing argument 2 of
‘jit_insn_store_relative’ makes pointer from integer without a cast
/usr/local/include/jit/jit-insn.h:82:5: note: expected ‘jit_value_t’ but
argument is of type ‘jit_int’
These are the warnings i get with gcc 4.6 on amd64 buiding with the
following command:
gcc -O2 -l jit TestBugxxx.c
Cheers,
Klaus
Am Mittwoch, den 24.08.2011, 17:59 +0200 schrieb manolo ohara:
> 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;
> }
> _______________________________________________
> Dotgnu-libjit mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/dotgnu-libjit
signature.asc
Description: This is a digitally signed message part