29 Sep 2003 jdybnis   » (Apprentice)

mwh: I share your irritation with C. There is no standard way of discovering the type of a library function at runtime. What is even more irritating to me is that even if you do somehow discover the type of a function at runtime (say by parsing the headers, or the debug information), I know of no way to construct a call to the function. Meaning that even if you've got the address of a function, and you know what type of arguments it expects, there is no way to call it, unless you've got a precompiled stub function of exactly that type. But you don't have that of course, because you only just discovered the function's type at runtime. But GDB can do it, so it's not impossible, it probably just involves some low-level non-portable work. One thing on my todo list for a while has been to break this functionality out of GDB into a nice little library. Anybody writing an interpreted language could use this to allow calls into precompiled C libraries, and leverage the porting work that GDB has done to all the platforms it supports. But it's a pretty low priority for me because I don't have much use for a GPL'ed library right now.

Update: via email, Pierre points me to libffi. It does pretty much what's described above. It lives in the gcc source tree, but its license is less restrictive than the GPL. Free software rocks!

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!