freenode/#lisp - IRC Chatlog
Search
6:43:45
beach
reinuseslisp: You may want to check with pjb. He has worked on MCL for some projects as I recall.
9:16:05
flip214
I'm trying to use CFFI. I need to allocate a pointer (done via (cffi:with-foreign-object (x :pointer))), and then need to pass the _address_ of that pointer to a function.
9:16:46
flip214
Do I need to check the foreign function declaration to make it pass the address of the SAP on?
9:18:07
flip214
well, it's about gphoto2 and (cffi:defcfun ("gp_list_new" gp_list_new) :int (list :pointer))
9:18:35
flip214
this actually needs to get the address of a pointer, so that it can allocate some memory and "return" the address
9:24:33
phoe
You give it an address of a size_t, it does some magic and destructively modifies the size_t at that address. Do I get it right?
9:25:10
flip214
well, I give it the address of a (void *), and the _destination_ of that pointer is modified, yeah.
9:26:46
phoe
so you can just allocate size_t bytes of memory and pass that address to that function.
9:27:55
flip214
yeah, but how do I pass the address? That's what I'm trying to do in these wrapper functions...
9:29:03
phoe
CFFI will notice that you passed it a SAP object, and it will unwrap it and pass the pointer itself to the C function.
9:30:24
flip214
yeah, but to _initialize_ the pointer I need to pass the _address_ of that pointer to a function!
9:33:56
phoe
forget about C types for a moment. all in all, you are not allocating "pointers to pointers". you're allocatiing size_t bytes of raw memory, and that's what your function actually expects.
9:38:54
flip214
I know about the low-level implications. I just don't know or even _where_ to tell CFFI that it needs to pass the "object" (as in the address of the allocated memory range) versus it needs to pass the _content_ (the size_t bytes in that object that now contain the address to some memory)
9:39:01
beach
So you can't take the address of a pointer, just like you can't take the address of an integer.
9:39:50
christiaan
What is the diffrence between let and let* ? Im reading the help for both in emacs, but its not clearer.
9:40:27
beach
christiaan: For LET*, the bindings are established sequentially, so that the variable bound in the first binding is available to the forms of the subsequent bindings.
9:40:28
flip214
swig gave me (:pointer) as types for both "CameraList**" and "CameraList*"; perhaps I need to fix _that_ to make it clear what needs to be passed?!
9:41:30
flip214
beach: well, a pointer needs to be stored somewhere... and I'd like to pass the address of that storage location, so that the called function can "return" me where its allocated data lives.
9:42:52
flip214
THIS function needs a pointer to size_t bytes where it can put the address of allocated memory.
9:43:55
flip214
but how would I reflect that in lisp and cffi? "The value 140730302857200 is not of type SB-SYS:SYSTEM-AREA-POINTER when binding SB-ALIEN::VALUE
9:44:30
beach
christiaan: So if you have (let ((x 1)) (let ((x 2) (y x)) (+ x y))) the x in (y x) refers to the outermost x, and you get 3, but in (let ((x 1)) (let* ((x 2) (y x)) (+ x y))), the x in (y x) refers to the inner x, so you get 4.
9:45:49
flip214
that's becoming philosophical.... if it's not stored anywhere (not even in a register), is it still a pointer?? ;) sorry.
9:46:09
beach
flip214: Take (x + 1) where x is a pointer. The resulting pointer is stored nowhere (at least not in a memory location). You can do *(x + 1) to dereference it without storing it in memory.
9:46:53
flip214
but how would I pass a) the address of the size_t bytes to a function to initialize them and later on b) pass these size_t bytes (now interpreted as a pointer) to another function?
9:46:57
beach
flip214: You can't take the address of a register, which is why you can only take the address of variables (or similar, like array locations) but not of values like integers and pointers.
9:49:51
beach
christiaan: Yes, in LET* the forms of the following bindings are included in the scope of a binding.
9:50:46
beach
In LET* the forms of the following bindings are included in the scope of a binding. In LET, that is not the case, The scope of a binding covers only the body forms.
9:52:23
beach
So if I mark with brackets the scope of x in (let ((x ...) ...) ...) and in (let* ((x ...) (...)) ...), you get (let ((x ...) ...) [...]) and (let* ((x ...) [...) ...])
9:53:55
flip214
_death: because I only right now found https://stackoverflow.com/questions/35841771/common-lisp-cffi-pointer-to-the-pointer telling me about mem-ref .... ;/
9:57:08
flip214
phoe: you did? I only saw pointer-address, which returns the wrong type (integer instead of a pointer)
11:36:08
flip214
CONSTANTP would be true for number literals etc., right? but why is EVAL then needed?
11:39:57
flip214
Bike: for a macro call like (WITH-FOREIGN-OBJECT (x :POINTER) ...), where would QUOTE come from?
11:41:16
flip214
or rather (WITH-FOREIGN-OBJECT (x 'my-type) ...), in analogy with MAKE-INSTANCE or so...
12:35:27
flip214
when using gphoto2 from sbcl, it tries to mmap 10GB of RAM, fails, and then returns a fake USB camera
12:45:17
flip214
my current guess is that because of my SBCL image being a few GB in space, it uses the address of some allocated memory block as the next size or so
12:52:21
flip214
pthread_create@@GLIBC_2.2.5 + 60 in section .text of /lib/x86_64-linux-gnu/libpthread.so.0
13:02:00
phoe
flip214: it's not about shutting you up, it's about poking you in the direction of the people who know the implementation details of SBCL
13:02:18
beach
pjb: Earlier, reinuseslisp wondered whether there is any common lisp for mac os 9.2.2 (pre os x). I said you might have some information.
13:04:08
flip214
no, not directly. only happens with sbcl and not a standalone C because of other mechanisms...
13:05:26
ludston
All of the resources that I have looked at say, "class slot access is slower than struct"
13:15:19
pjb
Nope, the 68K subdirectories in the sources of rmcl are empty (rmcl = Rosetta MCL AFAIUI).
13:16:42
pjb
Oh, he said macos 9.2.2 without precising the processor. it also ran on ppc, so rmcl could do in that case.
13:19:40
Bike
ludston: if you're on sbcl, i think it speeds up slot accesses inside appropriately specialized methods. i'd still be surprised to see structs be slower though.
13:21:29
ludston
Actually that's probably why; Since I stick some explicit types on the structs when I convert their types, it's likely that I have inadvertantly introduces lots of type conversions
13:24:54
Bike
guess it depends on what you're doing... if your implementation has unboxed struct storage, i would expect it to have unboxed arithmetic and boxing elision as well
13:27:13
ludston
I'm hazarding a guess here, but I'd expect that if I did (defmethod add (x y) (+ 1 2))
13:29:30
ludston
I am in this case, but if I am dispatching on a struct, and the second argument is a number, for example
14:38:24
flip214
swank:undefine-function in sbcl seems to keep the same function type declaration in place -- redefining the function with a different arglist gives style-warnings
14:43:09
Bike
i don't know what the design of that particular function is, but type declarations are independent of the actual definition. you can declare an ftype for a function before you define it, after all.
14:44:30
flip214
so the declaration shouldn't be removed along with the definition by swank? okay, thanks.
14:53:19
BW^-
are you aware of any distributed connected components algorithms for *dynamic* (aka online) graphs?
14:56:45
ludston
I had a function in a tight loop that was wrapping around a (defmethod) by accident
14:57:35
ludston
Things learned: If I see a certain kind of lock in the profiler it means it's a function being defined over and over
15:05:40
ludston
Factor of 2, maybe is impressive but in a production environment usually there is *somewhere* that is redundantly O(n)
15:08:25
rpg
The only such algorithms I know are for dynamic transitive closure (longest paths), but I'm also interested.
15:12:23
ludston
schweers: It was impressively bad code. It takes real skill to write something that performs so badly and still has the right answer.
15:13:21
schweers
you mean without having to resort to such obvious things as (dotimes (i 100000000000000)) ;)
15:15:53
rpg
BW^-: https://stackoverflow.com/questions/7241151/how-to-find-connected-component-dynamically
15:16:47
beach
marvin2: There is no attempt whatsoever to update the Common Lisp standard, if that is what you mean.