summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorFlaviu Tamas <tamasflaviu@gmail.com>2015-01-10 12:30:43 -0500
committerFlaviu Tamas <tamasflaviu@gmail.com>2015-01-10 12:30:43 -0500
commitca4cf242991ca46fea9cd94afe8207b8bb8fe2f1 (patch)
tree8a273babd86dd44669056ee5cf0566df409d60df /src
parent00b047a6600b53a6439e9bf78d05894c5dd10297 (diff)
downloadNim-ca4cf242991ca46fea9cd94afe8207b8bb8fe2f1.tar.gz
Implement correct destruction
Diffstat (limited to 'src')
-rw-r--r--src/nre.nim11
-rw-r--r--src/private/pcre.nim15
2 files changed, 17 insertions, 9 deletions
diff --git a/src/nre.nim b/src/nre.nim
index 3f06d33bb..2611ee7f6 100644
--- a/src/nre.nim
+++ b/src/nre.nim
@@ -78,8 +78,14 @@ type
 
   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 =
-  new result
+  new(result, destroyRegex)
   result.pattern = pattern
 
   var errorMsg: cstring
@@ -131,3 +137,6 @@ proc getNameToNumberTable(self: Regex): Table[string, int] =
       idx += 1
 
     result[name] = num
+
+proc exec*(self: Regex, str: string): RegexMatch =
+  discard
diff --git a/src/private/pcre.nim b/src/private/pcre.nim
index ba717efc6..385f85bc1 100644
--- a/src/private/pcre.nim
+++ b/src/private/pcre.nim
@@ -1,4 +1,3 @@
-
 when not defined(pcreDll):
   when hostOS == "windows":
     const pcreDll = "pcre.dll"
@@ -10,7 +9,6 @@ when not defined(pcreDll):
 else:
   {.pragma: pcreImport, header: "<pcre.h>".}
 
-
 #************************************************
 #       Perl-Compatible Regular Expressions      *
 #***********************************************
@@ -368,12 +366,13 @@ type
 #that is triggered by the (?) regex item. For Virtual Pascal, these definitions
 #have to take another form. 
 
-var malloc*: proc (a2: csize): pointer {.cdecl.}
-var free*: proc (a2: pointer) {.cdecl.}
-var stack_malloc*: proc (a2: csize): pointer {.cdecl.}
-var stack_free*: proc (a2: pointer) {.cdecl.}
-var callout*: proc (a2: ptr callout_block): cint {.cdecl.}
-var stack_guard*: proc (): cint {.cdecl.}
+{.emit: "#include <pcre.h>".}
+proc malloc*(a2: csize): pointer {.cdecl, importc: "pcre_malloc", pcreImport.}
+proc free*(a2: pointer) {.cdecl, importc: "pcre_free", pcreImport.}
+proc stack_malloc*(a2: csize): pointer {.cdecl, importc: "pcre_stack_malloc", pcreImport.}
+proc stack_free*(a2: pointer) {.cdecl, importc: "pcre_free", pcreImport.}
+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. 
 
ef='#n242'>242 243 244 245 246 247 248 249 250