beneroth changed the topic of #picolisp to: PicoLisp language | The scalpel of software development | Channel Log: https://libera.irclog.whitequark.org/picolisp | Check www.picolisp.com for more information
geri has joined #picolisp
<geri> hey, any idea what I'm doing wrong here? https://0x0.st/XyZF.l
<geri> actually i realized instantly that SOCKET_PATH doesnt exist XD
<geri> and ahd a wrong Msg, it had to be cycle pause\n
<geri> still doesn't work though
<abu[7]> Hi geri!
<abu[7]> No idea at a first glance
<geri> im guessing something's wrong with the Addr struct
<abu[7]> Two ints?
<geri> the thing is i honestly dont know
<geri> but AF_UNIX and SOCKET_PATH are ints
<geri> (i think!)
<abu[7]> T
<abu[7]> passing numbers
<geri> the struct stuff is a bit rough
<abu[7]> Have you compared with what @lib/net.l is doing?
<abu[7]> port, accept
<abu[7]> (I forgot the details)
<geri> last time i did, let me consult it again
<abu[7]> I'm preparing to leave and cannot dig into it atm
<abu[7]> But I'm sure you are close ;)
<geri> i hope...
rob_w has joined #picolisp
f8l has joined #picolisp
rob_w has quit [Remote host closed the connection]
geri has quit [Ping timeout: 244 seconds]
bjorkintosh has quit [Quit: "Every day, computers are making people easier to use." David Temkin]
bjorkintosh has joined #picolisp
geri has joined #picolisp
<geri> okay i think my struct call is broken
<geri> found proper addr-size at least...
<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
<abu[7]> (struct Addr NIL `(- AF_UNIX) `(- SOCKET_PATH))
<geri> why minus?
<abu[7]> Integers
<geri> hm
<geri> it's actually unsigned int + char*
<geri> so i guess only first one is to be negated
<abu[7]> no, see "initialization items"
<abu[7]> "negative number, whose absolute value is stored ..."
<abu[7]> : (buf P 256 (struct P NIL -3 -4) (byte (+ P 4))) -> 4
<abu[7]> 4 bytes per iet
<abu[7]> int
<geri> okay, but SOCKET_PATH is a char[]
<abu[7]> ah, ok
<geri> transient symbol will be convered to a char[] right?
<abu[7]> No, a pointer
<geri> C arrays are pointers
<abu[7]> Yes, but a symbol is packed into a char buffer and the pointer is stored
<geri> can you just define a type that's like 2 bits wide in C?
<geri> well, maybe shorts are that, but like define your own...
<abu[7]> You need to 'apply' struct
<abu[7]> to a list of chars
<geri> uh?
<abu[7]> Better use strdup native call
<geri> do i need to chop the string or something?
<abu[7]> no, just strdup to an offset of 4
<abu[7]> oops
<abu[7]> strcpy() I mean
<geri> still doesnt do anything
<geri> eh
<geri> cffi is hard
<abu[7]> How is the structure defined in C?
<geri> struct sockaddr_un {
<geri> sa_family_t sun_family; /* Address family */
<geri> char sun_path[]; /* Socket pathname */
<geri> };
<geri> that's from the manual though, i cant find the source code
<geri> also where sa_family_t is told to be an unsigned int
<abu[7]> ok, so it is like {int n; char buf[99];}
<abu[7]> 99 is unknown
<abu[7]> (buf P 256 (struct P NIL -3) (%@ "strcpy" NIL (+ P 4) "abc") #{...}# (struct (+ P 4) 'S))
<abu[7]> -> "abc"
<abu[7]> 256 must be big enough if the max string len is unknown
<geri> okay, now gotta figure out how to insert it into my code :D
<abu[7]> :)
<geri> (buf P 256 ...) is same as doing (setq (%@ "malloc" 'P 256)), right?
<abu[7]> Yes, plus free()
<geri> oh cool
<abu[7]> It allocates on the stack
<abu[7]> So much faster
beneroth has joined #picolisp
<geri> okay, so connect doesnt work i guess, its the step returning -1
<geri> stuff's rough
<beneroth> hey geri
<geri> hi
* beneroth checks the log
<abu[7]> T, nasty stuff
<geri> trying to talk to a unix socket with picolisp
<beneroth> the file socket thingy?
<geri> yes
<beneroth> can it not be opened just like a file (instead of like a socket) ?
<geri> i tried doing redirections with bash, didnt work
<geri> says "no such device or address" upon redirection
<beneroth> how did you create the socket?
<beneroth> I think it needs to be created first
<geri> abu[7]: i also attached some working C code, i think it should be a bit clearer what im doing
<beneroth> you sure you don't mix up networking sockets (TCP) with unix domain sockets (special kind of files, acting as named pipes) ?
<beneroth> sorry if I ask stupid question ^^
<geri> very stupid question
<abu[7]> "II.sun_path = SOCKET_PATH" looks rather like a *pointer* assignment
<geri> if i mixed em up id be using (connect) and such
<beneroth> good
<geri> abu[7]: so no strcpy?
<abu[7]> T
<abu[7]> Like your initial version
<beneroth> why not doing it the ugly way by starting a 'nc' process in a bidirectional (pipe) ?
<geri> (struct Addr NIL (- AF_UNIX) SOCKET_PATH) == Addr { int; char* }?
<abu[7]> Yes
<geri> beneroth: cause if i use nc for this its extra dependancies and i may as well go to my shell script version
<beneroth> yeah makes sense
<abu[7]> The last arg to "connect" is the total struct size?
<geri> yes
<abu[7]> so probably just 12
<abu[7]> Why times 4? (* 4 (length SOCKET_PATH))))
<geri> cause each char is 4 bytes?
<geri> i have a C example
<geri> i need a picolisp example)
<beneroth> each char is 4 bytes? not in UTF-8
<geri> how much is it then?
<abu[7]> Each char may be 1 ... 4 bytes
<beneroth> 1-4
<abu[7]> so 'size' instead of 'length'
<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]
bjorkint0sh has joined #picolisp
bjorkintosh has quit [Ping timeout: 260 seconds]
f8l has quit [Ping timeout: 246 seconds]