You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Colin Robertson <Co...@bbc.co.uk> on 2005/02/09 13:48:25 UTC

INIT blocks again

I've just got round to looking at the INIT block issue properly and I've
found a couple of alternative techniques. (Though I see now why you used
the INIT block in the first place. Given the way SWIG works it is tricky
finding a good insertion point.)

First though, the things that don't work: A BEGIN block doesn't work
because that gets executed as soon as the compiler sees it. Compilation
hasn't finished at that point, so it can't call things that are defined
in that module. The other obvious approach is to not put the Initialize
call inside any block at all but to just put it in the definition of
XML::Xerces and have it executed as the last stage of compiling the
module. But that fails because XML::Xerces::XMLPlatformUtils::Initialize
is actually a mapping to XML::Xercesc::XMLPlatformUtils_Initialize which
is set up inside XML::Xerces::XMLPlatformUtils.

So, the solutions: The more pleasant of the two possibilities is to
insert the Initialize call inside XMLPlatformUtils somewhere after the
long series of name mappings. That might be possible with SWIG, I don't
know. (I've never used SWIG. It wasn't obvious from the documentation
how to insert arbitrary code at that point.)

The slightly less pleasant solution is to put a call to
XML::Xercesc::XMLPlatformUtils_Initialize at the top of Xerces-extra.pm
(roughly where the INIT block is now). It's a little bit ugly to use
that name directly, but at that point in the code it's the only name
available.

How do either of those options sound? Let me know if I haven't explained
myself clearly.

colin

http://www.bbc.co.uk/

This e-mail (and any attachments) is confidential and may contain
personal views which are not the views of the BBC unless specifically
stated.
If you have received it in error, please delete it from your system. 
Do not use, copy or disclose the information in any way nor act in
reliance on it and notify the sender immediately. Please note that the
BBC monitors e-mails sent or received. 
Further communication will signify your consent to this.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: INIT blocks again

Posted by "Lincoln A. Baxter" <la...@lincolnbaxter.com>.
On Thu, 2005-02-10 at 09:07 +0530, Jason E. Stewart wrote:
> > On Wed, 2005-02-09 at 12:48 +0000, Colin Robertson wrote:
> >
> >> So, the solutions: The more pleasant of the two possibilities is to
> >> insert the Initialize call inside XMLPlatformUtils somewhere after the
> >> long series of name mappings. That might be possible with SWIG, I don't
> >> know. (I've never used SWIG. It wasn't obvious from the documentation
> >> how to insert arbitrary code at that point.)
> >> 
> >> The slightly less pleasant solution is to put a call to
> >> XML::Xercesc::XMLPlatformUtils_Initialize at the top of Xerces-extra.pm
> >> (roughly where the INIT block is now). It's a little bit ugly to use
> >> that name directly, but at that point in the code it's the only name
> >> available.
> 
> "Lincoln A. Baxter" <la...@lincolnbaxter.com> writes:
> 
> > This sounds ugly... Might it be simpler, to just require the user to
> > call a package global initialization function... such as
> > XML::Xerces::Initialize(), which could internally protected from
> > multiply invocations?
> 
> It would be possible to require users to use Initialize() and
> Terminate() themselves but it would be a sudden change from the way
> things are currently done. 
> 
> BTW. Xerces-C now protects against multiple calls to both functions,
> so we wouldn't need to.
> 

Yea, but... it is also painful for users to have to constantly go
looking for down rev versions of Xerces-C sources and libraries, to get
it work. Since that is the case... a big notice in a new version, would
allow you to make that change.   Its probably not worth it, however
unless it makes it easier to build new versions, when Xerces-C gets
updated.

Just a thought.

Lincoln


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: INIT blocks again

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
> On Wed, 2005-02-09 at 12:48 +0000, Colin Robertson wrote:
>
>> So, the solutions: The more pleasant of the two possibilities is to
>> insert the Initialize call inside XMLPlatformUtils somewhere after the
>> long series of name mappings. That might be possible with SWIG, I don't
>> know. (I've never used SWIG. It wasn't obvious from the documentation
>> how to insert arbitrary code at that point.)
>> 
>> The slightly less pleasant solution is to put a call to
>> XML::Xercesc::XMLPlatformUtils_Initialize at the top of Xerces-extra.pm
>> (roughly where the INIT block is now). It's a little bit ugly to use
>> that name directly, but at that point in the code it's the only name
>> available.

"Lincoln A. Baxter" <la...@lincolnbaxter.com> writes:

> This sounds ugly... Might it be simpler, to just require the user to
> call a package global initialization function... such as
> XML::Xerces::Initialize(), which could internally protected from
> multiply invocations?

Hey Colin,

Thanks for taking the time to look into this. It was so long ago that
I decided to put the Intialize() into the INIT block that I had
forgotten the details.

Actually the simplest solution by far would be to place it in
Xerces-extra.pm - that file is a bunch of Perl-specific code that SWIG
places verbatim into Xerces.pm whenever the module is rebuilt by SWIG,
pehaps it is unaesthetic, but it would be much simpler to maintain.

It would be possible to require users to use Initialize() and
Terminate() themselves but it would be a sudden change from the way
things are currently done. 

BTW. Xerces-C now protects against multiple calls to both functions,
so we wouldn't need to.

What do people feel?

Cheers,
jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org


Re: INIT blocks again

Posted by "Lincoln A. Baxter" <la...@lincolnbaxter.com>.
This sounds ugly... Might it be simpler, to just require the user to
call a package global initialization function... such as
XML::Xerces::Initialize(), which could internally protected from
multiply invocations?

On Wed, 2005-02-09 at 12:48 +0000, Colin Robertson wrote:
> I've just got round to looking at the INIT block issue properly and I've
> found a couple of alternative techniques. (Though I see now why you used
> the INIT block in the first place. Given the way SWIG works it is tricky
> finding a good insertion point.)
> 
> First though, the things that don't work: A BEGIN block doesn't work
> because that gets executed as soon as the compiler sees it. Compilation
> hasn't finished at that point, so it can't call things that are defined
> in that module. The other obvious approach is to not put the Initialize
> call inside any block at all but to just put it in the definition of
> XML::Xerces and have it executed as the last stage of compiling the
> module. But that fails because XML::Xerces::XMLPlatformUtils::Initialize
> is actually a mapping to XML::Xercesc::XMLPlatformUtils_Initialize which
> is set up inside XML::Xerces::XMLPlatformUtils.
> 
> So, the solutions: The more pleasant of the two possibilities is to
> insert the Initialize call inside XMLPlatformUtils somewhere after the
> long series of name mappings. That might be possible with SWIG, I don't
> know. (I've never used SWIG. It wasn't obvious from the documentation
> how to insert arbitrary code at that point.)
> 
> The slightly less pleasant solution is to put a call to
> XML::Xercesc::XMLPlatformUtils_Initialize at the top of Xerces-extra.pm
> (roughly where the INIT block is now). It's a little bit ugly to use
> that name directly, but at that point in the code it's the only name
> available.
> 
> How do either of those options sound? Let me know if I haven't explained
> myself clearly.
> 
> colin
> 
> http://www.bbc.co.uk/
> 
> This e-mail (and any attachments) is confidential and may contain
> personal views which are not the views of the BBC unless specifically
> stated.
> If you have received it in error, please delete it from your system. 
> Do not use, copy or disclose the information in any way nor act in
> reliance on it and notify the sender immediately. Please note that the
> BBC monitors e-mails sent or received. 
> Further communication will signify your consent to this.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-p-dev-help@xml.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-p-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-p-dev-help@xml.apache.org