MCPcopy Create free account
hub / github.com/KaisenAmin/c_std / tuple_create

Function tuple_create

tuple/tuple.c:46–68  ·  view source on GitHub ↗

* @brief This function allocates memory for a tuple and its elements based on the given size. * Each element is initialized to `NULL`. * * @param size The number of elements the tuple will contain. * @return A pointer to the newly created `Tuple`, or `NULL` if memory allocation fails. * * @note The function will terminate the program if memory allocation fails and `TUPLE_LOGGING_ENABLE` is

Source from the content-addressed store, hash-verified

44 * @note The function will terminate the program if memory allocation fails and `TUPLE_LOGGING_ENABLE` is defined.
45 */
46Tuple* tuple_create(size_t size) {
47 TUPLE_LOG("[tuple_create]: Entering with size: %zu", size);
48
49 Tuple* tuple = (Tuple*)malloc(sizeof(Tuple));
50 if (!tuple) {
51 TUPLE_LOG("[tuple_create]: Error: Memory allocation failed for tuple.");
52 return NULL;
53 }
54
55 tuple->size = size;
56 tuple->elements = NULL;
57 if (size > 0) {
58 tuple->elements = (TupleElement*)calloc(size, sizeof(TupleElement));
59 if (!tuple->elements) {
60 TUPLE_LOG("[tuple_create]: Error: Memory allocation failed for tuple elements.");
61 free(tuple);
62 return NULL;
63 }
64 }
65
66 TUPLE_LOG("[tuple_create]: Tuple created successfully with size %zu.", size);
67 return tuple;
68}
69
70
71/**

Callers 3

tuple_make_tupleFunction · 0.85
tuple_tieFunction · 0.85
tuple_forward_as_tupleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected