Re: Best Nim translation of C {void*, size_t} struct

2020-05-28 Thread Araq
It's supposed to work, yes and should be documented in the manual.

Re: Best Nim translation of C {void*, size_t} struct

2020-05-28 Thread snej
Just to make sure you're answering the exact question I asked :) — if I declare a C proc that takes an `openarray`, when Nim calls that function does it pass that parameter as a pointer followed by an int? For example: proc set_bytes(bytes: openarray[byte]) {.importc: "set_bytes".}

Re: Best Nim translation of C {void*, size_t} struct

2020-05-22 Thread Araq
I would use `openarray[uint8]` too. Strictly speaking though Nim uses a Nim `int` (== `ssize_t`) as the length information and so it's incompatible for arrays which contain more than 2 billion elements (on a 32 bit machine). Never happens.

Best Nim translation of C {void*, size_t} struct

2020-05-22 Thread snej
I'm working on Nim glue to a C API that uses `struct iovec` a lot as a parameter type — a generic (pointer, length) tuple indicating a range of memory to read or write. IIRC, a Nim `openarray[uint8]` is passed the same way as an `iovec`: as the address of the first byte, then the length. So if