Skip to content

Commit

Permalink
[CN-Exec] Minor changes to runtime library to accomodate testing (#542)
Browse files Browse the repository at this point in the history
* [CN-Exec] Runtime library include guards

* [CN-Exec] C++ header compatibility

* [CN-Exec] Allow setting exit callback

* [CN-Exec] Make `cn_exit` static
  • Loading branch information
ZippeyKeys12 authored Aug 30, 2024
1 parent e33539d commit 5f6325a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
13 changes: 13 additions & 0 deletions runtime/libcn/include/cn-executable/alloc.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#ifndef CN_ALLOC
#define CN_ALLOC

#ifdef __cplusplus
extern "C" {
#endif

// enum CNTYPE {
// NODE_CN,
// SEQ,
Expand All @@ -16,3 +23,9 @@ void *alloc_(long nbytes, const char *, int);


// void *alloc_zeros(long nbytes);

#ifdef __cplusplus
}
#endif

#endif // CN_ALLOC
13 changes: 13 additions & 0 deletions runtime/libcn/include/cn-executable/hash_table.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef CN_HASH_TABLE
#define CN_HASH_TABLE

/*
MIT License
Expand Down Expand Up @@ -27,6 +30,10 @@ SOFTWARE.
#include <stdbool.h>
#include <cn-executable/alloc.h>

#ifdef __cplusplus
extern "C" {
#endif

// Hash table entry (slot may be filled or empty).
typedef struct {
signed long *key; // key is NULL if this slot is empty
Expand Down Expand Up @@ -65,3 +72,9 @@ typedef struct {
hash_table_iterator ht_iterator(hash_table* table);

_Bool ht_next(hash_table_iterator* it);

#ifdef __cplusplus
}
#endif

#endif // CN_HASH_TABLE
10 changes: 10 additions & 0 deletions runtime/libcn/include/cn-executable/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <cn-executable/alloc.h>
#include <cn-executable/hash_table.h>

#ifdef __cplusplus
extern "C" {
#endif

struct cn_error_message_info {
const char *function_name;
Expand Down Expand Up @@ -109,6 +112,9 @@ void cn_free_sized(void*, size_t len);
void cn_print_nr_u64(int i, unsigned long u) ;
void cn_print_u64(const char *str, unsigned long u) ;

/* cn_exit callbacks */
void set_cn_exit_cb(void (*callback)(void));
void reset_cn_exit_cb(void);

/* Conversion functions */

Expand Down Expand Up @@ -559,4 +565,8 @@ static inline void cn_postfix(void *ptr, size_t size)
(*__tmp) OP; \
})

#ifdef __cplusplus
}
#endif

#endif // CN_UTILS
10 changes: 9 additions & 1 deletion runtime/libcn/src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ void cn_exit_aux(void) {
exit(SIGABRT);
}

void (*cn_exit)(void) = &cn_exit_aux;
void static (*cn_exit)(void) = &cn_exit_aux;

void set_cn_exit_cb(void (*callback)(void)) {
cn_exit = callback;
}

void reset_cn_exit_cb(void) {
cn_exit = &cn_exit_aux;
}

void print_error_msg_info(void) {
printf("Function: %s, %s:%d\n", error_msg_info.function_name, error_msg_info.file_name, error_msg_info.line_number);
Expand Down

0 comments on commit 5f6325a

Please sign in to comment.