[xsd-users] polymorphism across dlls broken

Eric Niebler eric at boostpro.com
Thu Sep 18 12:57:38 EDT 2008


I'm evaluating XSD 3.1 for use in a project, and first let me say that 
I've been very impressed so far. Nice work.

I have run into a problem with the support for polymorphism in the 
presence of multiple dlls. (I'm using the C++/tree mapping.) In my use 
case, I have an application consisting of multiple dlls, each with its 
own XML schema. A complexType in one dll's schema may be an 
xsd:extension of a complexType in another dll's schema. XSD generates 
the correct C++ inheritance hierarchy in this case (and the correct 
header includes and dllexport/imports, etc.), but when trying to 
serialize these types to XML, I get xsd::cxx::tree::no_type_info<char> 
exception. When all the types are in the same executable, everything 
works fine.

The problem, as far as I can tell, seems to be the 
xsd::cxx::tree::type_serializer_map_instance() function in 
type-serializer-map.hxx. It looks like this:

       template<unsigned long id, typename C>
       inline type_serializer_map<C>&
       type_serializer_map_instance ()
       {
         return *type_serializer_plate<id, C>::map;
       }

... where type_serializer_plate looks like ...

       template<unsigned long id, typename C>
       struct type_serializer_plate
       {
         static type_serializer_map<C>* map;
         /* ... */
       };

This is clearly not going to work in the presence of multiple dlls. Each 
dll will get its own type_serializer_map, in which the types that live 
in that dll -- and only those types -- are registered. Attempts to look 
up types from other dlls will fail, and the 
type_serializer_map::serialize() function will throw a no_type_info 
exception.

Is this a known problem? I can build a simple repro of the problem if 
that's necessary. The solution, it seems, would be to move the 
definition of the type_serializer_map object into a separate dll, so 
that all dlls can share the instance. Or something clever where each 
type_serializer_map::type_info object holds a pointer back to the 
type_serializer_map instance with which it's registered, so that type 
look-ups can chase pointers into the type_serializer_maps of other dlls.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com




More information about the xsd-users mailing list