initialize libxml error capture when we start processing XML on each thread.

This commit is contained in:
Ross Kinder
2015-12-23 18:54:11 -05:00
parent dc37ddb368
commit 2ab6245e33
2 changed files with 5 additions and 7 deletions

View File

@@ -1,7 +1,6 @@
package xmlsec package xmlsec
import ( import (
"C"
"fmt" "fmt"
"runtime" "runtime"
"strings" "strings"
@@ -9,6 +8,9 @@ import (
"github.com/crewjam/errset" "github.com/crewjam/errset"
) )
// void captureXmlErrors();
import "C"
var globalErrors = map[uintptr]errset.ErrSet{} var globalErrors = map[uintptr]errset.ErrSet{}
type libraryError struct { type libraryError struct {
@@ -61,13 +63,14 @@ func onXmlError(msg *C.char) {
func startProcessingXML() { func startProcessingXML() {
runtime.LockOSThread() runtime.LockOSThread()
globalErrors[getThreadID()] = errset.ErrSet{} globalErrors[getThreadID()] = errset.ErrSet{}
C.captureXmlErrors()
} }
// stopProcessingXML unlocks the goroutine-thread lock and deletes the current // stopProcessingXML unlocks the goroutine-thread lock and deletes the current
// error stack. // error stack.
func stopProcessingXML() { func stopProcessingXML() {
runtime.UnlockOSThread()
delete(globalErrors, getThreadID()) delete(globalErrors, getThreadID())
runtime.UnlockOSThread()
} }
// popError returns the global error for the current thread and resets it to // popError returns the global error for the current thread and resets it to

View File

@@ -27,9 +27,6 @@ import "C"
// } // }
import "C" import "C"
// void captureXmlErrors();
import "C"
func init() { func init() {
C.xmlInitParser() C.xmlInitParser()
@@ -42,8 +39,6 @@ func init() {
if rv := C.xmlSecCryptoInit(); rv < 0 { if rv := C.xmlSecCryptoInit(); rv < 0 {
panic("xmlsec crypto initialization failed.") panic("xmlsec crypto initialization failed.")
} }
C.captureXmlErrors()
} }
func newDoc(buf []byte, idattrs []XMLIDOption) (*C.xmlDoc, error) { func newDoc(buf []byte, idattrs []XMLIDOption) (*C.xmlDoc, error) {