freenode/#lisp - IRC Chatlog
Search
15:55:40
Posterdati
iolib is not usable on bsd systems, due to wrong error constants definitions in sockets/grovel.lisp and syscalls/ffi-types-unix.lisp
16:25:29
White_Flame
no-defun-allowed: specifically, 32-bit ieee floats have 7.22 decimal digits of precision
22:40:33
emaczen
https://pastebin.com/zJVfpq0h -- I can't determine the inconsistent results here...
22:42:17
emaczen
I get a memory access error in local function get-family when evaluating the form (cffi:foreign-slot-value addr '(:struct sockaddr) 'sa-family)
22:44:46
|3b|
(and use cffi to allocate it rather than mixing in some other FFI and manual malloc/free)
22:55:00
|3b|
ACTION wouldn't expect it to work at all if that was the problem (or at least give nonsense results), but doesn't look right
22:55:25
russellw
when you don't specify in-package, your symbols are defined in :cl-user, aren't they?
22:57:27
|3b|
i think it was working by luck if it happened to have 0s in the right place after the pointer, since setf buf ... ifa-next would be same as above
22:57:49
|3b|
but that happens after first call to get-family, so would depend on what was in memory there
22:58:54
|3b|
so first time you were passing pointer to the pointer returned by getifaddrs to the other things
22:59:28
|3b|
and buf->ifa_next happens to be the same as *buf, so if it survives the first iteration, it works OK
23:00:25
|3b|
so you could think of it as struct ifaddrs* buf; getifaddrs(buf); too (minus any warnings from static typing)
23:00:47
|3b|
you pass a pointer to getifaddrs, it stores a pointer in the memory pointed to by the passed pointer
23:01:44
|3b|
cffi tends to have 1 extra layer of pointers than corresponding C code, which can be confusing to get used to :/
23:02:30
|3b|
ACTION supposes you should check for null pointer before that first dereference of buf too
23:04:02
emaczen
|3b|: I see the difference between my C code and my Lisp code but I don't quite see why cffi:mem-ref does the trick
23:05:12
emaczen
|3b|: but I thought I was missing a pointer... since the C code passes the address via & and in my lisp code I just passed the pointer
23:13:10
emaczen
so for cffi we have to get rid of an extra pointer because getifaddrs thinks it is a **
23:18:05
|3b|
in C we can make a local variable, and pass a pointer to it, in cl, we can't make a local, so have to allocate the "struct ifaddr*" explicitly
23:18:43
|3b|
in C, we can make a local temp pointer to the struct ifaddr*, but in lisp we would have to explicitly allocate that too
23:20:40
|3b|
but more so in lisp since you have 2 allocations (though you never freeifaddrs in lisp)