1. Quick question
- Posted by petelomax Sep 15, 2014
- 1741 views
(I am not trying to imply anything is wrong at all, I just want a quick and plain factual answer from anyone with it already installed, since my rubbish mobile broadband is capping the d/l at a paltry 5K/s)
What does this code display on 64-bit OE
--/* include builtins\dll.e --*/ function f(atom i) ?i return 0 end function constant r_f=routine_id("f") constant cb_f=call_back(r_f) constant c_f=define_c_func({},cb_f,{C_INT},C_INT) ? c_func(c_f,{-1}) -- line 5 (in f()) displays 4294967295, then this (line 11) displays 0 if getc(0) then end if
Thanks, Pete
2. Re: Quick question
- Posted by K_D_R Sep 15, 2014
- 1704 views
Ubuntu 4.04 LTS 64-bit
4294967295 0 Euphoria Interpreter v4.1.0 development 64-bit Linux, Using System Memory Revision Date: unknown, Id: 0:unknown
4. Re: Quick question
- Posted by petelomax Sep 15, 2014
- 1749 views
Thanks
Hmmm...
(I am not trying to imply anything is wrong at all...
kinda wish I hadn't said that now
5. Re: Quick question
- Posted by mattlewis (admin) Sep 15, 2014
- 1713 views
Thanks
Hmmm...
(I am not trying to imply anything is wrong at all...
kinda wish I hadn't said that now
Yes, your define_c_func() call is wrong.
Matt
6. Re: Quick question
- Posted by petelomax Sep 16, 2014
- 1666 views
Yes, your define_c_func() call is wrong.
Oh, c'mon, I'm not a bloody mindreader! {C_FLOAT}, {C_DOUBLE}, and {C_DWORDLONG} (#03000008) all produce the inexplicable 9699474, and (the other guess/blind stabs of) #01000008 and #02000008 both give the same results. What should it say?
7. Re: Quick question
- Posted by mattlewis (admin) Sep 17, 2014
- 1661 views
Yes, your define_c_func() call is wrong.
Oh, c'mon, I'm not a bloody mindreader! {C_FLOAT}, {C_DOUBLE}, and {C_DWORDLONG} (#03000008) all produce the inexplicable 9699474, and (the other guess/blind stabs of) #01000008 and #02000008 both give the same results. What should it say?
Your function takes an atom. Use E_ATOM.
Matt
8. Re: Quick question
- Posted by ghaberek (admin) Sep 17, 2014
- 1636 views
Your function takes an atom. Use E_ATOM.
I still get 4294967295 using E_ATOM.
include std/dll.e function f( atom i ) printf( 1, "i = %d (#%08x)\n", i ) return 0 end function constant r_f = routine_id( "f") printf( 1, "r_f = %d\n", {r_f} ) constant cb_f = call_back( r_f ) printf( 1, "cb_f = #%08x\n", {cb_f} ) constant c_f = define_c_func( {}, cb_f, {E_ATOM}, E_INTEGER ) printf( 1, "c_f = %d\n", {c_f} ) ? c_func( c_f, {-1} )
r_f = 3 cb_f = #00390000 c_f = 28 i = 4294967295 (#FFFFFFFF) 0
-Greg
9. Re: Quick question
- Posted by mattlewis (admin) Sep 17, 2014
- 1605 views
I still get 4294967295 using E_ATOM.
Ah, yes. When a callback comes in, we cast everything to uintptr_t.
call_back_arg1->obj = make_atom32((uintptr_t)arg1); // etc...
Matt
10. Re: Quick question
- Posted by mattlewis (admin) Sep 17, 2014
- 1627 views
I think this does what Pete wanted:
include std/dll.e include std/machine.e atom signed_buffer = allocate( 4 ) function f( atom i ) poke4( signed_buffer, i ) printf( 1, "i = %d (#%08x)\n", peek4s( signed_buffer ) ) return 0 end function constant r_f = routine_id( "f") printf( 1, "r_f = %d\n", {r_f} ) constant cb_f = call_back( r_f ) printf( 1, "cb_f = #%08x\n", {cb_f} ) constant c_f = define_c_func( {}, cb_f, {C_INT}, E_INTEGER ) printf( 1, "c_f = %d\n", {c_f} ) ? c_func( c_f, {-1} )
11. Re: Quick question
- Posted by petelomax Sep 19, 2014
- 1518 views
I think this does what Pete wanted:
Ick. What I actually wanted I suppose, apart from another incompatibility between Eu and Phix, was a function f(integer i) that actually got the -1 as actually sent to it, which actually, I've now got .
I coped with this on 32 bit, but that "half an unsigned integer" on 64 bit, erm, no thanks.
Pete
12. Re: Quick question
- Posted by mattlewis (admin) Sep 22, 2014
- 1459 views
I think this does what Pete wanted:
Ick. What I actually wanted I suppose, apart from another incompatibility between Eu and Phix, was a function f(integer i) that actually got the -1 as actually sent to it, which actually, I've now got .
I coped with this on 32 bit, but that "half an unsigned integer" on 64 bit, erm, no thanks.
Oh, well, I just used 32-bits because you were using C_INT, which is a 32-bit signed integer on all of euphoria's platforms. Though I see that we have a bug there for interpreter callbacks for 64-bit platforms (the interpreter version uses make_atom32 instead of make_atom). Also, %d doesn't seem to handle a 64-bit unsigned value.
Matt
13. Re: Quick question
- Posted by mattlewis (admin) Sep 22, 2014
- 1494 views
Oh, well, I just used 32-bits because you were using C_INT, which is a 32-bit signed integer on all of euphoria's platforms. Though I see that we have a bug there for interpreter callbacks for 64-bit platforms (the interpreter version uses make_atom32 instead of make_atom). Also, %d doesn't seem to handle a 64-bit unsigned value.
I just pushed up a fix for the callback stuff. Now I can do:
include std/dll.e include std/machine.e atom signed_buffer = allocate( sizeof( C_POINTER ) ) function f( atom i ) printf( 1, "i = %g (#%x)\n", i ) poke_pointer( signed_buffer, i ) ifdef BITS64 then i = peek8s( signed_buffer ) elsedef i = peek4s( signed_buffer ) end ifdef printf( 1, "i = %d (#%x)\n", i ) return 0 end function constant r_f = routine_id( "f") printf( 1, "r_f = %d\n", {r_f} ) constant cb_f = call_back( r_f ) printf( 1, "cb_f = #%08x\n", {cb_f} ) constant c_f = define_c_func( {}, cb_f, {C_POINTER}, E_INTEGER ) printf( 1, "c_f = %d\n", {c_f} ) ? c_func( c_f, {-1} )
Note that there isn't a signed peek for pointer sized integers, which makes this a little more verbose to handle that detail.
Matt