From 2ab6245e33cf33d54c9ea0d7dfe6109f78d092f4 Mon Sep 17 00:00:00 2001 From: Ross Kinder Date: Wed, 23 Dec 2015 18:54:11 -0500 Subject: [PATCH] initialize libxml error capture when we start processing XML on each thread. --- error.go | 7 +++++-- xmlsec.go | 5 ----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/error.go b/error.go index 414b593..64fd7fa 100644 --- a/error.go +++ b/error.go @@ -1,7 +1,6 @@ package xmlsec import ( - "C" "fmt" "runtime" "strings" @@ -9,6 +8,9 @@ import ( "github.com/crewjam/errset" ) +// void captureXmlErrors(); +import "C" + var globalErrors = map[uintptr]errset.ErrSet{} type libraryError struct { @@ -61,13 +63,14 @@ func onXmlError(msg *C.char) { func startProcessingXML() { runtime.LockOSThread() globalErrors[getThreadID()] = errset.ErrSet{} + C.captureXmlErrors() } // stopProcessingXML unlocks the goroutine-thread lock and deletes the current // error stack. func stopProcessingXML() { - runtime.UnlockOSThread() delete(globalErrors, getThreadID()) + runtime.UnlockOSThread() } // popError returns the global error for the current thread and resets it to diff --git a/xmlsec.go b/xmlsec.go index 8b1029d..f35c337 100644 --- a/xmlsec.go +++ b/xmlsec.go @@ -27,9 +27,6 @@ import "C" // } import "C" -// void captureXmlErrors(); -import "C" - func init() { C.xmlInitParser() @@ -42,8 +39,6 @@ func init() { if rv := C.xmlSecCryptoInit(); rv < 0 { panic("xmlsec crypto initialization failed.") } - - C.captureXmlErrors() } func newDoc(buf []byte, idattrs []XMLIDOption) (*C.xmlDoc, error) {