[Mono-devel-list] Embedding API changes

Paolo Molaro lupus at ximian.com
Sat Jun 19 13:47:49 EDT 2004

The last few days I cleaned up the headers and the interfaces used
to embed Mono in C applications.
The short term result is that basically all the non trivial
applications will not compile anymore. The good news is that,
once updated, the apps will be source and binary compatible
for the versions of mono that will follow this year and the next.
This will allow us to change some implementation details and lower
the memory usage of some data structures, for example, without 
breaking binary or source compatibility.

Most of the data structures are no more directly accessible, but
you'll need to use function accessors to get at the fields.
Examples include (with their replacement):

	method->name 		mono_method_get_name (method)
	method->signature	mono_method_get_signature (method)
	klass->name 		mono_class_get_name (method)
	klass->image		mono_class_get_image (method)

etc. You got the idea, it's a pretty straightforward change.
Slightly different are the changes required to iterate over
methods in a class or other metadata elements like that. The old code 
looked like:

	for (i = 0; i < klass->method.count; ++i) {
		// use klass->methods [i]

This kind of code will now make use of iterators. An iterator is a
simple gpointer data, initialized to NULL to start at the beginning,
so the code becomes:

	gpointer iter = NULL;
	while ((method = mono_class_get_methods (klass, &iter))) {
		// use method

Note: I haven't yet changed the headers to hide also the structures
MonoType and MonoMethodSignature, but I added already the accessors that
are needed so the code can be changed to not access the structures
directly: please start changing to the new code as those strcutures
will only be available as typedeffed symbols in a few days.

Another data structure that used to be accessed directly was
mono_defaults, to get a MonoClass for some often used classes in corlib:
the code changes in this case are trival:

	mono_defaults.corlib       -> mono_get_corlib ()
	mono_defaults.object_class -> mono_get_object_class ()
	mono_defaults.byte_class   -> mono_get_byte_class ()

I may have missed a few needed accessors or helper methods that could be
useful for embedders: feel free to mail to the list or file bug reports,
so that I can add them before the mono 1.0 release.
People may also want to take a look at the new test in
mono/sameples/embed/test-metadata.c, where simple uses of the new API 
is showed.



lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better

More information about the Mono-devel-list mailing list