freenode/#lisp - IRC Chatlog
Search
22:57:22
emaczen
Shinmera: I'm having trouble arefing a foreign pointer/array the type of the array is an opaque type just defined like: struct name;
23:04:22
axg`
maybe you can define it as an alias to *void? types aren't "allocated" when defined beyond as data within cffi/the c compiler
23:07:52
emaczen
the C code initializes the pointer like: type **name; and then passes it in the function call via func(&name)
23:11:19
Bicyclidine
you have no addressof in lisp. if you want to pass a pointer you have to allocate a pointer
23:11:44
Bicyclidine
cffi doesn't really care about the type beyond knowing that it's a pointer, though
0:07:53
pjb
Shinmera: I wouldn't be so categoric: pointers can have different sizes. eg. in MS-DOS. But also because you may have pointers to different type of data requiring more or less bits.
3:38:45
jasom
pjb: Bike, faff appears to be gone now, but what about this, which doesn't appear to have been suggested: (apply map 'list (lambda (x y) (+ x y)) (k1))
3:48:31
emaczen
https://pastebin.com/PKJz7FLH -- I am having trouble converting this C code to lisp CFFI code
3:49:26
emaczen
I've written a short fully working program that uses CFFI and an external C library without any problems before, but the code was of a different style and didn't pass pointers to be modified like this code does
3:57:06
|3b|
https://github.com/3b/3b-libusb1/blob/master/bindings.lisp is how i would have done it ~2.5 years ago :)
3:58:07
axg
in the C++ code, you are passing the address of your ctx pointer to init. in the lisp version, it looks like you are passing null
3:58:53
|3b|
(though possibly for older version of libusb, not sure how much/if it has changed since then)
4:06:29
|3b|
you might need to read the pointer from that pointer after calling init to get something you can pass to other functions
4:07:31
pjb
jasom: I proposed: (apply (function map) 'list (function +) (f1)) <-- F1, an operator returning a list of lists. The point of k1 is that it is not possible for a macro to return multiple forms. A macro can only return one form. This form could compute a list of list, so (apply (function map) 'list (function +) (k1)) would be possible. But there would be no point in using a macro, since a function would work as well.
4:10:13
emaczen
All I changed was adding (cffi:mem-ref context :pointer) right after (libusb-init context)
4:13:37
emaczen
Okay now, it isn't giving me an unhandled memory error BUT when I (cffi:mem-ref devices :pointer 5) it is the null pointer
4:15:34
|3b|
ACTION can't explain it in IRc better than https://github.com/3b/3b-libusb1/blob/master/wrappers.lisp#L15 :p
4:17:47
jasom
emaczen: yes; the lisp code you would would roughly correspond to the c code: context = malloc(sizeof(void **)); libusb_init(context); libusb_get_device_list(*context);
4:18:30
|3b|
thanks, that's what i was failing to find words for :) been too long since i used C directly
4:18:33
jasom
because you need to explicitly allocate in lisp anything you are going to pass to C (rather than implicitly allocate on the stack like your C code)
4:19:48
emaczen
Now my problem is that libusb-get-device-list returns 6 (so I have 6 usb devices) which means I should be able to (cffi:mem-ref devices :pointer 5)
4:25:05
|3b|
and you probably want mem-aref there, where the offset is in pointers rather than bytes
4:29:13
emaczen
What should I be expecting in the print statements? I have no idea what are reasonable values for the number of configurations, device class, vendor id, or product id
4:36:14
beach
So again, we are on freenode (dedicated to free software) in the #lisp channel (dedicated to Common Lisp), but we are talking about using other languages on commercial operating systems. Go figure.
4:39:08
|3b|
beach: at least the foreign library in question doesn't require the commercial operating systems :)
4:49:12
|3b|
ACTION generally considers falling cffi:foreign-alloc directly to be "something wrong" without good reason, but shouldn't affect output of that
4:51:55
|3b|
assuming those are correct, looks reasonable, but i'd probably try to verify the offsets if possible (print results of offsetof from the c code for example)
4:52:15
|3b|
works if you know your ABI well enough to get the alignment etc right when counting bytes :)
4:52:49
|3b|
ACTION would just put all the fields in and let cffi figure it out for normal libraries
4:55:58
emaczen
and then I'm calling (print-dev (cffi:mem-aref devices :pointer 2)) or another index
5:04:43
|3b|
ACTION thinks padding might not matter for that struct, since it has uint8 in multiples of 2 between the uint16, but multiplying offsets by 8 probably isn't good :)
5:05:09
|3b|
(at least in my version of it, which presumably matched the C version well enough for my code to run at some point)
5:09:19
emaczen
|3b|: Right now, I'm just trying to get started with programming with USB devices from CL
5:12:03
|3b|
might see if my lib still works... not very complete but at least might bet you a little bit further to start out
5:16:25
emaczen
|3b|: Thanks for the help, the hardest part is getting started... I should be able to figure out a lot from here with the pointers given
5:22:13
sigjuice
would it be possible to do something like this to make a custom sbcl binary? (defsystem "mysbcl/exe" :build-operation program-op :build-pathname "mysbcl" :entry-point "launch-sbcl-repl????" :depends-on (...))
5:36:34
pillton
sigjuice: https://github.com/markcox80/lisp-executable/blob/master/lisp-executable-example.asd#L39
5:42:14
sigjuice
|3b| yes, sort of. and is it something I can use as an entrypoint in the asdf:defsystem I mentioned above.
5:47:12
pillton
sigjuice: Lisp-executable won't be of any use if you want that. I didn't read what you said properly.
5:58:12
pillton
sigjuice: No worries. Sorry for not reading your original question correctly. Thanks to |3b|.
9:36:50
schweers
ACTION wonders if filenames like foo.tar.gz might have been a bad idea after all (considering how SBCL handles the type of a namesting/pathname)
9:56:47
pjb
schweers: for unix, it's not a bad idea. But for common lisp logical pathnames, it's redhibitory, since #\. is not a conforming character for pathname names. cf. 19.3.1
9:58:00
schweers
Well, how were an implementation to know whether the dot separates the (stack of) type(s), or whether its just a funny name?
9:59:13
schweers
I know it is, but what I mean is: what might be the best behaviour? guessing is not an option, and the filenames themselves don’t provide enough information
10:02:13
schweers
pjb: I just now realized you were talking about logical pathnames. Are the rules for them relevant if I don’t use them (directly)?
10:04:41
Shinmera
schweers: The real problem is that the file name matters at all, rather than the type of file being encoded in the data/inode in a standard way.
10:05:13
schweers
That is what I would have preferred (I guess), but filesystems are the way they now are, I guess :(
10:06:08
pjb
schweers: of course, logical pathnames are not relevant when you don't use them directly. When you talk about a physical pathname such as "foo.tar.gz", nothing matters, since it's entirely implementation dependent how it's interpreted.
10:06:27
pjb
schweers: yes, two implementations can choose to cut the name / type on different dots.
10:07:10
schweers
okay, that’s what I thought. Not entirely satisfactory, but I guess I’ll just have to live with that
10:10:22
schweers
considering logical pathnames: are they used in the wild? i.e. do you guys and gals use them?
10:11:08
schweers
I must admit that I don’t know anything about them, other than that I have read statements online (can’t remember where or by whom) that they are badly designed and one should avoid them
10:11:11
pjb
You could have the rule, that you should not have literal physical pathnames in lisp sources. Only literal logical pathnames are allowed.
10:12:15
pjb
logical pathnames offers an indirection level allowing you to manipulate pathnames in an implementation independent way, thru the logical-pathname-translation mapping.
10:12:52
pjb
So you don't have to care where the files and directory your application uses are located; this will be decided by the user (thru load-logical-pathname-translations).
10:13:44
pjb
see for example: https://gitlab.com/patchwork/patchwork/blob/master/loghosts.lisp and https://gitlab.com/patchwork/patchwork/blob/master/builder.lisp