Skip to content

Commit

Permalink
various corrections and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Dec 23, 2024
1 parent f4497ec commit 7351916
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ endif()

project(
raii
VERSION 1.3.3
VERSION 1.3.4
DESCRIPTION "An general RAII implementation for C, with Defer, simple high-level C11/C++11 like Threading/Futures, custom malloc/heap allocation."
HOMEPAGE_URL "https://zelang-dev.github.io/c-raii/"
LANGUAGES C
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,12 @@ C_API void thrd_destroy(future_t);
C_API bool thrd_is_finish(future_t);

/**
* Creates an scoped `vector/array/container` for arbitrary arguments passing into an single `paramater` function.
* Creates an scoped `vector/array/container` for arbitrary arguments passing
* into an single `parameter` function.
* - Use standard `array access` for retrieval of an `union` storage type.
*
* - MUST CALL `args_destructor_set()` to have memory auto released
* within ~callers~ current scoped `context`, will happen either at return/exist or panics.
* within ~callers~ scoped `context`, will happen either at return/exist or panics.
*
* - OTHERWISE `memory leak` will be shown in DEBUG build.
*
Expand All @@ -352,6 +353,21 @@ C_API bool thrd_is_finish(future_t);
*/
C_API args_t args_for(size_t, ...);

/**
* Creates an scoped `vector/array/container` for arbitrary arguments passing
* into an single `parameter` function.
* - Use standard `array access` for retrieval of an `union` storage type.
*
* - MUST CALL `args_deferred_set` to have memory auto released
* when given `scope` context return/exist or panics.
*
* - OTHERWISE `memory leak` will be shown in DEBUG build.
*
* @param count numbers of parameters, `0` will create empty `vector/array`.
* @param arguments indexed in given order.
*/
C_API args_t args_for_ex(memory_t *, size_t, ...);

#define array(count, ...) args_for(count, __VA_ARGS__)
#define array_defer(arr) args_destructor_set(arr)
#define vectorize(vec) vectors_t vec = vector_variant()
Expand Down
20 changes: 18 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,12 @@ C_API void thrd_destroy(future_t);
C_API bool thrd_is_finish(future_t);

/**
* Creates an scoped `vector/array/container` for arbitrary arguments passing into an single `paramater` function.
* Creates an scoped `vector/array/container` for arbitrary arguments passing
* into an single `paramater` function.
* - Use standard `array access` for retrieval of an `union` storage type.
*
* - MUST CALL `args_destructor_set()` to have memory auto released
* within ~callers~ current scoped `context`, will happen either at return/exist or panics.
* within ~callers~ scoped `context`, will happen either at return/exist or panics.
*
* - OTHERWISE `memory leak` will be shown in DEBUG build.
*
Expand All @@ -347,6 +348,21 @@ C_API bool thrd_is_finish(future_t);
*/
C_API args_t args_for(size_t, ...);

/**
* Creates an scoped `vector/array/container` for arbitrary arguments passing
* into an single `paramater` function.
* - Use standard `array access` for retrieval of an `union` storage type.
*
* - MUST CALL `args_deferred_set` to have memory auto released
* when given `scope` context return/exist or panics.
*
* - OTHERWISE `memory leak` will be shown in DEBUG build.
*
* @param count numbers of parameters, `0` will create empty `vector/array`.
* @param arguments indexed in given order.
*/
C_API args_t args_for_ex(memory_t *, size_t, ...);

#define array(count, ...) args_for(count, __VA_ARGS__)
#define array_defer(arr) args_destructor_set(arr)
#define vectorize(vec) vectors_t vec = vector_variant()
Expand Down
22 changes: 19 additions & 3 deletions include/raii.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,12 @@ C_API memory_t *vector_scope(vectors_t);
C_API void vector_push_back(vectors_t, void_t);

/**
* Creates an scoped `vector/array/container` for arbitrary arguments passing into an single `paramater` function.
* Creates an scoped `vector/array/container` for arbitrary arguments passing
* into an single `paramater` function.
* - Use standard `array access` for retrieval of an `union` storage type.
*
* - MUST CALL `args_destructor_set()` to have memory auto released
* within ~callers~ current scoped `context`, will happen either at return/exist or panics.
* within ~callers~ scoped `context`, will happen either at return/exist or panics.
*
* - OTHERWISE `memory leak` will be shown in DEBUG build.
*
Expand All @@ -574,8 +575,23 @@ C_API void vector_push_back(vectors_t, void_t);
* @param arguments indexed in given order.
*/
C_API args_t args_for(size_t, ...);

/**
* Creates an scoped `vector/array/container` for arbitrary arguments passing
* into an single `paramater` function.
* - Use standard `array access` for retrieval of an `union` storage type.
*
* - MUST CALL `args_deferred_set` to have memory auto released
* when given `scope` context return/exist or panics.
*
* - OTHERWISE `memory leak` will be shown in DEBUG build.
*
* @param count numbers of parameters, `0` will create empty `vector/array`.
* @param arguments indexed in given order.
*/
C_API args_t args_for_ex(memory_t *, size_t, ...);

C_API void args_destructor_set(args_t);
C_API args_t args_for_ex(memory_t *, size_t count, ...);
C_API void args_deferred_set(args_t, memory_t *);
C_API void args_returning_set(args_t);
C_API bool is_args(args_t);
Expand Down
7 changes: 5 additions & 2 deletions tests/test-args_for.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ int some_args(args_t args) {
}

TEST(args_for) {
args_t d = args_for(3, "hello", "world", 32);
args_destructor_set(d);
memory_t *s = unique_init();
args_t d = args_for_ex(s, 3, "hello", "world", 32);
args_deferred_set(d, s);
_defer(raii_delete, s);

string arg1 = d[0].char_ptr;
string arg2 = d[1].char_ptr;
int num = d[2].integer;
Expand Down

0 comments on commit 7351916

Please sign in to comment.