<geri>
sockfd gets created fine it seems, addr looks okayish too, but struct stuff looks very off - when i try to look up a value form the addr struct everything looks off
<beneroth>
marked with leading 1 on each byte, how many belong to the same char
<beneroth>
ASCII char are normal 1 byte
<geri>
abu[7]: its 10, huh
<beneroth>
abu[7] T
<beneroth>
geri, see e.g. getChar in src/io.l of pil21 (in the pico llvm dialect)
<abu[7]>
(size "abc") -> 3 (size "赤髭") -> 6
<beneroth>
: (length "😎 ")
<beneroth>
-> 2
<beneroth>
: (size "😎 ")
<beneroth>
-> 5
<geri>
B)
<beneroth>
(uh I added a space by mistake)
<beneroth>
: (size "😎")
<beneroth>
: (length "😎")
<beneroth>
-> 1
<beneroth>
-> 4
<geri>
(spammer!)
<beneroth>
1 char, 4 bytes
<beneroth>
(sorry! not really sorry)
<abu[7]>
:)
<abu[7]>
What anyway we probably need only the pointer
<abu[7]>
(if we understand the structure right)
<geri>
(struct P NIL -1 "/tmp/music")
<geri>
how do i print this one
<geri>
(struct P '(I P)) doesnt break but doesnt print the string
<beneroth>
abu[7], yeah the struct is handed in
<beneroth>
geri, 'S is the code for (struct) to return a picolisp string
<geri>
it crashes the interpreter if i do '(I S)
<beneroth>
its very easy to crash (do invalid memory access) with struct, that's true
<beneroth>
always a programmer error
<geri>
if i do (struct (+ 4 P) 'S) it returns gibberish
<geri>
maybe because stuff after 4 bytes is a pointer to chars
<beneroth>
the chars must end with C-string NULL termination to be read by (struct Buf 'S ...)
<abu[7]>
Hmm, perhaps only 'native' takes a symbol directly?
<abu[7]>
I forgot
<beneroth>
you can use (byte) to set the NULL byte
<geri>
okay actually i think ive had enough for today xd
<geri>
gotta sleep at adequate times
<beneroth>
if you attempt to read a binary buffer as a string with (struct) and its not C-style NULL-terminated, then struct happily reads garbage until it finds NULL or is stopped because its accessing invalid/forbidden memory
<beneroth>
geri, ok, have a good sleep
<geri>
thanks
<beneroth>
don't give up! it's definitely doable with pil
<beneroth>
but the stuff is a bit tricky and needs some head-wrapping
<abu[7]>
Ok, let's think tomorrow
<beneroth>
abu[7], you're also tired or busy? Else I can quickly tell how nginx is distributing the load on multiple workers, I only recently find out xD
<beneroth>
maybe interesting. not relevant nor important, though.
<abu[7]>
Yes, indeed interesting, but not so good today :)
<beneroth>
kk, have a good evening :)
<abu[7]>
Thanks, you all too ☺
<abu[7]>
geri, could not resist :)
<abu[7]>
How about this?
<abu[7]>
(buf P 256 (buf S 4 (struct S NIL '("abc" . 4)) (struct P NIL -3 (cons S 8)) (struct P '(I S))))
<abu[7]>
-> (3 "abc")
<abu[7]>
I don't remember atm if there is an easier way
<abu[7]>
Perhaps aw- knows? He did more native stuff
<abu[7]>
You can also pass an on-the-fly struct to 'native' as '(NIL (12) -3 "abc")
<abu[7]>
ie. without calling 'struct'
<abu[7]>
'native' automatically allocates the 12 bytes, fills in 4 and the string pointer, and frees all when done
<abu[7]>
OK, must stop for today
<abu[7]>
o/
lagash has quit [Ping timeout: 276 seconds]
lagash has joined #picolisp
lagash has quit [Remote host closed the connection]