This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Dynamic Loading of classes in C++ without knowing their interface


rms suggested me to ask here about an idea I had to see what C++ users think
about it.

I haven't found a GPL library which lets the user load classes without knowing
their interface and through libdl it's possible to load them only if there is
the declaration of the class in the code. I've written a set of classes which
makes possible to load a class without having to know anything about it and then
add/remove/replace his methods and properties at runtime. I know that there are
some library which makes this possible in C, but the classes aren't compatible
with C++ ones. They don't have constructor/destructor and often miss inheritance
and to call their methods you must use a syntax like void *call(Object,
"method", parameters) which isn't very nice.

I've written this experiment and ended up with something working quite well on
g++-3.2 which has a quite robust runtime environment which makes possible to
call methods of a class with something that I find to be a nice way: ret_type
retv = object.method<ret_type>("method_name")(parameters), the user can just
call a method with the parameters, if the objects doesn't have that method or
the parameters are of wrong type it will throw a runtime_error exception. You
can also add/replace functions of a class without having to have the source code
and it's possible to change a part of the code that uses a new function of the
class without having to recompile the other (now if you add a method to a class
you must change his interface and so the .h which declares it and so you have to
recompile every cpp file which includes that .h)

I'm writing here to see what other C++ users think of it and to see if there is
someone else interested in helping with this project which is far from being
complete (I think that there are probably a few bugs that I've missed and there
are a lot of thing to tune).

I've written to rms to see if he tought it could be a good idea to make it a gnu
package because it' strictly related to libdl and g++ (things like templates
don't compile on some other platforms I've tested and there are some platforms
where the code doesn't work cause of the way they manage typeinfo data) and he
answered me to send a message here, so here it is.

Thank you for your time, and sorry for my bad english.
Alessandro Molina


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]