Infinite recursion in generated code. (was: Re: [xsd-users] For <xs:restriction base="xs:anyType"> generated code does not compile.)

Jeroen N. Witmond [Bahco] jnw at xs4all.nl
Fri Nov 16 16:35:41 EST 2007


Hi Boris,

Boris Kolpackov writes:
> Hi Jeroen,
>
> Sorry for replying so late.

Don't worry about that. I have no deadlines regarding xsd. :)

> Jeroen N. Witmond [Bahco] <jnw at xs4all.nl> writes:
>
>> When I try to generate code for a Schema containing
>> <xs:restriction base="xs:anyType">
>> (my guess for the problem) it does not compile. The Schema file and
>> Makefile attached demonstrate the problem.
>
> You get this error because you use the --generate-xml-schema and
> --extern-xml-schema options but do not compile the XmlSchema.hxx
> header with --generate-ostream. This leads to a header file with
> operator<<'s for built-in types not being included.

Alright. But now I have come across the next stumbling block, and it is a
strange one.

When I add the custom type for anyType (for the xml:base attribute, from
item 4, custom-intended, on
http://www.xs4all.nl/~jnw/codesynthesis/xmlnamespace/index.html ) to the
translation of XmlSchema, and add a simple driver program, it enters an
infinite recursion starting at

    std::auto_ptr<metadox::problem>
      foo(metadox::problem_(argv1,
                            xml_schema::flags::keep_dom |
                            xml_schema::flags::dont_initialize));

At the start of the recursion, the backtrace is

#0  simple_type (this=0xafdfea9c, a=@0x8063908, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
0}, c=0x0) at
/home/bahco/Sandbox/xsd-3.1.0.a1-i686-linux-gnu/libxsd/xsd/cxx/tree/parsing.txx:81

#1  0x08052033 in simple_type (this=0x805b2a0, a=@0x8063908, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
769}, c=0x8077010) at
/home/bahco/Sandbox/xsd-3.1.0.a1-i686-linux-gnu/libxsd/xsd/cxx/tree/parsing.txx:82

#2  0x080521ad in uri (this=0x805b2a0, a=@0x8063908, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
769}, c=0x8077010) at
/home/bahco/Sandbox/xsd-3.1.0.a1-i686-linux-gnu/libxsd/xsd/cxx/tree/parsing.txx:705

#3  0x0805227a in xsd::cxx::tree::traits<xsd::cxx::tree::uri<wchar_t,
xsd::cxx::tree::simple_type<xml_schema::XmlNamespace> >, wchar_t>::create
(
    a=@0x8063908, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
769}, container=0x8077010) at
/home/bahco/Sandbox/xsd-3.1.0.a1-i686-linux-gnu/libxsd/xsd/cxx/tree/elements.hxx:717

#4  0x0804b06d in metadox::problem::parse (this=0x8077010, p=@0xafdfebd0, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
769}) at restrict-base-anytype.cxx:131

#5  0x0804b3ac in problem (this=0x8077010, e=@0x8063480, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
769}, c=0x0) at restrict-base-anytype.cxx:114

#6  0x0805232c in xsd::cxx::tree::traits<metadox::problem,
wchar_t>::create (e=@0x8063480, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
769}, container=0x0) at
/home/bahco/Sandbox/xsd-3.1.0.a1-i686-linux-gnu/libxsd/xsd/cxx/tree/elements.hxx:711

#7  0x0804b548 in metadox::problem_ (d=0x8062d50, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
769}) at restrict-base-anytype.cxx:458

#8  0x0804c9ee in metadox::problem_ (u=@0xafdfed60, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
257}, p=@0xafdfed6c) at restrict-base-anytype.cxx:192

#9  0x0804aa98 in main (argc=2, argv=0xafdfee14) at driver.cpp:53

When the recursion causes a SIGSEGV, the backtrace is nothing but

#n  0x08051f9b in simple_type (this=0xaf60009c, a=@0x8063908, f=
      {static keep_dom = 256, static own_dom = 512, static dont_validate =
<optimized out>, static dont_initialize = 1, static
no_xml_declaration = <optimized out>, static base = 16777216, x_ =
0}, c=0x0) at
/home/bahco/Sandbox/xsd-3.1.0.a1-i686-linux-gnu/libxsd/xsd/cxx/tree/parsing.txx:82

for a very long time.

The strange thing is that the recursion appears only when I use the custom
anyType, and yet the backtrace above does not pass through code in any way
related to that custom type. And apart from the main program, it passes
only through generated code.

>From parsing.txx (version 3.1.0.a1):

      template <typename B>
      inline simple_type<B>::
      simple_type (const xercesc::DOMAttr& a, flags f, type* c)
          : B (a, f, c)                                      // line 82
      {
      }

Shouldn't the g++ compiler complain when this evaluates to a recursive
initialization? Or is the compiler generating incorrect code for this
case? Or am I completely out of my scope? :)

If you want the source files to recreate this problem, let me know and
I'll send them off the list.

Jeroen.






More information about the xsd-users mailing list