Re: Extending XML::LibXML through XS

Petr Pajas <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Organization UFAL MFF UK
Message-ID <[email protected]>
On Sunday 30 November 2008 09:28:39 Emmanuel Rodriguez wrote:
> On Sat, Nov 29, 2008 at 11:30 PM, Petr Pajas <[email protected]> wrote:
> > Hi Emmanuel,
>
> Hi Petr,
>
> Thanks for the pointers!
>
> > PmmSvNode(node) is a macro defined in XML::LibXML's libxml-perl-mm.h that
> > expands to a function call PmmSvNodeExt(node,1) whose prototype is
> >
> > xmlNodePtr PmmSvNodeExt(SV* node, int copy);
>
> I tried this but then I get the following error at runtime:
> symbol lookup error: Xacobeo/XS/XS.so: undefined symbol: PmmSvNodeExt
>
> I managed to get around this error by linking Xacobeo/XS/XS.so with
> /usr/lib/perl5/auto/XML/LibXML/LibXML.so. I'm not too crazy about
> linking to LibXML.so as I will need to detect where the .so is.
>
> > Try adding just this prototype and either defining the macro or rewriting
> > the typemap to use the direct function call. Hopefully the dynamical
> > linker will be able to locate the symbol in XML/LibXML.so loaded with
> > XML::LibXML. If not, you'll have to copy-paste the function from
> > perl-libxml-mm.c.
>
> I tried to copy  perl-libxml-mm.c and perl-libxml-sax.c (it's needed
> by perl-libxml-mm.c) but I still have problem at runtime:
> undefined symbol: PROXY_NODE_REGISTRY_MUTEX
>
> I've checked and this mutex is declared in LibXML.c. I tried to link
> again with LibXML/LibXML.so but the error persists. The only way I
> found out to remove the error is to declare  PROXY_NODE_REGISTRY_MUTEX
> in xs file. I'm not sure that this is a great idea as the mutex seems
> to be used for thread synchronization and this will create two
> different mutexes.

Emmanuel,
definitelly don't do that. If you must, XML::LibXML has a function that 
returns a pointer to the mutex (see how this is done in XML::LibXSLT). But 
this copying full perl-libxml-mm.c is much overhead and I can't even 
guarantee neither backward nor forward binary compatibility for all the code.

> I think that I have no choice but to use the first alternative: to
> declare the prototypes of PmmSvNode and PmmSvNodeExt and to link with
> XML/LibXML/LibXML.so

Either that or, since you just need this function, copy/paste only this 
function (and a few macros used by it) from perl-libxml-mm.c should work as 
well; PmmSvNodeExt does not do much, you may even simplify the code to 
something like this (and maybe use it directly in your typemap):

struct _ProxyNode {
    xmlNodePtr node;
    xmlNodePtr owner;
    int count;
    int encoding;
};
typedef struct _ProxyNode ProxyNode;
typedef ProxyNode* ProxyNodePtr;

PmmSvNodeSimple( SV* perlnode )
{
  ProxyNodePtr proxy = NULL;
  if ( perlnode != NULL && perlnode != &PL_sv_undef &&
       sv_derived_from(perlnode, "XML::LibXML::Node")  ) {
    proxy = INT2PTR(ProxyNodePtr,SvIV(SvRV(perlnode)));
    if ( proxy != NULL ) return proxy->node;
  }
  return NULL;
}

Best,
-- Petr
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.