Access violation exception when reading/writing xml formats

8 messages Options
Embed this post
Permalink
Matt Sprague

Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
I was working on  the next release of OBDotNet when I discovered that read or writing any xml format triggers an access violation exception. After debugging into the C++ code I was able to identify the call to xmlFreeTextReader as the source of the exception. I've spent the last 3 days trying to figure out a work around but I'm stumped. Any thoughts?

-Matt

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
Noel O'Boyle

Re: Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
Are you working off the svn 22x branch?

2009/11/4 Matt Sprague <[hidden email]>:

> I was working on  the next release of OBDotNet when I discovered that read
> or writing any xml format triggers an access violation exception. After
> debugging into the C++ code I was able to identify the call to
> xmlFreeTextReader as the source of the exception. I've spent the last 3 days
> trying to figure out a work around but I'm stumped. Any thoughts?
>
> -Matt
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> OpenBabel-scripting mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
>
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
Noel O'Boyle

Re: Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
2009/11/4 Matt Sprague <[hidden email]>:
> On Wed, Nov 4, 2009 at 7:11 AM, Noel O'Boyle <[hidden email]> wrote:
> Are you working off the svn 22x branch?
>
> Yes, is there a another branch I should switch to?

No - that's fine. Just checking.

> Also, just to clarify,
> this is only a problem in with the bindings it works fine in C++.

Ok - that's useful to know.

That's pretty weird though. The XML formats are always problematic
though as everything goes through libxml and it seems to be a bit
messy. Could it be that it is picking up on the wrong libxml2 or
whatever? Or that there is some conflict there? Chris is the resident
expert on all things XML/Windows, but if it cannot be reproduced in
C++ it'll be next to impossible for him to debug.

I have a mixture of different OBs on my computer so I can't easily
check whether XML read/writing works from Python, but I will do so as
soon as possible.

- Noel

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
Chris Morley

Re: Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
In reply to this post by Matt Sprague
Matt Sprague wrote:
> I was working on  the next release of OBDotNet when I discovered that
> read or writing any xml format triggers an access violation exception.
> After debugging into the C++ code I was able to identify the call to
> xmlFreeTextReader as the source of the exception. I've spent the last 3
> days trying to figure out a work around but I'm stumped. Any thoughts?

I find libxml2 difficult and cumbersome to work with. Its interface is
  C, not a C++, in style and sometimes, but not always, you have to
delete the memory used by strings it has given you and other objects.
I have to confess I never really sorted this out properly and the code
was left working in C++ but possibly with memory leaks. I'm sorry if
it has turned out to be more than this and has wasted your time.

I'll try to look at it again, but, in the meantime, it looks as if it
could benefit addition of the second line here

xmlFreeTextReader(_reader);
_reader = NULL;

This would ensure it wasn't deleted twice, which might be the
immediate cause of the error.

Chris



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
Matt Sprague

Re: Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
In reply to this post by Noel O'Boyle
Noel, did you ever get a chance to check whether or not this exception happens in the python bindings? I downloaded the libxml2 source and built the dll with MinGW using the posix threading library (pthreadgc2.dll) and that seems to work fine on my machine. Maybe be it's a bug in the VC runtime?

-Matt


On Thu, Nov 5, 2009 at 4:41 AM, Noel O'Boyle <[hidden email]> wrote:
2009/11/4 Matt Sprague <[hidden email]>:
> On Wed, Nov 4, 2009 at 7:11 AM, Noel O'Boyle <[hidden email]> wrote:
> Are you working off the svn 22x branch?
>
> Yes, is there a another branch I should switch to?

No - that's fine. Just checking.

> Also, just to clarify,
> this is only a problem in with the bindings it works fine in C++.

Ok - that's useful to know.

That's pretty weird though. The XML formats are always problematic
though as everything goes through libxml and it seems to be a bit
messy. Could it be that it is picking up on the wrong libxml2 or
whatever? Or that there is some conflict there? Chris is the resident
expert on all things XML/Windows, but if it cannot be reproduced in
C++ it'll be next to impossible for him to debug.

I have a mixture of different OBs on my computer so I can't easily
check whether XML read/writing works from Python, but I will do so as
soon as possible.

- Noel


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
Noel O'Boyle

Re: Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
No I didn't. I saw that Geoff had attempted to fix this issue so I was
waiting to hear from you:
http://openbabel.svn.sourceforge.net/viewvc/openbabel?view=rev&revision=3455

This is on the trunk, but presumably you could cut 'n' paste onto the branch.

If you can check this out, I'll follow up with python.

- Noel

2009/11/30 Matt Sprague <[hidden email]>:

> Noel, did you ever get a chance to check whether or not this exception
> happens in the python bindings? I downloaded the libxml2 source and built
> the dll with MinGW using the posix threading library (pthreadgc2.dll) and
> that seems to work fine on my machine. Maybe be it's a bug in the VC
> runtime?
>
> -Matt
>
>
> On Thu, Nov 5, 2009 at 4:41 AM, Noel O'Boyle <[hidden email]> wrote:
>>
>> 2009/11/4 Matt Sprague <[hidden email]>:
>> > On Wed, Nov 4, 2009 at 7:11 AM, Noel O'Boyle <[hidden email]>
>> > wrote:
>> > Are you working off the svn 22x branch?
>> >
>> > Yes, is there a another branch I should switch to?
>>
>> No - that's fine. Just checking.
>>
>> > Also, just to clarify,
>> > this is only a problem in with the bindings it works fine in C++.
>>
>> Ok - that's useful to know.
>>
>> That's pretty weird though. The XML formats are always problematic
>> though as everything goes through libxml and it seems to be a bit
>> messy. Could it be that it is picking up on the wrong libxml2 or
>> whatever? Or that there is some conflict there? Chris is the resident
>> expert on all things XML/Windows, but if it cannot be reproduced in
>> C++ it'll be next to impossible for him to debug.
>>
>> I have a mixture of different OBs on my computer so I can't easily
>> check whether XML read/writing works from Python, but I will do so as
>> soon as possible.
>>
>> - Noel
>
>

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
Matt Sprague

Re: Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
Nope, that didn't help. The program is crashing inside of the the call to xmlFreeTextReader. You can view the source here:

Whatever is happening occurs between the beginning of the function (line 2177)
and the call to xmlFreeParserInputBuffer(input) (line 2245). I thought I was closing in on the problem, but the version of libxml2 I built with MinGW works just fine. So now I'm really puzzled. 


-Matt




------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting
Noel O'Boyle

Re: Access violation exception when reading/writing xml formats

Reply Threaded More More options
Print post
Permalink
Seems to work fine from Python. Using OpenBabel on the trunk, I have:

>>> mol = pybel.readstring("smi", "CC(=O)Cl")
>>> print mol.write("cml")
<molecule>
 <atomArray>
  <atom id="a1" elementType="C"/>
  <atom id="a2" elementType="C"/>
  <atom id="a3" elementType="O"/>
  <atom id="a4" elementType="Cl"/>
 </atomArray>
 <bondArray>
  <bond atomRefs2="a1 a2" order="1"/>
  <bond atomRefs2="a2 a3" order="2"/>
  <bond atomRefs2="a2 a4" order="1"/>
 </bondArray>
</molecule>

>>>

I am using the libxml2.dll that comes with OpenBabel 2.2.3, which I
can test with Cygwin's "which" as follows:
C:\> which libxml2.dll
/cygdrive/c/Program Files/OpenBabel-2.2.3/libxml2.dll

I haven't done any work enabling other scripting languages on the
trunk, so I can't easily test whether it works from C# there...

- Noel

2009/12/1 Matt Sprague <[hidden email]>:

> Nope, that didn't help. The program is crashing inside of the the call
> to xmlFreeTextReader. You can view the source here:
> http://svn.gnome.org/viewvc/libxml2/trunk/xmlreader.c?revision=3795&view=markup
> Whatever is happening occurs between the beginning of the function (line
> 2177)
> and the call to xmlFreeParserInputBuffer(input) (line 2245). I thought I was
> closing in on the problem, but the version of libxml2 I built with MinGW
> works just fine. So now I'm really puzzled.
>
> -Matt
>
>
>

------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing.
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
OpenBabel-scripting mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-scripting