Skip to content

Commit 5a69b08

Browse files
rickrick
rick
authored and
rick
committed
tighten up dependencies
1 parent 5a2c5e7 commit 5a69b08

30 files changed

+541
-56
lines changed

.gitmodules

+9
Original file line numberDiff line numberDiff line change
@@ -961,3 +961,12 @@
961961
[submodule "submodules/c_libmonitors"]
962962
path = submodules/c_libmonitors
963963
url = [email protected]:binRick/c_libmonitors.git
964+
[submodule "submodules/memory_leak_detector"]
965+
path = submodules/memory_leak_detector
966+
url = https://github.com/namantam1/memory-leak-detector
967+
[submodule "submodules/xterm_js"]
968+
path = submodules/xterm_js
969+
url = https://github.com/xtermjs/xterm.js
970+
[submodule "submodules/c_liamloads"]
971+
path = submodules/c_liamloads
972+
url = https://github.com/liamloads/c-liamloads

etc/meson.mk

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
MESON_BUILD_DIR=build
2-
MESON_DEFAULT_BUILD_TYPE=debug
2+
MESON_DEFAULT_BUILD_TYPE=release
33
MESON_DEFAULT_BUILD_TYPE=minsize
4+
MESON_DEFAULT_BUILD_TYPE=debug
45
BUILD_TYPE ?=$(MESON_DEFAULT_BUILD_TYPE)
5-
BUILD_JOBS ?=20
6-
TEST_JOBS ?=10
6+
BUILD_JOBS ?=10
7+
TEST_JOBS ?=3
78
MESON_DEFAULT_LIBRARY ?=static
9+
BUILD_OPTIMIZATION ?=3
810
WARN_LEVEL ?=2
911
MESON_PARALLEL_JOBS=$(BUILD_JOBS)
1012
MESON_BUILD_TYPE=$(BUILD_TYPE)
1113
MESON_SETUP_ARGS=\
14+
--fatal-meson-warnings \
1215
--buildtype $(MESON_BUILD_TYPE) \
1316
--strip \
1417
--default-library $(MESON_DEFAULT_LIBRARY) \
15-
--prefer-static \
1618
--warnlevel $(WARN_LEVEL) \
1719
--backend ninja \
1820
--errorlogs
1921
meson-setup:
20-
@[[ -d $(MESON_BUILD_DIR) ]] && { $(MESON) setup $(MESON_SETUP_ARGS) --reconfigure $(MESON_BUILD_DIR); } || { $(MESON) setup $(MESON_SETUP_ARGS) $(MESON_BUILD_DIR); }
22+
@if [[ -d $(MESON_BUILD_DIR) ]]; then $(MESON) setup $(MESON_SETUP_ARGS) --reconfigure $(MESON_BUILD_DIR); else $(MESON) setup $(MESON_SETUP_ARGS) $(MESON_BUILD_DIR); fi
2123
meson-build: meson-setup
2224
@$(MESON) compile -C $(MESON_BUILD_DIR) -j $(MESON_PARALLEL_JOBS)
23-
do-build: meson-build muon-build
25+
meson-build-retry-clean:
26+
@$(MAKE) meson-build -B || { $(MAKE) clean && $(MAKE) meson-build; }
27+
do-build: meson-build
2428
scan-build:
2529
@env SCANBUILD=$(SCAN_BUILD) ninja -C $(MESON_BUILD_DIR) scan-build
2630
meson-install: do-meson
@@ -32,7 +36,7 @@ meson-test:
3236
@env MESON_TESTTHREADS=$(TEST_JOBS) $(PASSH) $(MESON) test -C $(MESON_BUILD_DIR) --print-errorlogs
3337
test: meson-test muon-test
3438
test-verbose: meson-test-verbose
35-
do-meson: meson-build
39+
do-meson: do-build
3640
meson: do-meson
3741
build: meson muon
3842
all: build test

