Update of /cvsroot/perl-xml/XML-LibXML-XPathContext
In directory sc8-pr-cvs1:/tmp/cvs-serv27841
Modified Files:
XPathContext.xs XPathContext.pm
Log Message:
implement context locking by adding _enter and _leave
Index: XPathContext.xs
===================================================================
RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.xs,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- XPathContext.xs 20 Mar 2003 13:25:19 -0000 1.12
+++ XPathContext.xs 20 Mar 2003 13:55:25 -0000 1.13
@@ -490,7 +490,7 @@
SvREFCNT_dec(XPathContextDATA(ctxt)->node);
}
if (XPathContextDATA(ctxt)->pool != NULL) {
- SvREFCNT_dec(XPathContextDATA(ctxt)->pool);
+ SvREFCNT_dec((SV *)XPathContextDATA(ctxt)->pool);
}
Safefree(XPathContextDATA(ctxt));
}
@@ -685,6 +685,38 @@
} else {
/* warn("Registering function '%s'\n", name); */
xmlXPathRegisterFunc(ctxt, name, LibXML_generic_extension_function);
+ }
+
+void
+_enter( pxpath_context )
+ SV * pxpath_context
+ PREINIT:
+ xmlXPathContextPtr ctxt = NULL;
+ INIT:
+ ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context));
+ if ( ctxt == NULL ) {
+ croak( "XPathContext: missing xpath context" );
+ }
+ PPCODE:
+ if ( XPathContextDATA(ctxt)->lock != 0 ) {
+ croak( "XPathContext: context is locked" );
+ }
+ XPathContextDATA(ctxt)->lock=1;
+
+void
+_leave( pxpath_context )
+ SV * pxpath_context
+ PREINIT:
+ xmlXPathContextPtr ctxt = NULL;
+ INIT:
+ ctxt = (xmlXPathContextPtr)SvIV(SvRV(pxpath_context));
+ if ( ctxt == NULL ) {
+ croak( "missing xpath context" );
+ }
+ PPCODE:
+ XPathContextDATA(ctxt)->lock=0;
+ if (XPathContextDATA(ctxt)->pool != NULL) {
+ SvREFCNT_dec((SV *)XPathContextDATA(ctxt)->pool);
}
void
Index: XPathContext.pm
===================================================================
RCS file: /cvsroot/perl-xml/XML-LibXML-XPathContext/XPathContext.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- XPathContext.pm 16 Mar 2003 16:21:29 -0000 1.5
+++ XPathContext.pm 20 Mar 2003 13:55:25 -0000 1.6
@@ -20,7 +20,14 @@
sub findnodes {
my ($self, $xpath) = @_;
- my @nodes = $self->_findnodes($xpath);
+ my @nodes;
+ $self->_enter;
+ eval {
+ @nodes = $self->_findnodes($xpath);
+ };
+ $self->_leave;
+ if ($@) { die $@; }
+
if (wantarray) {
return @nodes;
}
@@ -32,18 +39,21 @@
sub findvalue {
my ($self, $xpath) = @_;
my $res;
- eval {
- $res = $self->find($xpath);
- };
- if ( $@ ) {
- die $@;
- }
+ $res = $self->find($xpath);
return $res->to_literal->value;
}
sub find {
my ($self, $xpath) = @_;
- my ($type, @params) = $self->_find($xpath);
+ my ($type, @params);
+
+ $self->_enter;
+ eval {
+ ($type, @params) = $self->_find($xpath);
+ };
+ $self->_leave;
+ if ($@) { die $@; }
+
if ($type) {
return $type->new(@params);
}
|