Skip to content

Commit dffe139

Browse files
committed
Major change: C ABI is now thread safe, and protects against bad
bindings!
1 parent eee4cce commit dffe139

File tree

10 files changed

+385
-180
lines changed

10 files changed

+385
-180
lines changed

bindings/headers/imageflow_default.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool imageflow_context_add_input_buffer(struct imageflow_context *context,
6767
// The buffer will be freed with the context.
6868
//
6969
//
70-
// Returns null if allocation failed; check the context for error details.
70+
// Returns false if allocation failed or context is damaged; check the context for error details.
7171
bool imageflow_context_add_output_buffer(struct imageflow_context *context, int32_t io_id);
7272

7373
// Begins the process of destroying the context, yet leaves error information intact
@@ -91,7 +91,7 @@ bool imageflow_context_begin_terminate(struct imageflow_context *context);
9191
//
9292
// Returns a null pointer if allocation fails or the provided interface version is incompatible
9393
struct imageflow_context *imageflow_context_create(uint32_t imageflow_abi_ver_major,
94-
uint32_t imageflow_abi_ver_minor);
94+
uint32_t imageflow_abi_ver_minor);
9595

9696
// Destroys the imageflow context and frees the context object.
9797
// Only use this with contexts created using `imageflow_context_create`
@@ -165,6 +165,7 @@ bool imageflow_context_error_write_to_buffer(struct imageflow_context *context,
165165
//
166166
// Provides access to the underlying buffer for the given io id
167167
//
168+
// Returns false and sets the error if the io id is invalid, the result buffer pointers are null, or the context is damaged.
168169
bool imageflow_context_get_output_buffer_by_id(struct imageflow_context *context,
169170
int32_t io_id,
170171
const uint8_t **result_buffer,

bindings/headers/imageflow_lua.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool imageflow_context_add_input_buffer(struct imageflow_context *context,
6060
// The buffer will be freed with the context.
6161
//
6262
//
63-
// Returns null if allocation failed; check the context for error details.
63+
// Returns false if allocation failed or context is damaged; check the context for error details.
6464
bool imageflow_context_add_output_buffer(struct imageflow_context *context, int32_t io_id);
6565

6666
// Begins the process of destroying the context, yet leaves error information intact
@@ -84,7 +84,7 @@ bool imageflow_context_begin_terminate(struct imageflow_context *context);
8484
//
8585
// Returns a null pointer if allocation fails or the provided interface version is incompatible
8686
struct imageflow_context *imageflow_context_create(uint32_t imageflow_abi_ver_major,
87-
uint32_t imageflow_abi_ver_minor);
87+
uint32_t imageflow_abi_ver_minor);
8888

8989
// Destroys the imageflow context and frees the context object.
9090
// Only use this with contexts created using `imageflow_context_create`
@@ -158,6 +158,7 @@ bool imageflow_context_error_write_to_buffer(struct imageflow_context *context,
158158
//
159159
// Provides access to the underlying buffer for the given io id
160160
//
161+
// Returns false and sets the error if the io id is invalid, the result buffer pointers are null, or the context is damaged.
161162
bool imageflow_context_get_output_buffer_by_id(struct imageflow_context *context,
162163
int32_t io_id,
163164
const uint8_t **result_buffer,

bindings/headers/imageflow_pinvoke.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ bool imageflow_context_add_input_buffer(void *context,
6767
// The buffer will be freed with the context.
6868
//
6969
//
70-
// Returns null if allocation failed; check the context for error details.
70+
// Returns false if allocation failed or context is damaged; check the context for error details.
7171
bool imageflow_context_add_output_buffer(void *context, int32_t io_id);
7272

7373
// Begins the process of destroying the context, yet leaves error information intact
@@ -91,7 +91,7 @@ bool imageflow_context_begin_terminate(void *context);
9191
//
9292
// Returns a null pointer if allocation fails or the provided interface version is incompatible
9393
void *imageflow_context_create(uint32_t imageflow_abi_ver_major,
94-
uint32_t imageflow_abi_ver_minor);
94+
uint32_t imageflow_abi_ver_minor);
9595

9696
// Destroys the imageflow context and frees the context object.
9797
// Only use this with contexts created using `imageflow_context_create`
@@ -165,6 +165,7 @@ bool imageflow_context_error_write_to_buffer(void *context,
165165
//
166166
// Provides access to the underlying buffer for the given io id
167167
//
168+
// Returns false and sets the error if the io id is invalid, the result buffer pointers are null, or the context is damaged.
168169
bool imageflow_context_get_output_buffer_by_id(void *context,
169170
int32_t io_id,
170171
const uint8_t **result_buffer,

bindings/headers/imageflow_short.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ bool imageflow_context_add_output_buffer(void *context, int32_t io_id);
2929
bool imageflow_context_begin_terminate(void *context);
3030

3131
void *imageflow_context_create(uint32_t imageflow_abi_ver_major,
32-
uint32_t imageflow_abi_ver_minor);
32+
uint32_t imageflow_abi_ver_minor);
3333

3434
void imageflow_context_destroy(void *context);
3535

imageflow_abi/build.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ enum StructModification {
101101
//You can specify no prefix..
102102
Prefix { prefix: &'static str, style: Style },
103103
}
104+
fn rename_structs(s: String, pairs: &[(&str, &str)], style: Style) -> String {
105+
let mut temp = s;
106+
for (old_name, new_name) in pairs {
107+
temp = rename_word_excluding_enum_members(temp, old_name, new_name, style);
108+
}
109+
temp
110+
}
104111

105112
fn filter_structs(s: String, names: &[&str], how: StructModification) -> String {
106113
let mut temp = s;
@@ -154,7 +161,8 @@ fn filter_enums<'a, 'b>(s: String, names: &'a [&'a str], how: EnumModification)
154161
}
155162

156163
static ENUM_NAMES: [&str; 4] = ["IoMode", "Direction", "Lifetime", "CleanupWith"];
157-
static STRUCT_NAMES: [&str; 4] = ["Job", "JobIo", "Context", "JsonResponse"];
164+
static STRUCT_NAMES: [&str; 5] = ["Job", "JobIo", "Context", "ThreadSafeContext", "JsonResponse"];
165+
static RENAME_STRUCTS: [(&str, &str); 1] = [("ThreadSafeContext", "Context")];
158166

159167
#[derive(Copy, Clone, PartialEq, Debug)]
160168
enum Target {
@@ -267,7 +275,13 @@ fn generate(target: Target) -> String {
267275

268276
let builder = cbindgen::Builder::new().with_config(config).with_crate(crate_dir);
269277
let s = generate_to_string(builder);
270-
let temp = filter_enums(filter_structs(s, &STRUCT_NAMES, structs), &ENUM_NAMES, enums);
278+
// let rename_style = match structs{
279+
// StructModification::Prefix { style , ..} => style,
280+
// _ => Style::Snake
281+
// };
282+
let renamed = rename_structs(s, &RENAME_STRUCTS, Style::Unchanged);
283+
let temp =
284+
filter_enums(filter_structs(renamed, &STRUCT_NAMES, structs), &ENUM_NAMES, enums);
271285
if no_preprocessor_directives {
272286
strip_preprocessor_directives(&temp)
273287
} else {

0 commit comments

Comments
 (0)