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