pointer->integer returns unexpected value on Windows
Issue #22
resolved
Prepare C function;
void set_int(int *i) { *i = 0xF5; }
call above from Scheme like this;
(let ((p (integer->pointer -1))
(set-int (c-function void set_int (void*))))
(set-int (address p))
(pointer->integer p))
This should return #xF5 but return something very huge.
Comments (4)
-
reporter -
reporter - changed status to resolved
Added pointer->uinteger, pointer->long, pointer->ulong and uinteger->pointer (fixes
#22)→ <<cset c0b2d67bfc02>>
-
reporter - changed status to open
This doesn't work if void* = long = 8 environment (64 bit linux). it's better to let user specify how much pointer value want
so pointer->integer and pointer->uinteger should have optional argument which specify the bits. (by default all)
-
reporter - changed status to resolved
Removed pointer->long and pointer->ulong. Added optional argument bits to pointer->integer and pointer->uinteger (Fixes
#22)→ <<cset 9d735e3096a7>>
- Log in to comment
This is probably an expected behaviour on 64 bit Windows. The actual cause is the different size of void* and long.
So actual pointer value is 0xFFFFFFFFFFFFFFFF and set_int only sets 32 bit. then after setting the pointer value would be 0xFFFFFFFF000000F5. pointer->integer converts this value to a negative integer.
So if the value is expected to be an 32 bit size then it's better to get pointer value directly (slot ref return uintptr_t value) and mask it.
I'll add 4 procedures to handle this case
pointer->long and pointer->ulong would do the same as pointer->integer and pointer->uinteger on the environment which has the same size of void* and long.