@@ -16,6 +16,17 @@ pub struct Arg {
1616 pub json_value : serde_json:: Value ,
1717}
1818
19+ // Freeing from the caller side crashes the runtime with jemalloc enabled (EXIT CODE 11 SEGFAULT)
20+ #[ unsafe( no_mangle) ]
21+ pub extern "C" fn free_cstr ( string : * mut c_char ) -> ( ) {
22+ if string. is_null ( ) {
23+ return ;
24+ }
25+ unsafe {
26+ let _ = CString :: from_raw ( string) ;
27+ }
28+ }
29+
1930#[ unsafe( no_mangle) ]
2031pub extern "C" fn run_duckdb_ffi (
2132 query_block_list : * const * const c_char ,
@@ -289,11 +300,11 @@ fn row_to_value(row: &Row<'_>, column_names: &[String]) -> Result<Box<RawValue>,
289300 duckdb:: types:: Value :: UBigInt ( u) => serde_json:: Value :: Number ( u. into ( ) ) ,
290301 duckdb:: types:: Value :: Float ( f) => serde_json:: Value :: Number (
291302 serde_json:: Number :: from_f64 ( f as f64 )
292- . ok_or_else ( || ( "Could not convert to f64" . to_string ( ) ) ) ?,
303+ . ok_or_else ( || "Could not convert to f64" . to_string ( ) ) ?,
293304 ) ,
294305 duckdb:: types:: Value :: Double ( f) => serde_json:: Value :: Number (
295306 serde_json:: Number :: from_f64 ( f)
296- . ok_or_else ( || ( "Could not convert to f64" . to_string ( ) ) ) ?,
307+ . ok_or_else ( || "Could not convert to f64" . to_string ( ) ) ?,
297308 ) ,
298309 duckdb:: types:: Value :: Decimal ( d) => serde_json:: Value :: String ( d. to_string ( ) ) ,
299310 duckdb:: types:: Value :: Timestamp ( _, ts) => serde_json:: Value :: String ( ts. to_string ( ) ) ,
@@ -401,7 +412,7 @@ fn json_value_to_duckdb_value(
401412 "double" | "float8" => duckdb:: types:: Value :: Double ( v) ,
402413 "decimal" | "numeric" => duckdb:: types:: Value :: Decimal (
403414 Decimal :: from_f64 ( v)
404- . ok_or_else ( || ( "Could not convert f64 to Decimal" . to_string ( ) ) ) ?,
415+ . ok_or_else ( || "Could not convert f64 to Decimal" . to_string ( ) ) ?,
405416 ) ,
406417 _ => duckdb:: types:: Value :: Double ( v) , // default fallback
407418 }
@@ -436,7 +447,7 @@ fn string_to_duckdb_timestamp(s: &str) -> Result<duckdb::types::Value, String> {
436447fn string_to_duckdb_date ( s : & str ) -> Result < duckdb:: types:: Value , String > {
437448 use chrono:: Datelike ;
438449 let date = chrono:: NaiveDate :: parse_from_str ( s, "%Y-%m-%d" )
439- . map_err ( |e| ( format ! ( "Invalid date format: {}" , e) ) ) ?;
450+ . map_err ( |e| format ! ( "Invalid date format: {}" , e) ) ?;
440451 Ok ( duckdb:: types:: Value :: Date32 ( date. num_days_from_ce ( ) ) )
441452}
442453
0 commit comments