[Expat-bugs] [ expat-Bugs-651754 ] Function to get XML_Memory_Handling_Suite

SourceForge.net noreply at sourceforge.net
Thu Jan 16 14:15:29 EST 2003


Bugs item #651754, was opened at 2002-12-10 20:16
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=110127&aid=651754&group_id=10127

Category: None
Group: Feature Request
Status: Open
>Resolution: Fixed
Priority: 5
Submitted By: Artyom Bolgar (artyom17)
Assigned to: Nobody/Anonymous (nobody)
Summary: Function to get XML_Memory_Handling_Suite

Initial Comment:
It is not a bug report, it is a feature request. What do 
you think of adding the function, that returns the pointer 
to XML_Memory_Handling_Suite for passed 
XML_Parser? It is necessary for me, I am developing an 
extension for Expat and I would like to use the same 
allocation/reallocation/free function as the current 
XML_Parser uses. Since XML_Parser struct defined 
inside .C-file, I can't get an access to 
XML_Memory_Handling_Suite struct for the parser. 
Please add this function, since it will be very simple.

Sincerely,
 Artyom Bolgar.

----------------------------------------------------------------------

>Comment By: Karl Waclawek (kwaclaw)
Date: 2003-01-16 17:15

Message:
Logged In: YES 
user_id=290026

Applied a patch with two solutions:

1) Added XML_FreeContentModel API
2) Exposed all three memory handling functions as
   XML_MemMalloc, XML_MemRealloc, XML_MemFree

Check out xmlparse.c rev. 1.102 and expat.h rev. 1.50

----------------------------------------------------------------------

Comment By: Karl Waclawek (kwaclaw)
Date: 2002-12-11 16:38

Message:
Logged In: YES 
user_id=290026

Artyom,

I think I understand now.
>From a proper design perspective your use case should
not involve Expat. This is a matter between your code
and the user's application. It should provide you with
the necessary information to use it properly.

However, I still think that there is a reason
for having an API like the one you suggested:

There is one use case where the application has to
free memory allocated by the parser (in the  element 
declaration handler).  If Expat is not accessed from 
C/C++,  then there may not be a way to do so
from languages that can access Dlls, but have different
memory allocation implementations.

In my case, I am lucky that Delphi's memory manager
is basically identical to C/C++, so I can create the
parser with the Delphi memory management functions.

However, I would have preferred if there was an API like 
you suggested, or at least a function to free the content 
model passed to the element declaration handler.

----------------------------------------------------------------------

Comment By: Artyom Bolgar (artyom17)
Date: 2002-12-11 16:22

Message:
Logged In: YES 
user_id=657326

Karl,
Why user overloads memory allocation functions? Because 
he don't want to use malloc/realloc/free for some reasons, for 
example performance or compatibility (some embedded 
platforms do not support malloc/realloc/free functions). As far 
as I develops the extension of Expat and it will be linked 
together with Expat library I want to use the same memory 
functions as are used by parser.

----------------------------------------------------------------------

Comment By: Karl Waclawek (kwaclaw)
Date: 2002-12-11 15:18

Message:
Logged In: YES 
user_id=290026

Artyom:
I am still not clear what you mean with overloading.
I don't think you need the same memory handler 
functions as Expat as long as you don't have to free
memory that Expat allocates.

----------------------------------------------------------------------

Comment By: Artyom Bolgar (artyom17)
Date: 2002-12-11 15:14

Message:
Logged In: YES 
user_id=657326

I am developing an extension to Expat API that provides 
ability of parsing from any source, from file, network, etc. Of 
course, I have to make some memory allocations. For 
example, the function name EXML_CreateFileInputSource 
(XML_Parser, const char* filename). I don't know how 
XML_Parser was created, with mem suite or without. But I 
need to use the same memory functions as parser uses, 
because user might overload them.

----------------------------------------------------------------------

Comment By: Karl Waclawek (kwaclaw)
Date: 2002-12-11 14:40

Message:
Logged In: YES 
user_id=290026

Attached is a potential patch MemSuite.diff.
Includes changes to expat.h, xmlparse.c
and the DEF files for Windows builds.

This is just a suggestion.
For the content model example all one would need,
however, is a FreeContentModel API.


----------------------------------------------------------------------

Comment By: Karl Waclawek (kwaclaw)
Date: 2002-12-11 10:23

Message:
Logged In: YES 
user_id=290026

Fred:
I know that, but I just pointed out an example
where it would make sense.

I have another reason too that has to do with
writing wrappers/bindings for Expat, but I will
mention it in a reply to your upcoming message
on expat-discuss.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-12-11 09:38

Message:
Logged In: YES 
user_id=3066

Karl:  Artyom didn't say he was setting a handler on an
XML_Parser object someone else passed him, nor did he say he
wasn't.  The only specific I see here is that he wants to
use the same resource handlers as the parser; it's not clear
that this is a real requirement.  I'll follow up with a
discussion on expat-discuss.

----------------------------------------------------------------------

Comment By: Karl Waclawek (kwaclaw)
Date: 2002-12-11 08:59

Message:
Logged In: YES 
user_id=290026

Once you set an element declaration handler you need
to free the content model passed to the handler, so
you will need to know the memory handler in use.

It is just a rare case that the code that sets the handlers
has no control over the code that creates the parser.
But it is not too far fetched, so IMO that feature
request makes some sense, unless I am overlooking
the obvious.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-12-11 07:40

Message:
Logged In: YES 
user_id=3066

Can you explain why you need the memory handler they've
asked Expat to use?  The requirements aren't clear, so more
explanation of the use case should help.

Thanks.

----------------------------------------------------------------------

Comment By: Artyom Bolgar (artyom17)
Date: 2002-12-11 06:32

Message:
Logged In: YES 
user_id=657326

Of course, I know about this. But in my case, I use 
XML_Parser passed by user (and it is created by him), and I 
don't know how it was created, either by 
XML_ParserCreate_MM or not. That is why I requested this 
function.

----------------------------------------------------------------------

Comment By: Karl Waclawek (kwaclaw)
Date: 2002-12-10 21:24

Message:
Logged In: YES 
user_id=290026

Are you creating the parser using XML_ParserCreate?
In that case - without supplying an external memory handler,
Expat just uses the standard C runtime functions
malloc, realloc and free.

If you use XML_ParserCreate_MM however, then *you*
are supplying the memory handler yourself.

In both cases you don't need the requested function.

Is your situation different from what I described?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=110127&aid=651754&group_id=10127



More information about the Expat-bugs mailing list