etc/template-subdir-library_c.j2

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,33 @@
44
#ifndef {{UPPER_LIBRARY_NAME}}_C
55
#define {{UPPER_LIBRARY_NAME}}_C
66
////////////////////////////////////////////
7-
{%if SUBDIR_TEST_DEBUG_MEMORY_ENABLED%}#define DEBUG_MEMORY{%endif%}
8-
////////////////////////////////////////////
97
#include "{{SUBDIR_NAME}}/{{SUBDIR_NAME}}.h"
108
////////////////////////////////////////////
119
{%for i in INCLUDED_HEADERS.split(' ') -%}
1210
#include "{{i}}"
1311
{%endfor%}
1412
////////////////////////////////////////////
15-
static bool {{LIBRARY_NAME}}_DEBUG_MODE = false;
13+
static bool {{UPPER_LIBRARY_NAME}}_DEBUG_MODE = false;
1614
///////////////////////////////////////////////////////////////////////
1715
static void __attribute__((constructor)) __constructor__{{LIBRARY_NAME}}(void){
1816
if (getenv("DEBUG") != NULL || getenv("DEBUG_{{LIBRARY_NAME}}") != NULL) {
1917
log_debug("Enabling {{SUBDIR_NAME}} Debug Mode");
20-
{{LIBRARY_NAME}}_DEBUG_MODE = true;
18+
{{UPPER_LIBRARY_NAME}}_DEBUG_MODE = true;
2119
}
2220
}
2321
static void {{LIBRARY_NAME}}_internal_fxn1(void);
2422
////////////////////////////////////////////
2523
static void {{LIBRARY_NAME}}_internal_fxn1(void){
2624
log_info("Called function {{LIBRARY_NAME}}_internal_fxn1");
27-
if({{LIBRARY_NAME}}_DEBUG_MODE == true){
25+
if({{UPPER_LIBRARY_NAME}}_DEBUG_MODE == true){
2826
log_info("Debug Mode Enabled");
2927
}
3028
}
3129
////////////////////////////////////////////
3230
void {{LIBRARY_NAME}}_fxn1(void){
3331
{{LIBRARY_NAME}}_internal_fxn1();
3432
log_info("Called function {{LIBRARY_NAME}}_fxn1");
35-
if({{LIBRARY_NAME}}_DEBUG_MODE == true){
33+
if({{UPPER_LIBRARY_NAME}}_DEBUG_MODE == true){
3634
log_info("Debug Mode Enabled");
3735
}
3836
}
+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include "ansi-codes/ansi-codes.h"
2+
#include "bytes/bytes.h"
3+
#include "c_fsio/include/fsio.h"
4+
#include "c_greatest/greatest/greatest.h"
5+
#include "c_string_buffer/include/stringbuffer.h"
6+
#include "c_stringfn/include/stringfn.h"
7+
#include "c_vector/vector/vector.h"
8+
#include "iowow-compound-test/iowow-compound-test.h"
9+
#include "log/log.h"
10+
#include "ms/ms.h"
11+
#include "timestamp/timestamp.h"
12+
#include <iowow/iwkv.h>
13+
14+
TEST t_iowow_compound_test2(){
15+
PASS();
16+
}
17+
18+
/// Compound keys demo.
19+
///
20+
/// Compound keys allows associate one `key value` with many references
21+
/// represented as VNUM64 (eg.: Non unique table indexes).
22+
///
23+
/// Compound mainly used for non-unique indexes in ejdb2 database engine:
24+
///
25+
/// `<prefix key value>.<document id>`
26+
TEST t_iowow_compound_test1(){
27+
struct user_s {
28+
uint32_t id;
29+
char *name;
30+
};
31+
32+
struct chat_root_s {
33+
char *name;
34+
struct user_s users[5];
35+
};
36+
37+
static struct chat_root_s rooms[] = {
38+
{
39+
.name = "Meeting room",
40+
.users ={
41+
{ .id = 1, .name = "Joy Lynn" },
42+
{ .id = 2, .name = "Aubrey Sparks" },
43+
{ .id = 3, .name = "Vinnie Kaye" },
44+
{ 0 }
45+
}
46+
},
47+
{
48+
.name = "Webinar room",
49+
.users ={
50+
{ .id = 4, .name = "Arda Payne" },
51+
{ .id = 2, .name = "Joy Lynn" },
52+
{ 0 }
53+
}
54+
}
55+
};
56+
57+
IWKV_OPTS opts = {
58+
.path = "compoundkeys.db",
59+
.oflags = IWKV_TRUNC
60+
};
61+
IWKV iwkv;
62+
IWDB db;
63+
IWKV_cursor cur = 0;
64+
iwrc rc = iwkv_open(&opts, &iwkv);
65+
66+
RCRET(rc);
67+
68+
rc = iwkv_db(iwkv, 1, IWDB_COMPOUND_KEYS, &db);
69+
RCGO(rc, finish);
70+
71+
// Persist all rooms with members
72+
for (int i = 0; i < sizeof(rooms) / sizeof(rooms[0]); ++i) {
73+
int j = 0;
74+
struct chat_root_s *room = &rooms[i];
75+
for (struct user_s *user = &room->users[0]; user->id; user = &room->users[++j]) {
76+
IWKV_val key = { .data = room->name, .size = strlen(room->name), .compound = user->id };
77+
IWKV_val val = { .data = user->name, .size = strlen(user->name) };
78+
RCC(rc, finish, iwkv_put(db, &key, &val, 0));
79+
}
80+
}
81+
82+
// Get specific user from the room
83+
{
84+
IWKV_val key = { .data = "Webinar room", .size = sizeof("Webinar room") - 1, .compound = 2 };
85+
IWKV_val val;
86+
RCC(rc, finish, iwkv_get(db, &key, &val));
87+
fprintf(stdout, "\n>>>> Found: '%.*s' in room '%s' by id: %d\n",
88+
(int)val.size, (char *)val.data,
89+
(char *)key.data, (int)key.compound);
90+
iwkv_val_dispose(&val);
91+
}
92+
93+
// Iterate over all members in `Meeting room`
94+
{
95+
size_t len = strlen(rooms[0].name);
96+
fprintf(stdout, "\n>>>> Iterate over all members in %s\n", rooms[0].name);
97+
IWKV_val val, key = { .data = rooms[0].name, .size = len };
98+
RCC(rc, finish, iwkv_cursor_open(db, &cur, IWKV_CURSOR_GE, &key));
99+
do {
100+
RCC(rc, finish, iwkv_cursor_get(cur, &key, &val));
101+
if (memcmp(key.data, rooms[0].name, MIN(key.size, len))) {
102+
// We rolled to end of `Meeting room` room
103+
iwkv_kv_dispose(&key, &val);
104+
break;
105+
}
106+
fprintf(stdout, "%.*s: %d %.*s\n",
107+
(int)key.size, (char *)key.data,
108+
(int)key.compound,
109+
(int)val.size,
110+
(char *)val.data);
111+
iwkv_kv_dispose(&key, &val);
112+
} while ((rc = iwkv_cursor_to(cur, IWKV_CURSOR_PREV)) == 0);
113+
rc = 0;
114+
}
115+
116+
finish:
117+
if (cur) {
118+
iwkv_cursor_close(&cur);
119+
}
120+
iwkv_close(&iwkv);
121+
122+
PASS();
123+
} /* t_iowow_compound_test1 */
124+
125+
SUITE(s_iowow_compound_test) {
126+
RUN_TEST(t_iowow_compound_test1);
127+
if (isatty(STDOUT_FILENO)) {
128+
RUN_TEST(t_iowow_compound_test2);
129+
}
130+
}
131+
132+
GREATEST_MAIN_DEFS();
133+
134+
int main(int argc, char **argv) {
135+
GREATEST_MAIN_BEGIN();
136+
RUN_SUITE(s_iowow_compound_test);
137+
GREATEST_MAIN_END();
138+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
#ifndef IOWOW_COMPOUND_TEST_H
3+
#define IOWOW_COMPOUND_TEST_H
4+
//////////////////////////////////////
5+
#include <ctype.h>
6+
#include <errno.h>
7+
#include <inttypes.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
#include <unistd.h>
12+
//////////////////////////////////////
13+
14+
#endif

iowow-compound-test/meson.build

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
iowow_compound_test_srcs = [
2+
'iowow-compound-test.c',
3+
]
4+
inc = get_variable('inc', join_paths(meson.current_source_dir(),'..'))
5+
iowow_compound_test_include_dirs = [
6+
'.',
7+
inc,
8+
]
9+
iowow_compound_test_deps = [
10+
c_greatest_dep,
11+
ansi_codes_dep,
12+
iowow_dep,
13+
c_vector_dep,
14+
c_fsio_dep,
15+
c_stringfn_dep,
16+
c_string_buffer_dep,
17+
timestamp_dep,
18+
log_dep,
19+
ms_dep,
20+
bytes_dep,
21+
]
22+
iowow_compound_test_c_args = [
23+
]
24+
iowow_compound_test_link_args = [
25+
]
26+
27+
iowow_compound_test_test_dir = join_paths(meson.current_source_dir(), '..')
28+
29+
if get_option('enable-binaries')
30+
iowow_compound_test_exec = executable('iowow-compound-test',
31+
iowow_compound_test_srcs,
32+
dependencies: iowow_compound_test_deps,
33+
include_directories: iowow_compound_test_include_dirs,
34+
link_args: iowow_compound_test_link_args,
35+
c_args: iowow_compound_test_c_args,
36+
install: false,
37+
)
38+
#test('iowow-compound-test',
39+
# iowow_compound_test_exec, args: ['-v','-a'],
40+
# workdir: iowow_compound_test_test_dir,
41+
#)
42+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
#include "ansi-codes/ansi-codes.h"
3+
#include "bytes/bytes.h"
4+
#include "c_fsio/include/fsio.h"
5+
#include "c_greatest/greatest/greatest.h"
6+
#include "c_string_buffer/include/stringbuffer.h"
7+
#include "c_stringfn/include/stringfn.h"
8+
#include "c_vector/vector/vector.h"
9+
#include "log/log.h"
10+
#include "memory-leak-detector-test/memory-leak-detector-test.h"
11+
#include "memory_leak_detector/leak.h"
12+
#include "ms/ms.h"
13+
#include "timestamp/timestamp.h"
14+
15+
TEST t_memory_leak_detector_test2(){
16+
PASS();
17+
}
18+
19+
TEST t_memory_leak_detector_test1(){
20+
char *a = malloc(100);
21+
22+
free(a);
23+
24+
char *b = malloc(120);
25+
// forget to free //--> LEAK (120)
26+
27+
char *c = calloc(10, 8);
28+
29+
// refrence to memory lost
30+
c = malloc(10); //--> LEAK (10 * 8)
31+
32+
char *d = realloc(c, 15); // Here memory will be free first
33+
34+
free(d);
35+
PASS();
36+
}
37+
38+
SUITE(s_memory_leak_detector_test) {
39+
RUN_TEST(t_memory_leak_detector_test1);
40+
if (isatty(STDOUT_FILENO)) {
41+
RUN_TEST(t_memory_leak_detector_test2);
42+
}
43+
}
44+
45+
GREATEST_MAIN_DEFS();
46+
47+
int main(int argc, char **argv) {
48+
GREATEST_MAIN_BEGIN();
49+
RUN_SUITE(s_memory_leak_detector_test);
50+
GREATEST_MAIN_END();
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
#ifndef MEMORY_LEAK_DETECTOR_TEST_H
3+
#define MEMORY_LEAK_DETECTOR_TEST_H
4+
//////////////////////////////////////
5+
#include <ctype.h>
6+
#include <errno.h>
7+
#include <inttypes.h>
8+
#include <stdio.h>
9+
#include <stdlib.h>
10+
#include <string.h>
11+
#include <unistd.h>
12+
//////////////////////////////////////
13+
14+
#endif

0 commit comments

Comments
 (0)