freenode/#ecl - IRC Chatlog
Search
15:47:24
compuphonic
hey guys, I've been trying out ECL lately and I have a question. I'd like to initialize a struct that has a function pointer memeber with a cffi:defcallback function pointer but I'm not sure how to go about it in ECL. I do plan to use ECL but if there's a fully portable solution I'd still be open to that. I suppose I could write a wrapper but since this struct is fed to another application through ashared
15:55:39
pjb
compuphonic: the easiest way to do it in ecl, is to use c-line. Otherwise, you can do it portably with cffi, but it's more difficult and problematic (you have to know the size of the function pointers, etc).
15:59:54
jackdaniel
compuphonic: defcallback should be OK (i.e it should return function pointer), what is the problem?
16:21:01
compuphonic
jackdaniel: Well the issue is that I need the struct that this function pointer resides in to be statically initialized so it can be exported globally for the other program to load. I just can't seem to figure out a way to have (callback [callback-name]) work in that instance.
16:22:42
compuphonic
I tried to create a variable using c-inline but in that case I checked the symbol table and it wasn't exported
16:24:35
compuphonic
if it was the case that I could just setf everything thn I wouldn't mind but it's getting exported as a shared library and te program that loads it is looking for a symbol (the struct) with the data loaded already
16:26:19
compuphonic
like have the struct be partially initialized with clines and then when the function pointer member came up, I could insert c-inline to get run (callback) and return the address of the lisp function pointer, and then continue with the rest of the members.
16:26:20
jackdaniel
you can, note though that clines are put toplevel, while c-inline is indeed inline in the source code
16:26:39
pjb
Well, shared libraries may imply another set of problems. In some cases, you can have write initialization code in shared libraries.
16:27:08
pjb
The thing is that you need to understand how things work, to be able to do the right thing.
16:27:38
jackdaniel
compuphonic: for some very good examples you may see contrib/sockets/sockets.lisp in ECL source code
16:30:39
compuphonic
pjb, that's no issue in this case. I've loaded plenty of shared libs in the past. I can get ECL to build a shared lib but it's just the way that this program does it's loading through a statically initialized struct that's giving me issue. I do agree though, that's why I came to ask about ECL so I could get some understanding about it. jackdaniel: I'll check there and see what I can find, thanks.
16:31:54
jackdaniel
compuphonic: if that won't prove helpful, please fill an issue on the tracker with some steps to reproduce, I will try to come up with a recommended way next week
16:32:24
pjb
Usually, I write my own initialize function that I call when the application launches. I try to avoid implicit initialization done in defvar/defparameter and other toplevel code. Notice in the case of ecl however, that there's no image saving and image startup. Instead, launching an executable is a load-toplevel time IIRC.
16:34:34
compuphonic
pjb, in this case I can do stuff like cl_boot() in a provided function pointer member (.init) but that'll be a c function so it's no big deal
16:36:21
compuphonic
plugins exports a struct of that type on their symbol table which is loaded by Radare
16:38:20
compuphonic
jackdaniel, yeah I've seen that, but in this case I can't do it at runtime like usual since it has to be statically exported from the lib
20:43:18
compuphonic
well as it turns out it was less static than I thought. I can just use the init method to change the other pointers around and that should allow me to boot ECL and then ask for the pointer so I can set it. Though I wasn't able to get the original way to work. There doesn't seem to be a way to get the pointer to the function during the compilation phase and then export that address through a struct.