Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions include/c2pa.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,6 @@ struct C2paReader *c2pa_reader_from_stream(const char *format,
* Reads from NULL-terminated C strings.
* The returned value MUST be released by calling c2pa_reader_free
* and it is no longer valid after that call.
*
* # Example
* ```c
* auto result = c2pa_reader_from_manifest_data_and_stream(manifest_data, manifest_data_size, "image/jpeg", stream);
* if (result == NULL) {
* let error = c2pa_error();
* printf("Error: %s\n", error);
* c2pa_string_free(error);
* }
* ```
*/
C2PA_API extern
struct C2paReader *c2pa_reader_from_manifest_data_and_stream(const char *format,
Expand Down
40 changes: 18 additions & 22 deletions src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ pub struct C2paSigner {
// Null check macro for C pointers.
#[macro_export]
macro_rules! null_check {
($ptr : expr) => {
if $ptr.is_null() {
Error::set_last(Error::NullParameter(stringify!($ptr).to_string()));
return std::ptr::null_mut();
}
};
(($ptr:expr), $transform:expr, $default:expr) => {
if $ptr.is_null() {
Error::set_last(Error::NullParameter(stringify!($ptr).to_string()));
Expand All @@ -96,6 +102,18 @@ macro_rules! null_check_int {
};
}

/// If the expression is null, set the last error and return std::ptr::null_mut().
#[macro_export]
macro_rules! from_cstr_or_return_null {
($ptr : expr) => {
null_check!(
($ptr),
|ptr| { std::ffi::CStr::from_ptr(ptr).to_string_lossy().into_owned() },
std::ptr::null_mut()
)
};
}

// Internal routine to convert a *const c_char to a rust String or return a NULL error.
#[macro_export]
macro_rules! from_cstr_null_check {
Expand Down Expand Up @@ -170,18 +188,6 @@ macro_rules! return_boxed {
};
}

/// If the expression is null, set the last error and return std::ptr::null_mut().
#[macro_export]
macro_rules! from_cstr_or_return_null {
($ptr : expr) => {
null_check!(
($ptr),
|ptr| { std::ffi::CStr::from_ptr(ptr).to_string_lossy().into_owned() },
std::ptr::null_mut()
)
};
}

/// Defines a callback to read from a stream.
///
/// # Parameters
Expand Down Expand Up @@ -478,16 +484,6 @@ pub unsafe extern "C" fn c2pa_reader_from_stream(
/// Reads from NULL-terminated C strings.
/// The returned value MUST be released by calling c2pa_reader_free
/// and it is no longer valid after that call.
///
/// # Example
/// ```c
/// auto result = c2pa_reader_from_manifest_data_and_stream(manifest_data, manifest_data_size, "image/jpeg", stream);
/// if (result == NULL) {
/// let error = c2pa_error();
/// printf("Error: %s\n", error);
/// c2pa_string_free(error);
/// }
/// ```
#[no_mangle]
pub unsafe extern "C" fn c2pa_reader_from_manifest_data_and_stream(
format: *const c_char,
Expand Down