Implement correct destruction
This commit is contained in:
parent
00b047a660
commit
ca4cf24299
2 changed files with 17 additions and 9 deletions
11
src/nre.nim
11
src/nre.nim
|
|
@ -78,8 +78,14 @@ type
|
||||||
|
|
||||||
StudyError* = ref object of Exception
|
StudyError* = ref object of Exception
|
||||||
|
|
||||||
|
proc destroyRegex(self: Regex) =
|
||||||
|
pcre.free_substring(cast[cstring](self.pcreObj))
|
||||||
|
self.pcreObj = nil
|
||||||
|
if self.pcreExtra != nil:
|
||||||
|
pcre.free_study(self.pcreExtra)
|
||||||
|
|
||||||
proc initRegex*(pattern: string, options = "Sx"): Regex =
|
proc initRegex*(pattern: string, options = "Sx"): Regex =
|
||||||
new result
|
new(result, destroyRegex)
|
||||||
result.pattern = pattern
|
result.pattern = pattern
|
||||||
|
|
||||||
var errorMsg: cstring
|
var errorMsg: cstring
|
||||||
|
|
@ -131,3 +137,6 @@ proc getNameToNumberTable(self: Regex): Table[string, int] =
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|
||||||
result[name] = num
|
result[name] = num
|
||||||
|
|
||||||
|
proc exec*(self: Regex, str: string): RegexMatch =
|
||||||
|
discard
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
when not defined(pcreDll):
|
when not defined(pcreDll):
|
||||||
when hostOS == "windows":
|
when hostOS == "windows":
|
||||||
const pcreDll = "pcre.dll"
|
const pcreDll = "pcre.dll"
|
||||||
|
|
@ -10,7 +9,6 @@ when not defined(pcreDll):
|
||||||
else:
|
else:
|
||||||
{.pragma: pcreImport, header: "<pcre.h>".}
|
{.pragma: pcreImport, header: "<pcre.h>".}
|
||||||
|
|
||||||
|
|
||||||
#************************************************
|
#************************************************
|
||||||
# Perl-Compatible Regular Expressions *
|
# Perl-Compatible Regular Expressions *
|
||||||
#***********************************************
|
#***********************************************
|
||||||
|
|
@ -368,12 +366,13 @@ type
|
||||||
#that is triggered by the (?) regex item. For Virtual Pascal, these definitions
|
#that is triggered by the (?) regex item. For Virtual Pascal, these definitions
|
||||||
#have to take another form.
|
#have to take another form.
|
||||||
|
|
||||||
var malloc*: proc (a2: csize): pointer {.cdecl.}
|
{.emit: "#include <pcre.h>".}
|
||||||
var free*: proc (a2: pointer) {.cdecl.}
|
proc malloc*(a2: csize): pointer {.cdecl, importc: "pcre_malloc", pcreImport.}
|
||||||
var stack_malloc*: proc (a2: csize): pointer {.cdecl.}
|
proc free*(a2: pointer) {.cdecl, importc: "pcre_free", pcreImport.}
|
||||||
var stack_free*: proc (a2: pointer) {.cdecl.}
|
proc stack_malloc*(a2: csize): pointer {.cdecl, importc: "pcre_stack_malloc", pcreImport.}
|
||||||
var callout*: proc (a2: ptr callout_block): cint {.cdecl.}
|
proc stack_free*(a2: pointer) {.cdecl, importc: "pcre_free", pcreImport.}
|
||||||
var stack_guard*: proc (): cint {.cdecl.}
|
proc callout*(a2: ptr callout_block): cint {.cdecl, importc: "pcre_callout", pcreImport.}
|
||||||
|
proc stack_guard*(): cint {.cdecl, importc: "pcre_stack_guard", pcreImport.}
|
||||||
|
|
||||||
# User defined callback which provides a stack just before the match starts.
|
# User defined callback which provides a stack just before the match starts.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue