Skip to content

Commit

Permalink
fix: pass double ptr to result_from_duckdb_appender
Browse files Browse the repository at this point in the history
this ensures that the pointer is correctly cleared when errors occur
  • Loading branch information
Mause committed Apr 22, 2024
1 parent 4731abb commit badc214
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/appender/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Appender<'_> {
record_batch_to_duckdb_data_chunk(&record_batch, &mut data_chunk).map_err(|_op| Error::AppendError)?;

let rc = unsafe { duckdb_append_data_chunk(self.app, data_chunk.get_ptr()) };
result_from_duckdb_appender(rc, self.app)
result_from_duckdb_appender(rc, &mut self.app)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/appender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Appender<'_> {
params.__bind_in(self)?;
// NOTE: we only check end_row return value
let rc = unsafe { ffi::duckdb_appender_end_row(self.app) };
result_from_duckdb_appender(rc, self.app)
result_from_duckdb_appender(rc, &mut self.app)
}

#[inline]
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Appender<'_> {
pub fn flush(&mut self) -> Result<()> {
unsafe {
let res = ffi::duckdb_appender_flush(self.app);
result_from_duckdb_appender(res, self.app)
result_from_duckdb_appender(res, &mut self.app)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ fn error_from_duckdb_code(code: ffi::duckdb_state, message: Option<String>) -> R

#[cold]
#[inline]
pub fn result_from_duckdb_appender(code: ffi::duckdb_state, mut appender: ffi::duckdb_appender) -> Result<()> {
pub fn result_from_duckdb_appender(code: ffi::duckdb_state, appender: *mut ffi::duckdb_appender) -> Result<()> {
if code == ffi::DuckDBSuccess {
return Ok(());
}
unsafe {
let message = if appender.is_null() {
let message = if (*appender).is_null() {
Some("appender is null".to_string())
} else {
let c_err = ffi::duckdb_appender_error(appender);
let c_err = ffi::duckdb_appender_error(*appender);
let message = Some(CStr::from_ptr(c_err).to_string_lossy().to_string());
ffi::duckdb_appender_destroy(&mut appender);
ffi::duckdb_appender_destroy(appender);
message
};
error_from_duckdb_code(code, message)
Expand Down
2 changes: 1 addition & 1 deletion src/inner_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl InnerConnection {
&mut c_app,
)
};
result_from_duckdb_appender(r, c_app)?;
result_from_duckdb_appender(r, &mut c_app)?;
Ok(Appender::new(conn, c_app))
}

Expand Down

0 comments on commit badc214

Please sign in to comment.