diff --git a/Cargo.toml b/Cargo.toml index 9b0ffda..2ed15d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "brcode" -version = "1.4.2" +version = "1.4.3" authors = ["Julia Naomi "] edition = "2018" description = "Crate to parse and emit BR Codes" diff --git a/clj-brcode/test/clj_brcode/core_test.clj b/clj-brcode/test/clj_brcode/core_test.clj index ec009fc..ed9a5f3 100644 --- a/clj-brcode/test/clj_brcode/core_test.clj +++ b/clj-brcode/test/clj_brcode/core_test.clj @@ -23,3 +23,22 @@ (testing "biscuit is B8CE" (is (= (crc16-ccitt "biscuit") "B8CE")) (is (= (crc16-ccitt unchecked-code) "AD38")))) + +(deftest drop + (testing "access edn after a drop" + (let [e edn + resp (edn->brcode e)] + (is (= resp code)) + (is (= 1 (get e :payload-version))))) + (testing "access code after crc16" + (let [uc unchecked-code + crc (crc16-ccitt uc) + code (str uc crc) + expect (str unchecked-code "AD38")] + (is (= code expect))) + ) + (testing "access code after drop" + (let [c code + edn (brcode->edn c)] + (is (= 1 (get edn :payload-version))) + (is (= (subs c 0 2) "00"))))) \ No newline at end of file diff --git a/libbrcode.dylib b/libbrcode.dylib new file mode 100755 index 0000000..935d0a7 Binary files /dev/null and b/libbrcode.dylib differ diff --git a/libbrcode.so b/libbrcode.so new file mode 100644 index 0000000..49f9adf Binary files /dev/null and b/libbrcode.so differ diff --git a/src/lib.rs b/src/lib.rs index 488f090..83bc945 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,7 @@ use std::str; fn chars_to_string(pointer: *const c_char) -> String { let slice = unsafe { CStr::from_ptr(pointer).to_bytes() }; + drop(pointer); str::from_utf8(slice).unwrap().to_string() } @@ -40,6 +41,7 @@ fn to_c_char(s: &str) -> *const c_char { let cs = CString::new(s.as_bytes()).unwrap(); let ptr = cs.as_ptr(); mem::forget(cs); + drop(s); ptr } @@ -47,6 +49,7 @@ fn to_c_char(s: &str) -> *const c_char { pub extern "C" fn crc16_ccitt_from_message(message: *const c_char) -> *const c_char { let message_str = chars_to_string(message); let checksum = crc16_ccitt(&message_str); + drop(message_str); to_c_char(&checksum) } @@ -55,6 +58,7 @@ pub extern "C" fn crc16_ccitt_from_message(message: *const c_char) -> *const c_c pub extern "C" fn edn_from_brcode(edn: *const c_char) -> *const c_char { let edn_str = chars_to_string(edn); let brcode = str_to_brcode(&edn_str); + drop(edn); to_c_char(&edn_rs::to_string(brcode)) } @@ -62,7 +66,7 @@ pub extern "C" fn edn_from_brcode(edn: *const c_char) -> *const c_char { pub extern "C" fn edn_to_brcode(edn: *const c_char) -> *const c_char { let edn_str = chars_to_string(edn); let brcode: BrCode = edn_rs::from_str(&edn_str).unwrap(); - + drop(edn); to_c_char(&brcode_to_string(brcode)) } @@ -71,7 +75,7 @@ pub extern "C" fn edn_to_svg_brcode(edn: *const c_char) -> *const c_char { let edn_str = chars_to_string(edn); let brcode: BrCode = edn_rs::from_str(&edn_str).unwrap(); let svg = brcode.to_svg_standard_string(); - + drop(edn); to_c_char(&svg) } @@ -80,6 +84,7 @@ pub extern "C" fn edn_to_svg_file(edn: *const c_char, file_path: *const c_char) let edn_str = chars_to_string(edn); let file_path_str = chars_to_string(file_path); let brcode: BrCode = edn_rs::from_str(&edn_str).unwrap(); + drop(edn); drop(file_path); brcode.to_standard_svg_file(&file_path_str); } @@ -88,6 +93,7 @@ pub extern "C" fn edn_to_svg_file(edn: *const c_char, file_path: *const c_char) pub extern "C" fn json_from_brcode(json: *const c_char) -> *const c_char { let json_str = chars_to_string(json); let brcode = str_to_brcode(&json_str); + drop(json); to_c_char(&serde_json::to_string(&brcode).unwrap_or_else(|_| "error".to_string())) } @@ -95,7 +101,7 @@ pub extern "C" fn json_from_brcode(json: *const c_char) -> *const c_char { pub extern "C" fn json_to_brcode(json: *const c_char) -> *const c_char { let json_str = chars_to_string(json); let brcode: BrCode = serde_json::from_str(&json_str).unwrap(); - + drop(json); to_c_char(&brcode_to_string(brcode)) } @@ -104,7 +110,7 @@ pub extern "C" fn json_to_svg_brcode(json: *const c_char) -> *const c_char { let json_str = chars_to_string(json); let brcode: BrCode = serde_json::from_str(&json_str).unwrap(); let svg = brcode.to_svg_standard_string(); - + drop(json); to_c_char(&svg) } @@ -113,5 +119,6 @@ pub extern "C" fn json_to_svg_file(json: *const c_char, file_path: *const c_char let json_str = chars_to_string(json); let file_path_str = chars_to_string(file_path); let brcode: BrCode = serde_json::from_str(&json_str).unwrap(); + drop(json); drop(file_path); brcode.to_standard_svg_file(&file_path_str); }