Hello,
I’ve been using v9.4 of the Go SDK for some PDF processing, but I’ve run into an issue when I attempt to upgrade to v9.5.
Using this code and the attached sample document with v9.4, the little application will finish successfully and print the message Found match: "Hello!"
.
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/org/repo/third-party/pdftron"
)
func main() {
// Initialize PDFTron
licenseKey := os.Getenv("PDFTRON_LICENSE_KEY")
pdftron.PDFNetInitialize(licenseKey)
// Load sample document
content, err := ioutil.ReadFile("sample.pdf")
if err != nil {
msg := fmt.Sprintf("error while opening sample.pdf: %v", err)
panic(msg)
}
// Start the workload
doc := pdftron.NewPDFDoc(&content[0], int64(len(content)))
txtSearch := pdftron.NewTextSearch()
defer txtSearch.Destroy()
mode := pdftron.TextSearchE_highlight | pdftron.TextSearchE_reg_expression
if ok := txtSearch.Begin(doc, "Hello.*", uint(mode)); !ok {
panic("failed to initialize text search")
}
searchResults := txtSearch.Run()
if !searchResults.IsFound() {
panic("no results found")
}
highlights := searchResults.GetHighlights()
highlights.Begin(doc)
txtRange := highlights.GetCurrentTextRange()
textMatch := txtRange.GetText()
fmt.Printf("Found match: %q\n", textMatch)
}
After upgrading to v9.5, I get the following error message when I try to run the same code. Is this a bug or has the way to call the code changed?
PDFNet is running in demo mode.
Package: base
sandbox(40027,0x7ff85bbc3680) malloc: *** error for object 0x7ff7bfefe8d0: pointer being freed was not allocated
sandbox(40027,0x7ff85bbc3680) malloc: *** set a breakpoint in malloc_error_break to debug
SIGABRT: abort
PC=0x7ff81824e22a m=0 sigcode=0
signal arrived during cgo execution
goroutine 1 [syscall]:
runtime.cgocall(0x1000e62a0, 0xc000073e58)
/usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc000073e30 sp=0xc000073df8 pc=0x10000335c
github.com/org/repo/third-party/pdftron._Cfunc__wrap_Highlights_GetCurrentTextRange_pdftron_4dfb989b999904da(0x101319800)
_cgo_gotypes.go:28218 +0x4d fp=0xc000073e58 sp=0xc000073e30 pc=0x10009124d
github.com/org/repo/third-party/pdftron.SwigcptrHighlights.GetCurrentTextRange(...)
/Users/username/Sandbox/repo/third-party/pdftron/pdftron.go:79658
github.com/org/repo/third-party/pdftron.(*SwigcptrHighlights).GetCurrentTextRange(0x101310460?)
<autogenerated>:1 +0x31 fp=0xc000073e78 sp=0xc000073e58 pc=0x1000cdeb1
main.main()
/Users/username/Sandbox/repo/cmd/sandbox/main.go:43 +0x2d5 fp=0xc000073f80 sp=0xc000073e78 pc=0x1000ce815
runtime.main()
/usr/local/go/src/runtime/proc.go:250 +0x207 fp=0xc000073fe0 sp=0xc000073f80 pc=0x1000336c7
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000073fe8 sp=0xc000073fe0 pc=0x10005e741
goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000060fb0 sp=0xc000060f90 pc=0x100033af6
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:387
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:305 +0xb0 fp=0xc000060fe0 sp=0xc000060fb0 pc=0x100033930
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000060fe8 sp=0xc000060fe0 pc=0x10005e741
created by runtime.init.6
/usr/local/go/src/runtime/proc.go:293 +0x25
goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000061780 sp=0xc000061760 pc=0x100033af6
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:387
runtime.bgsweep(0x0?)
/usr/local/go/src/runtime/mgcsweep.go:278 +0x8e fp=0xc0000617c8 sp=0xc000061780 pc=0x1000211ae
runtime.gcenable.func1()
/usr/local/go/src/runtime/mgc.go:178 +0x26 fp=0xc0000617e0 sp=0xc0000617c8 pc=0x100016646
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc0000617e8 sp=0xc0000617e0 pc=0x10005e741
created by runtime.gcenable
/usr/local/go/src/runtime/mgc.go:178 +0x6b
goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc0000241c0?, 0x10019e370?, 0x1?, 0x0?, 0x0?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000061f70 sp=0xc000061f50 pc=0x100033af6
runtime.goparkunlock(...)
/usr/local/go/src/runtime/proc.go:387
runtime.(*scavengerState).park(0x1002af140)
/usr/local/go/src/runtime/mgcscavenge.go:400 +0x53 fp=0xc000061fa0 sp=0xc000061f70 pc=0x10001f0b3
runtime.bgscavenge(0x0?)
/usr/local/go/src/runtime/mgcscavenge.go:628 +0x45 fp=0xc000061fc8 sp=0xc000061fa0 pc=0x10001f685
runtime.gcenable.func2()
/usr/local/go/src/runtime/mgc.go:179 +0x26 fp=0xc000061fe0 sp=0xc000061fc8 pc=0x1000165e6
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000061fe8 sp=0xc000061fe0 pc=0x10005e741
created by runtime.gcenable
/usr/local/go/src/runtime/mgc.go:179 +0xaa
goroutine 5 [finalizer wait]:
runtime.gopark(0x1a0?, 0x1002af580?, 0x60?, 0x78?, 0xc000060770?)
/usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000060628 sp=0xc000060608 pc=0x100033af6
runtime.runfinq()
/usr/local/go/src/runtime/mfinal.go:193 +0x107 fp=0xc0000607e0 sp=0xc000060628 pc=0x100015687
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc0000607e8 sp=0xc0000607e0 pc=0x10005e741
created by runtime.createfing
/usr/local/go/src/runtime/mfinal.go:163 +0x45
rax 0x0
rbx 0x7ff85bbc3680
rcx 0x7ff7bfefdfe8
rdx 0x0
rdi 0x103
rsi 0x6
rbp 0x7ff7bfefe010
rsp 0x7ff7bfefdfe8
r8 0x1
r9 0x0
r10 0x0
r11 0x246
r12 0x103
r13 0x1006df028
r14 0x6
r15 0x16
rip 0x7ff81824e22a
rflags 0x246
cs 0x7
fs 0x0
gs 0x0
exit status 2
Thanks in advanced,
Ben
sample.pdf (13.4 KB)