lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am 06.12.2013 23:28 schröbte Andrew Starks:
[please forgive me if this isn't the appropriate place to discuss
Roberto's struct library]

Compiling struct in Windows works, accepting warnings about size_t ->
int conversions, which I normally ignore, but...

Running the provided test file in Windows 7 64bit, it fails here:

`assert(lib.pack('<T', -10) == string.char(256-10) .. string.char(255):rep(x))`

given the following minimal example:

```lua

local lib = require"struct"

x = lib.size("T") - 1

assert(lib.pack('<!T', 10) == string.char(10) .. string.char(0):rep(x))
assert(lib.pack('>!T', 10) == string.char(0):rep(x) .. string.char(10))

local str = lib.pack('<!T', -10)
local str2 = string.char(256-10)..string.char(255):rep(x)

print(x, #str, #str2)

for i = 1, #str do
   print(i, str:sub(i,i) == str2:sub(i,i),
     str:byte(i), str2:byte(i)
   )
end

assert(lib.pack('<T', -10) == string.char(256-10) .. string.char(255):rep(x))

```

Output in WIN64 is:

```
7       8       8
1       true    246     246
2       true    255     255
3       true    255     255
4       true    255     255
5       false   0       255
6       false   0       255
7       false   0       255
8       false   0       255
lua: aas_test.lua:19: assertion failed!
stack traceback:
         [C]: in function 'assert'
         aas_test.lua:19: in main chunk
         [C]: in ?
```

This looks like there's some truncation to 32 bits going on. Can you check if recompiling with ´STRUCT_INT` #defined to `ptrdiff_t` solves the problem (the default `long` still being 32 bits on Windows 64)?


Philipp