You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2001/05/06 00:58:31 UTC
cvs commit: xml-xerces/perl/Handler .cvsignore Makefile.PL PerlContentCallbackHandler.cpp PerlContentCallbackHandler.hpp PerlContentCallbackHandler.swig.hpp PerlDefaultCallbackHandler.hpp PerlDocumentCallbackHandler.cpp PerlDocumentCallbackHandler.hpp PerlDocumentCallbackHandler.swig.hpp PerlErrorCallbackHandler.cpp PerlErrorCallbackHandler.hpp PerlErrorCallbackHandler.swig.hpp
jasons 01/05/05 15:58:31
Added: perl/Handler .cvsignore Makefile.PL
PerlContentCallbackHandler.cpp
PerlContentCallbackHandler.hpp
PerlContentCallbackHandler.swig.hpp
PerlDefaultCallbackHandler.hpp
PerlDocumentCallbackHandler.cpp
PerlDocumentCallbackHandler.hpp
PerlDocumentCallbackHandler.swig.hpp
PerlErrorCallbackHandler.cpp
PerlErrorCallbackHandler.hpp
PerlErrorCallbackHandler.swig.hpp
Log:
New interfaces for callbacks
Revision Changes Path
1.1 xml-xerces/perl/Handler/.cvsignore
Index: .cvsignore
===================================================================
Handler.bs
Makefile
pm_to_blib
1.1 xml-xerces/perl/Handler/Makefile.PL
Index: Makefile.PL
===================================================================
WriteMakefile(
'OPTIMIZE' => '-g',
'NAME' => 'Handler',
'INC' => $INCLUDES,
'OBJECT' => '$(O_FILES)',
);
__END__
sub MY::static
{
'
static :: libhandler$(LIB_EXT)
dynamic :: static
libhandler$(LIB_EXT): $(O_FILES) $(MYEXTLIB)
$(AR) cru libhandler$(LIB_EXT) $(O_FILES)
$(RANLIB) libhandler$(LIB_EXT)
libhandler.$(DLEXT): $(LDFROM) $(MYEXTLIB)
$(LD) -o libhandler.$(DLEXT) $(LDDLFLAGS) --whole-archive $(LDFROM) $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) $(EXPORT_LIST)
$(CHMOD) 755 libhandler.$(DLEXT)
';
}
1.1 xml-xerces/perl/Handler/PerlContentCallbackHandler.cpp
Index: PerlContentCallbackHandler.cpp
===================================================================
#include <stdlib.h>
#include "PerlContentCallbackHandler.hpp"
PerlContentCallbackHandler::PerlContentCallbackHandler() {
callbackObj = NULL;
}
PerlContentCallbackHandler::~PerlContentCallbackHandler() {
if (callbackObj) {
SvREFCNT_dec(callbackObj);
callbackObj = NULL;
}
}
void
PerlContentCallbackHandler::set_callback_obj(SV* object) {
SvREFCNT_inc(object);
callbackObj = object;
}
void
PerlContentCallbackHandler::startElement(const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname,
const Attributes& attrs)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the uri
char *cptr1 = XMLString::transcode(uri);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
// the next argument is the localname
char *cptr2 = XMLString::transcode(localname);
SV *string2 = sv_newmortal();
sv_setpv(string2, (char *)cptr2);
XPUSHs(string2);
// the next argument is the qname
char *cptr3 = XMLString::transcode(qname);
SV *string3 = sv_newmortal();
sv_setpv(string3, (char *)cptr3);
XPUSHs(string3);
// next is the attributes
char *class_name = "XML::Xerces::Attributes";
HV *hash = newHV();
HV *stash = gv_stashpv(class_name, FALSE);
hv_magic(hash,
(GV *)sv_setref_pv(sv_newmortal(),
class_name, (void *)&attrs),
'P');
XPUSHs(sv_bless(newRV_noinc((SV *)hash), stash));
PUTBACK;
perl_call_method("start_element", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::endElement(const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the uri
char *cptr1 = XMLString::transcode(uri);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
// the next argument is the localname
char *cptr2 = XMLString::transcode(localname);
SV *string2 = sv_newmortal();
sv_setpv(string2, (char *)cptr2);
XPUSHs(string2);
// the next argument is the qname
char *cptr3 = XMLString::transcode(qname);
SV *string3 = sv_newmortal();
sv_setpv(string3, (char *)cptr3);
XPUSHs(string3);
PUTBACK;
perl_call_method("end_element", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::characters(const XMLCh* const chars,
const unsigned int length)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the element name
char *cptr = XMLString::transcode(chars);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
// next is the length
XPUSHs(sv_2mortal(newSViv(length)));
PUTBACK;
perl_call_method("characters", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::ignorableWhitespace(const XMLCh* const chars,
const unsigned int length)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the element name
char *cptr = XMLString::transcode(chars);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
// next is the length
XPUSHs(sv_2mortal(newSViv(length)));
PUTBACK;
perl_call_method("ignorable_whitespace", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::resetDocument(void)
{
return;
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
PUTBACK;
perl_call_method("reset_document", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::startDocument(void)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
PUTBACK;
perl_call_method("start_document", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::endDocument(void)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
PUTBACK;
perl_call_method("end_document", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::processingInstruction(const XMLCh* const target,
const XMLCh* const data)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the target
char *cptr1 = XMLString::transcode(target);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
// the next argument is the data
char *cptr2 = XMLString::transcode(data);
SV *string2 = sv_newmortal();
sv_setpv(string2, (char *)cptr2);
XPUSHs(string2);
PUTBACK;
perl_call_method("processing_instruction", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::setDocumentLocator(const Locator* const locator)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// next is the attribute list
char *class_name = "XML::Xerces::Locator";
HV *hash = newHV();
HV *stash = gv_stashpv(class_name, FALSE);
hv_magic(hash,
(GV *)sv_setref_pv(sv_newmortal(),
class_name, (void *)locator),
'P');
XPUSHs(sv_bless(newRV_noinc((SV *)hash), stash));
PUTBACK;
perl_call_method("set_document_locator", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::startPrefixMapping (const XMLCh* const prefix,
const XMLCh* const uri)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the prefix
char *cptr1 = XMLString::transcode(prefix);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
// the next argument is the uri
char *cptr2 = XMLString::transcode(uri);
SV *string2 = sv_newmortal();
sv_setpv(string2, (char *)cptr2);
XPUSHs(string2);
PUTBACK;
perl_call_method("start_prefix_mapping", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::endPrefixMapping (const XMLCh* const prefix)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the prefix
char *cptr1 = XMLString::transcode(prefix);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
PUTBACK;
perl_call_method("end_prefix_mapping", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlContentCallbackHandler::skippedEntity (const XMLCh* const name)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the name
char *cptr1 = XMLString::transcode(name);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
PUTBACK;
perl_call_method("skipped_entity", G_VOID);
FREETMPS;
LEAVE;
}
1.1 xml-xerces/perl/Handler/PerlContentCallbackHandler.hpp
Index: PerlContentCallbackHandler.hpp
===================================================================
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny
games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#include <string.h>
#ifdef __cplusplus
}
#endif
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes PL_sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef PL_sv_undef
#endif
#ifndef PL_na
#define PL_na PL_na
#endif
#endif
#include "sax2/ContentHandler.hpp"
#include "util/XMLString.hpp"
class PerlContentCallbackHandler : public ContentHandler {
private:
SV *callbackObj;
public:
PerlContentCallbackHandler();
~PerlContentCallbackHandler();
void set_callback_obj(SV*);
// The ContentHandler interface
void startElement(const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname,
const Attributes& attrs);
void characters(const XMLCh* const chars,
const unsigned int length);
void ignorableWhitespace(const XMLCh* const chars,
const unsigned int length);
void endElement(const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname);
void resetDocument(void);
void startDocument();
void endDocument();
void processingInstruction (const XMLCh* const target,
const XMLCh* const data);
void setDocumentLocator(const Locator* const locator);
void startPrefixMapping (const XMLCh* const prefix,
const XMLCh* const uri);
void endPrefixMapping (const XMLCh* const prefix);
void skippedEntity (const XMLCh* const name);
};
1.1 xml-xerces/perl/Handler/PerlContentCallbackHandler.swig.hpp
Index: PerlContentCallbackHandler.swig.hpp
===================================================================
class PerlContentCallbackHandler : public ContentHandler {
// private:
// SV *callbackObj;
public:
PerlContentCallbackHandler();
~PerlContentCallbackHandler();
void set_callback_obj(SV*);
// The ContentHandler interface
void startElement(const XMLCh* /*const*/ uri,
const XMLCh* /*const*/ localname,
const XMLCh* /*const*/ qname,
const Attributes& attrs);
void characters(const XMLCh* /*const*/ chars,
const unsigned int length);
void ignorableWhitespace(const XMLCh* /*const*/ chars,
const unsigned int length);
void endElement(const XMLCh* /*const*/ uri,
const XMLCh* /*const*/ localname,
const XMLCh* /*const*/ qname);
void resetDocument(void);
void startDocument();
void endDocument();
void processingInstruction (const XMLCh* /*const*/ target,
const XMLCh* /*const*/ data);
void setDocumentLocator(const Locator* /*const*/ locator);
void startPrefixMapping (const XMLCh* /*const*/ prefix,
const XMLCh* /*const*/ uri);
void endPrefixMapping (const XMLCh* /*const*/ prefix);
void skippedEntity (const XMLCh* /*const*/ name);
};
1.1 xml-xerces/perl/Handler/PerlDefaultCallbackHandler.hpp
Index: PerlDefaultCallbackHandler.hpp
===================================================================
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny
games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#include <string.h>
#ifdef __cplusplus
}
#endif
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes PL_sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef PL_sv_undef
#endif
#ifndef PL_na
#define PL_na PL_na
#endif
#endif
#include "sax/DefaultHandler.hpp"
#include "util/XMLString.hpp"
class PerlDefaultCallbackHandler : public DefaultHandler {
private:
SV *callbackObj;
public:
PerlDefaultCallbackHandler();
~PerlDefaultCallbackHandler();
void set_callback_obj(SV*);
// The DefaultHandler interface
void startElement(const XMLCh* const name,
AttributeList& attributes);
void characters(const XMLCh* const chars,
const unsigned int length);
void ignorableWhitespace(const XMLCh* const chars,
const unsigned int length);
void endElement(const XMLCh* const name);
void resetDefault(void);
void startDefault();
void endDefault();
void processingInstruction (const XMLCh* const target,
const XMLCh* const data);
void setDefaultLocator(const Locator* const locator);
};
1.1 xml-xerces/perl/Handler/PerlDocumentCallbackHandler.cpp
Index: PerlDocumentCallbackHandler.cpp
===================================================================
#include <stdlib.h>
#include "PerlDocumentCallbackHandler.hpp"
PerlDocumentCallbackHandler::PerlDocumentCallbackHandler() {
callbackObj = NULL;
}
PerlDocumentCallbackHandler::~PerlDocumentCallbackHandler() {
if (callbackObj) {
SvREFCNT_dec(callbackObj);
callbackObj = NULL;
}
}
void
PerlDocumentCallbackHandler::set_callback_obj(SV* object) {
SvREFCNT_inc(object);
callbackObj = object;
}
void
PerlDocumentCallbackHandler::startElement(const XMLCh* const name,
AttributeList& attributes) {
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the element name
char *cptr = XMLString::transcode(name);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
// next is the attribute list
char *class_name = "XML::Xerces::AttributeList";
HV *hash = newHV();
HV *stash = gv_stashpv(class_name, FALSE);
hv_magic(hash,
(GV *)sv_setref_pv(sv_newmortal(),
class_name, (void *)&attributes),
'P');
XPUSHs(sv_bless(newRV_noinc((SV *)hash), stash));
PUTBACK;
perl_call_method("start_element", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::endElement(const XMLCh* const name)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the element name
char *cptr = XMLString::transcode(name);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
PUTBACK;
perl_call_method("end_element", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::characters(const XMLCh* const chars,
const unsigned int length)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the element name
char *cptr = XMLString::transcode(chars);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
// next is the length
XPUSHs(sv_2mortal(newSViv(length)));
PUTBACK;
perl_call_method("characters", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::ignorableWhitespace(const XMLCh* const chars,
const unsigned int length)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the element name
char *cptr = XMLString::transcode(chars);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
// next is the length
XPUSHs(sv_2mortal(newSViv(length)));
PUTBACK;
perl_call_method("ignorable_whitespace", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::resetDocument(void)
{
return;
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
PUTBACK;
perl_call_method("reset_document", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::startDocument(void)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
PUTBACK;
perl_call_method("start_document", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::endDocument(void)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
PUTBACK;
perl_call_method("end_document", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::processingInstruction(const XMLCh* const target,
const XMLCh* const data)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the target
char *cptr1 = XMLString::transcode(target);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
// the next argument is the data
char *cptr2 = XMLString::transcode(data);
SV *string2 = sv_newmortal();
sv_setpv(string2, (char *)cptr2);
XPUSHs(string2);
PUTBACK;
perl_call_method("processing_instruction", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlDocumentCallbackHandler::setDocumentLocator(const Locator* const locator)
{
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// next is the attribute list
char *class_name = "XML::Xerces::Locator";
HV *hash = newHV();
HV *stash = gv_stashpv(class_name, FALSE);
hv_magic(hash,
(GV *)sv_setref_pv(sv_newmortal(),
class_name, (void *)locator),
'P');
XPUSHs(sv_bless(newRV_noinc((SV *)hash), stash));
PUTBACK;
perl_call_method("set_document_locator", G_VOID);
FREETMPS;
LEAVE;
}
1.1 xml-xerces/perl/Handler/PerlDocumentCallbackHandler.hpp
Index: PerlDocumentCallbackHandler.hpp
===================================================================
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny
games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#include <string.h>
#ifdef __cplusplus
}
#endif
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes PL_sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef PL_sv_undef
#endif
#ifndef PL_na
#define PL_na PL_na
#endif
#endif
#include "sax/DocumentHandler.hpp"
#include "util/XMLString.hpp"
class PerlDocumentCallbackHandler : public DocumentHandler {
private:
SV *callbackObj;
public:
PerlDocumentCallbackHandler();
~PerlDocumentCallbackHandler();
void set_callback_obj(SV*);
// The DocumentHandler interface
void startElement(const XMLCh* const name,
AttributeList& attributes);
void characters(const XMLCh* const chars,
const unsigned int length);
void ignorableWhitespace(const XMLCh* const chars,
const unsigned int length);
void endElement(const XMLCh* const name);
void resetDocument(void);
void startDocument();
void endDocument();
void processingInstruction (const XMLCh* const target,
const XMLCh* const data);
void setDocumentLocator(const Locator* const locator);
};
1.1 xml-xerces/perl/Handler/PerlDocumentCallbackHandler.swig.hpp
Index: PerlDocumentCallbackHandler.swig.hpp
===================================================================
class PerlDocumentCallbackHandler : public DocumentHandler {
// private:
// SV *callbackObj;
public:
PerlDocumentCallbackHandler();
~PerlDocumentCallbackHandler();
void set_callback_obj(SV*);
// The DocumentHandler interface
void startElement(const XMLCh* /*const*/ name,
AttributeList& attributes);
void endElement(const XMLCh* /*const*/ name);
void characters(const XMLCh* /*const*/ chars,
const unsigned int length);
void ignorableWhitespace(const XMLCh* /*const*/ chars,
const unsigned int length);
void resetDocument(void);
void startDocument();
void endDocument();
void processingInstruction (const XMLCh* /*const*/ target,
const XMLCh* /*const*/ data);
void setDocumentLocator(const Locator* /*const*/ locator);
};
1.1 xml-xerces/perl/Handler/PerlErrorCallbackHandler.cpp
Index: PerlErrorCallbackHandler.cpp
===================================================================
#include <stdlib.h>
#include "PerlErrorCallbackHandler.hpp"
PerlErrorCallbackHandler::PerlErrorCallbackHandler() {
callbackObj = NULL;
// printf("in error: constructor");
}
PerlErrorCallbackHandler::~PerlErrorCallbackHandler() {
if (callbackObj) {
SvREFCNT_dec(callbackObj);
}
// printf("in error: destructor");
}
void
PerlErrorCallbackHandler::set_callback_obj(SV* object) {
SvREFCNT_inc(object);
callbackObj = object;
// printf("in error: set_callback");
}
void
PerlErrorCallbackHandler::warning(const SAXParseException& exception) {
// printf("in error: warning");
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// then put the exception on the stack
HV *hash = newHV();
HV *stash = gv_stashpv("XML::Xerces::SAXParseException", FALSE);
hv_magic( hash, (GV *)sv_setref_pv( sv_newmortal(), "XML::Xerces::SAXParseException", (void *)&exception ), 'P' );
XPUSHs( sv_bless( newRV_noinc( (SV *)hash ), stash ) );
PUTBACK;
perl_call_method("warning", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlErrorCallbackHandler::error(const SAXParseException& exception) {
// printf("in error: error");
if (!callbackObj) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// then put the exception on the stack
HV *hash = newHV();
HV *stash = gv_stashpv("XML::Xerces::SAXParseException", FALSE);
hv_magic( hash, (GV *)sv_setref_pv( sv_newmortal(), "XML::Xerces::SAXParseException", (void *)&exception ), 'P' );
XPUSHs( sv_bless( newRV_noinc( (SV *)hash ), stash ) );
PUTBACK;
perl_call_method("error", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlErrorCallbackHandler::fatalError(const SAXParseException& exception) {
// printf("in error: fatal_error");
if (!callbackObj) {
die("Received FatalError and no ErrorHandler was set");
}
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// then put the exception on the stack
HV *hash = newHV();
HV *stash = gv_stashpv("XML::Xerces::SAXParseException", FALSE);
hv_magic(hash,
(GV *)sv_setref_pv(sv_newmortal(),
"XML::Xerces::SAXParseException",
(void *) &exception),
'P');
XPUSHs(sv_bless(newRV_noinc((SV *)hash), stash));
PUTBACK;
perl_call_method("fatal_error", G_VOID);
FREETMPS;
LEAVE;
}
void
PerlErrorCallbackHandler::resetErrors(void)
{
// printf("in error: reset_errors");
if (!callbackObj) return;
dSP;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
PUTBACK;
perl_call_method("reset_errors", G_VOID);
}
1.1 xml-xerces/perl/Handler/PerlErrorCallbackHandler.hpp
Index: PerlErrorCallbackHandler.hpp
===================================================================
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny
games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#include <string.h>
#ifdef __cplusplus
}
#endif
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes PL_sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef PL_sv_undef
#endif
#ifndef PL_na
#define PL_na PL_na
#endif
#endif
#include "sax/ErrorHandler.hpp"
class PerlErrorCallbackHandler : public ErrorHandler {
private:
SV *callbackObj;
public:
PerlErrorCallbackHandler();
~PerlErrorCallbackHandler();
void set_callback_obj(SV*);
// the ErrorHandler interface
virtual void warning(const SAXParseException& exception);
virtual void error(const SAXParseException& exception);
virtual void fatalError(const SAXParseException& exception);
virtual void resetErrors(void);
};
1.1 xml-xerces/perl/Handler/PerlErrorCallbackHandler.swig.hpp
Index: PerlErrorCallbackHandler.swig.hpp
===================================================================
class PerlErrorCallbackHandler : public ErrorHandler {
public:
PerlErrorCallbackHandler();
~PerlErrorCallbackHandler();
void set_callback_obj(SV*);
virtual void warning(const SAXParseException& exception);
virtual void error(const SAXParseException& exception);
virtual void fatalError(const SAXParseException& exception);
virtual void resetErrors(void);
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org