Skip to content

Commit 2ce5772

Browse files
committed
try extra API for holding memory
1 parent a440278 commit 2ce5772

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ crate-type = ["dylib"] # Creates dynamic lib
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
cirru_edn = "0.6.4-a4"
17-
# cirru_edn = { path = "/Users/chenyong/repo/cirru/edn.rs" }
16+
# cirru_edn = "0.6.4-a4"
17+
cirru_edn = { path = "/Users/chenyong/repo/cirru/edn.rs" }
1818
cirru_parser = "0.1.29"
1919
regex = "1.10.4"
2020
lazy_static = "1.4.0"

calcit.cirru

Lines changed: 31 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compact.cirru

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
:files $ {}
77
|regex.core $ %{} :FileEntry
88
:defs $ {}
9+
|hold-patterns-memory! $ %{} :CodeEntry (:doc |)
10+
:code $ quote
11+
defn hold-patterns-memory! ()
12+
&call-dylib-edn (get-dylib-path "\"/dylibs/libcalcit_regex") "\"holding_patterns_memory"
13+
println "\"memory of regex patterns are set to hold!"
914
|re-drop $ %{} :CodeEntry (:doc |)
1015
:code $ quote
1116
defn re-drop (pattern)
@@ -61,21 +66,23 @@
6166
assert= |1abXcX3 $ re-replace-all |1ab22c333 |\d{2} "\"X"
6267
assert= ([] "\"1ab" "\"c" "\"3") (re-split |1ab22c333 |\d{2})
6368
println "\"%%% test variable holding regex"
69+
hold-patterns-memory!
6470
let
6571
pattern $ re-pattern "\"\\d+"
72+
p2 $ re-pattern "\"\\w+"
6673
println "\"Pattern is:" pattern
6774
assert= true $ re-matches |2 pattern
6875
assert= true $ re-matches |23 pattern
6976
assert= false $ re-matches |qq pattern
7077
assert= "\"22" $ re-find |q22 pattern
7178
assert= ([] |1 |2 |3) (re-find-all |1q2q3 pattern)
7279
assert= |XabXcX $ re-replace-all |1ab22c333 pattern "\"X"
73-
w-log $ re-drop pattern
80+
w-log $ re-drop p2
7481
w-log $ re-drop pattern
7582
:ns $ %{} :CodeEntry (:doc |)
7683
:code $ quote
7784
ns regex.test $ :require
78-
regex.core :refer $ re-matches re-find-index re-find re-find-all re-split re-replace-all re-pattern re-drop
85+
regex.core :refer $ re-matches re-find-index re-find re-find-all re-split re-replace-all re-pattern re-drop hold-patterns-memory!
7986
regex.$meta :refer $ calcit-dirname calcit-filename
8087
|regex.util $ %{} :FileEntry
8188
:defs $ {}

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ pub fn abi_version() -> String {
1616
String::from("0.0.8")
1717
}
1818

19+
/// just call mem::forget to avoid GC
20+
#[no_mangle]
21+
pub fn holding_patterns_memory() -> Result<Edn, String> {
22+
let patterns = PATTERNS.lock().unwrap();
23+
let data = patterns.to_owned();
24+
std::mem::forget(data);
25+
Ok(Edn::Nil)
26+
}
27+
1928
#[no_mangle]
2029
pub fn re_pattern(args: Vec<Edn>) -> Result<Edn, String> {
2130
if args.len() == 1 {
@@ -47,6 +56,7 @@ pub fn re_drop(args: Vec<Edn>) -> Result<Edn, String> {
4756
let mut patterns = PATTERNS.lock().unwrap();
4857
let mut i = 0;
4958
let mut found = false;
59+
println!("patterns size {}", patterns.len());
5060
for v in patterns.iter() {
5161
if v == p {
5262
found = true;

0 commit comments

Comments
 (0)