Skip to content

Commit

Permalink
Change `zarrs{LastError,ArrayGetMetadataString,ArrayGetAttributesStri…
Browse files Browse the repository at this point in the history
…ng}` to return non-const pointers
  • Loading branch information
LDeakin committed Aug 12, 2024
1 parent 4610993 commit 78c8ebf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Bump `cbindgen` to 0.27
- Change `zarrs{LastError,ArrayGetMetadataString,ArrayGetAttributesString}` to return non-const pointers

### Fixed
- Bump MSRV to 1.75 (needed since 0.6.1)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zarrs_ffi"
description = "FFI bindings for the zarrs crate"
version = "0.8.1"
version = "0.8.2"
authors = ["Lachlan Deakin <ljdgit@gmail.com>"]
edition = "2021"
rust-version = "1.75"
Expand Down
4 changes: 2 additions & 2 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ pub unsafe extern "C" fn zarrsArrayGetSubsetSize(
pub unsafe extern "C" fn zarrsArrayGetMetadataString(
array: ZarrsArray,
pretty: bool,
pMetadataString: *mut *const c_char,
pMetadataString: *mut *mut c_char,
) -> ZarrsResult {
// Validation
if array.is_null() {
Expand Down Expand Up @@ -509,7 +509,7 @@ pub unsafe extern "C" fn zarrsArrayGetMetadataString(
pub unsafe extern "C" fn zarrsArrayGetAttributesString(
array: ZarrsArray,
pretty: bool,
pAttributesString: *mut *const c_char,
pAttributesString: *mut *mut c_char,
) -> ZarrsResult {
// Validation
if array.is_null() {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ pub enum ZarrsResult {
static mut LAST_ERROR: Lazy<String> = Lazy::new(|| "".to_string());

/// Get the last error string.
///
/// The string must be freed with `zarrsFreeString`.
#[no_mangle]
pub extern "C" fn zarrsLastError() -> *const c_char {
pub extern "C" fn zarrsLastError() -> *mut c_char {
let c_str = CString::new(unsafe { LAST_ERROR.as_str() }).unwrap();
c_str.into_raw()
}
Expand Down
12 changes: 5 additions & 7 deletions zarrs.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ extern "C" {
* # Safety
* `array` must be a valid `ZarrsArray` handle.
*/
ZarrsResult zarrsArrayGetAttributesString(ZarrsArray array,
bool pretty,
const char **pAttributesString);
ZarrsResult zarrsArrayGetAttributesString(ZarrsArray array, bool pretty, char **pAttributesString);

/**
* Return the number of chunks in the chunk grid.
Expand Down Expand Up @@ -241,9 +239,7 @@ ZarrsResult zarrsArrayGetInnerChunkShape(ZarrsArray array,
* # Safety
* `array` must be a valid `ZarrsArray` handle.
*/
ZarrsResult zarrsArrayGetMetadataString(ZarrsArray array,
bool pretty,
const char **pMetadataString);
ZarrsResult zarrsArrayGetMetadataString(ZarrsArray array, bool pretty, char **pMetadataString);

/**
* Returns the shape of the array.
Expand Down Expand Up @@ -481,8 +477,10 @@ ZarrsResult zarrsFreeString(char *string);

/**
* Get the last error string.
*
* The string must be freed with `zarrsFreeString`.
*/
const char *zarrsLastError(void);
char *zarrsLastError(void);

/**
* Create a handle to an existing array (read/write capability).
Expand Down

0 comments on commit 78c8ebf

Please sign in to comment.