1. Quick question

(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

new topic     » topic index » view message » categorize

2. Re: Quick question

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 
 

new topic     » goto parent     » topic index » view message » categorize

3. Re: Quick question

Same for Windows 7.

new topic     » goto parent     » topic index » view message » categorize

4. Re: Quick question

Thanks

Hmmm...

petelomax said...

(I am not trying to imply anything is wrong at all...

kinda wish I hadn't said that now blink

new topic     » goto parent     » topic index » view message » categorize

5. Re: Quick question

petelomax said...

Thanks

Hmmm...

petelomax said...

(I am not trying to imply anything is wrong at all...

kinda wish I hadn't said that now blink

Yes, your define_c_func() call is wrong.

Matt

new topic     » goto parent     » topic index » view message » categorize

6. Re: Quick question

mattlewis said...

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?

new topic     » goto parent     » topic index » view message » categorize

7. Re: Quick question

petelomax said...
mattlewis said...

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

new topic     » goto parent     » topic index » view message » categorize

8. Re: Quick question

mattlewis said...

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

new topic     » goto parent     » topic index » view message » categorize

9. Re: Quick question

ghaberek said...

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

new topic     » goto parent     » topic index » view message » categorize

10. Re: Quick question

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} )  
new topic     » goto parent     » topic index » view message » categorize

11. Re: Quick question

mattlewis said...

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 blink.

I coped with this on 32 bit, but that "half an unsigned integer" on 64 bit, erm, no thanks.

Pete

new topic     » goto parent     » topic index » view message » categorize

12. Re: Quick question

petelomax said...
mattlewis said...

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 blink.

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

new topic     » goto parent     » topic index » view message » categorize

13. Re: Quick question

mattlewis said...

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu