Hi,

  http://search.cpan.org/src/BJOERN/SGML-Parser-OpenSP-0.02/OpenSP.xs
is a C++ XS extension. I am trying to figure out what is needed, if
anything, to make it play nicely in the context of multiple threads.
Do I understand correctly from perlguts that nothing is actually needed?

Then perlguts lists two other way of making this more efficient, the
most efficient way is supposed to be using the pTHX_ macro, do I under-
stand correctly that my extension generally cannot use it as most of the
methods of the main object are actually callbacks called by external
code which won't pass the required parameters?

Then, the middle way would be to define PERL_NO_GET_CONTEXT prior to
including the Perl headers and then call dTHX from all functions and
methods that use the Perl API, right? Then, are there any requirements
for when dTHX should be called (other than before actually using the
API) like, for example, before or after dSP? I guess dSP counts as
using the API so dTHX would have to precede it.

Can I use the two more efficient way in combination? For example, there
is the heavily used _cs2sv function which converts a custom string re-
presentation to a proper UTF-8 SV*, and the sdata method which is called
from external code, currently

  void SgmlParserOpenSP::sdata(const SdataEvent& e)
  {
    if (!handler_can("sdata"))
      return;
  
    updatePosition(e.pos);
  
    HV* hv = newHV();
  
    hv_store(hv, "EntityName", 10, _cs2sv(e.entityName), HvvEntityName);
    hv_store(hv, "Text", 4, _cs2sv(e.text), HvvText);
  
    dispatchEvent("sdata", hv);
  }

Can I change this to

  ...
  SV* _cs2sv(pTHX_ const SGMLApplication::CharString s)
  ...
  void SgmlParserOpenSP::sdata(const SdataEvent& e)
  {
    dTHX;
    ...
    hv_store(hv, "EntityName", 10, _cs2sv(aTHX_ e.entityName), ...);
    hv_store(hv, "Text", 4, _cs2sv(aTHX_ e.text), ...);
    ...
  }

or are these methods mutually exclusive? Is there anything special to
consider for C++ extensions as opposed to C extensions?

Assuming nothing actually needs to be done to support such usage, are
there any rules to estimate what could be gained from using one of the
more efficient methods in my extension? perlguts only states it is more
efficient but that could mean anything from totally insignificant to my
extension would be unusable if not optimized in this regard. Are there
rules to determine which functions would gain most from optimizations
in this regard?

TIA.

Reply via email to