Compare commits
7 Commits
v1.0.3
..
2e5163ba33
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e5163ba33 | |||
| 515493b963 | |||
| 8061692801 | |||
| 70997f091f | |||
| f61cb3cae0 | |||
| 946bcc9b59 | |||
| 7ffebe7dce |
@@ -153,7 +153,7 @@ builddir:
|
|||||||
@mkdir -p "$(BUILD_DIR)"
|
@mkdir -p "$(BUILD_DIR)"
|
||||||
|
|
||||||
build-c-test:
|
build-c-test:
|
||||||
$(CC) $(CSTD) $(CFLAGS) $(BUILD_FLAGS) $(TEST_INCLUDE) $(TEST_C_SRC) -o "$(TEST_C_OUT)"
|
bear -- $(CC) $(CSTD) $(CFLAGS) $(BUILD_FLAGS) $(TEST_INCLUDE) $(TEST_C_SRC) -o "$(TEST_C_OUT)"
|
||||||
|
|
||||||
run-c-test: build-c-test
|
run-c-test: build-c-test
|
||||||
@echo -e "\n\033[34;1mRUNNING C TESTS\033[0m"
|
@echo -e "\n\033[34;1mRUNNING C TESTS\033[0m"
|
||||||
@@ -161,7 +161,7 @@ run-c-test: build-c-test
|
|||||||
@rm "$(TEST_C_OUT)"
|
@rm "$(TEST_C_OUT)"
|
||||||
|
|
||||||
build-cc-test:
|
build-cc-test:
|
||||||
$(CXX) $(CXXSTD) $(CFLAGS) $(BUILD_FLAGS) $(TEST_INCLUDE) $(TEST_CXX_SRC) "$(LIB_OUT)" -o "$(TEST_CXX_OUT)"
|
bear -a -- $(CXX) $(CXXSTD) $(CFLAGS) $(BUILD_FLAGS) $(TEST_INCLUDE) $(TEST_CXX_SRC) "$(LIB_OUT)" -o "$(TEST_CXX_OUT)"
|
||||||
|
|
||||||
run-cc-test: build-cc-test
|
run-cc-test: build-cc-test
|
||||||
@echo -e "\n\033[34;1mRUNNING C++ TESTS\033[0m"
|
@echo -e "\n\033[34;1mRUNNING C++ TESTS\033[0m"
|
||||||
@@ -175,6 +175,6 @@ install: build-lib
|
|||||||
@bash $(HEADER_INSTALL_CMD) $(LIB_SRC) "$(INCLUDE_INSTALL)" $(INCLUDES)
|
@bash $(HEADER_INSTALL_CMD) $(LIB_SRC) "$(INCLUDE_INSTALL)" $(INCLUDES)
|
||||||
|
|
||||||
build-lib: builddir
|
build-lib: builddir
|
||||||
$(CC) -c $(CSTD) $(CFLAGS) $(BUILD_FLAGS) $(LIBFLAGS) $(LIB_SRC) -o "$(OBJ_OUT)"
|
bear -a -- $(CC) -c $(CSTD) $(CFLAGS) $(BUILD_FLAGS) $(LIBFLAGS) $(LIB_SRC) -o "$(OBJ_OUT)"
|
||||||
$(AR) r "$(LIB_OUT)" "$(OBJ_OUT)"
|
$(AR) r "$(LIB_OUT)" "$(OBJ_OUT)"
|
||||||
@rm "$(OBJ_OUT)"
|
@rm "$(OBJ_OUT)"
|
||||||
|
|||||||
@@ -55,4 +55,4 @@ if ! contains ${BUILD_TYPE} "${ACCEPTED_BUILD_TYPES[@]}"; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bear -- make BUILD_TYPE=$BUILD_TYPE $ARGS
|
make BUILD_TYPE=$BUILD_TYPE $ARGS
|
||||||
|
|||||||
+25
-2
@@ -30,7 +30,10 @@ GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue,
|
|||||||
GenericQueue *output = queue;
|
GenericQueue *output = queue;
|
||||||
|
|
||||||
u64 capacity = wapp_array_capacity(queue->items);
|
u64 capacity = wapp_array_capacity(queue->items);
|
||||||
if (queue->count >= capacity) {
|
|
||||||
|
// NOTE (Abdelrahman): Extracted into variable to fix MSVC error
|
||||||
|
b8 queue_full = queue->count >= capacity;
|
||||||
|
if (queue_full) {
|
||||||
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(capacity * 2);
|
u64 new_capacity = wapp_misc_utils_u64_round_up_pow2(capacity * 2);
|
||||||
u64 array_size = _array_calc_alloc_size(new_capacity, item_size);
|
u64 array_size = _array_calc_alloc_size(new_capacity, item_size);
|
||||||
u64 alloc_size = sizeof(GenericQueue) + array_size;
|
u64 alloc_size = sizeof(GenericQueue) + array_size;
|
||||||
@@ -51,7 +54,27 @@ GenericQueue *_queue_push_alloc(const Allocator *allocator, GenericQueue *queue,
|
|||||||
void *copy_boundary = (void *)((uptr)(queue->items) + (queue->front * item_size));
|
void *copy_boundary = (void *)((uptr)(queue->items) + (queue->front * item_size));
|
||||||
|
|
||||||
memcpy(output->items, copy_boundary, front_count * item_size);
|
memcpy(output->items, copy_boundary, front_count * item_size);
|
||||||
if (back_count > 0) {
|
|
||||||
|
/**
|
||||||
|
* NOTE (Abdelrahman): Since this is a ring buffer, the elements at the beginning of the array
|
||||||
|
* aren't always the ones at the front of the queue. When that's the case, the memcpy above
|
||||||
|
* will only copy a subset of the elements. This is why we need to copy the remaining ones.
|
||||||
|
*
|
||||||
|
* Example: Take a queue that looks like this with a capacity of 5 elements
|
||||||
|
*
|
||||||
|
* 0 1 | 2 3 4
|
||||||
|
* ---------------|-----------------------
|
||||||
|
* | * | * | * | * | * |
|
||||||
|
* ---------------|-----------------------
|
||||||
|
* |
|
||||||
|
* queue_front = 2
|
||||||
|
* queue_back = 2
|
||||||
|
*
|
||||||
|
* In this case, the first memcpy will only copy elements 2-4. The memcpy below will be
|
||||||
|
* responsible for copying elements 0-1.
|
||||||
|
*/
|
||||||
|
b8 items_left_to_copy = back_count > 0;
|
||||||
|
if (items_left_to_copy) {
|
||||||
void *back_copy_dst = (void *)((uptr)(output->items) + (front_count * item_size));
|
void *back_copy_dst = (void *)((uptr)(output->items) + (front_count * item_size));
|
||||||
memcpy(back_copy_dst, queue->items, back_count * item_size);
|
memcpy(back_copy_dst, queue->items, back_count * item_size);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ typedef intptr_t iptr;
|
|||||||
|
|
||||||
#ifdef WAPP_PLATFORM_CPP
|
#ifdef WAPP_PLATFORM_CPP
|
||||||
#define wapp_class_mem static
|
#define wapp_class_mem static
|
||||||
#define BEGIN_C_LINKAGE extern "C" {
|
#define BEGIN_C_LINKAGE wapp_extern "C" {
|
||||||
#define END_C_LINKAGE }
|
#define END_C_LINKAGE }
|
||||||
#endif // WAPP_PLATFORM_CPP
|
#endif // WAPP_PLATFORM_CPP
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
#endif // !WAPP_PLATFORM_CPP
|
#endif // !WAPP_PLATFORM_CPP
|
||||||
|
|
||||||
#define wapp_static_assert(EXPR, MSG) extern char ASSERTION_FAILED[EXPR ? 1 : -1]
|
#define wapp_static_assert(EXPR, MSG) wapp_extern char ASSERTION_FAILED[EXPR ? 1 : -1]
|
||||||
|
|
||||||
#ifndef WAPP_NO_RUNTIME_ASSERT
|
#ifndef WAPP_NO_RUNTIME_ASSERT
|
||||||
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
|
#define wapp_runtime_assert(EXPR, MSG) __wapp_runtime_assert(EXPR, MSG)
|
||||||
|
|||||||
+11
-8
@@ -34,6 +34,9 @@ typedef enum {
|
|||||||
FILE_SEEK_ORIGIN_COUNT,
|
FILE_SEEK_ORIGIN_COUNT,
|
||||||
} FileSeekOrigin;
|
} FileSeekOrigin;
|
||||||
|
|
||||||
|
wapp_extern WFile *wapp_file_stdin(void);
|
||||||
|
wapp_extern WFile *wapp_file_stdout(void);
|
||||||
|
wapp_extern WFile *wapp_file_stderr(void);
|
||||||
WFile *wapp_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode);
|
WFile *wapp_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode);
|
||||||
i64 wapp_file_get_current_position(WFile *file);
|
i64 wapp_file_get_current_position(WFile *file);
|
||||||
i64 wapp_file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
|
i64 wapp_file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
|
||||||
@@ -47,14 +50,14 @@ i32 wapp_file_close(WFile *file);
|
|||||||
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
|
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
|
||||||
i32 wapp_file_remove(Str8RO *filepath);
|
i32 wapp_file_remove(Str8RO *filepath);
|
||||||
|
|
||||||
extern WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode);
|
wapp_extern WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode);
|
||||||
extern i64 _file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
|
wapp_extern i64 _file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
|
||||||
extern u64 _file_read(void *dst_buf, u64 byte_count, WFile *file, u64 file_length);
|
wapp_extern u64 _file_read(void *dst_buf, u64 byte_count, WFile *file, u64 file_length);
|
||||||
extern i64 _file_write(const void *src_buf, WFile *file, u64 byte_count);
|
wapp_extern i64 _file_write(const void *src_buf, WFile *file, u64 byte_count);
|
||||||
extern i32 _file_flush(WFile *file);
|
wapp_extern i32 _file_flush(WFile *file);
|
||||||
extern i32 _file_close(WFile *file);
|
wapp_extern i32 _file_close(WFile *file);
|
||||||
extern i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
|
wapp_extern i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
|
||||||
extern i32 _file_remove(Str8RO *filepath);
|
wapp_extern i32 _file_remove(Str8RO *filepath);
|
||||||
|
|
||||||
#ifdef WAPP_PLATFORM_CPP
|
#ifdef WAPP_PLATFORM_CPP
|
||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
|
|||||||
@@ -49,6 +49,21 @@ wapp_intern i32 file_seek_origins[FILE_SEEK_ORIGIN_COUNT] = {
|
|||||||
[WAPP_SEEK_END] = SEEK_END,
|
[WAPP_SEEK_END] = SEEK_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WFile *wapp_file_stdin(void) {
|
||||||
|
wapp_persist WFile _stdin = { .fd = STDIN_FILENO };
|
||||||
|
return &_stdin;
|
||||||
|
}
|
||||||
|
|
||||||
|
WFile *wapp_file_stdout(void) {
|
||||||
|
wapp_persist WFile _stdout = { .fd = STDOUT_FILENO };
|
||||||
|
return &_stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
WFile *wapp_file_stderr(void) {
|
||||||
|
wapp_persist WFile _stderr = { .fd = STDERR_FILENO };
|
||||||
|
return &_stderr;
|
||||||
|
}
|
||||||
|
|
||||||
WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
|
WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
|
||||||
wapp_persist c8 tmp[WAPP_PATH_MAX] = {0};
|
wapp_persist c8 tmp[WAPP_PATH_MAX] = {0};
|
||||||
memset(tmp, 0, WAPP_PATH_MAX);
|
memset(tmp, 0, WAPP_PATH_MAX);
|
||||||
|
|||||||
@@ -54,6 +54,24 @@ wapp_intern DWORD file_seek_origins[FILE_SEEK_ORIGIN_COUNT] = {
|
|||||||
[WAPP_SEEK_END] = FILE_END,
|
[WAPP_SEEK_END] = FILE_END,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
WFile *wapp_file_stdin(void) {
|
||||||
|
wapp_persist WFile _stdin = { .fh = INVALID_HANDLE_VALUE };
|
||||||
|
_stdin.fh = GetStdHandle(STD_INPUT_HANDLE);
|
||||||
|
return &_stdin;
|
||||||
|
}
|
||||||
|
|
||||||
|
WFile *wapp_file_stdout(void) {
|
||||||
|
wapp_persist WFile _stdout = { .fh = INVALID_HANDLE_VALUE };
|
||||||
|
_stdout.fh = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||||
|
return &_stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
WFile *wapp_file_stderr(void) {
|
||||||
|
wapp_persist WFile _stderr = { .fh = INVALID_HANDLE_VALUE };
|
||||||
|
_stderr.fh = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
return &_stderr;
|
||||||
|
}
|
||||||
|
|
||||||
WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
|
WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
|
||||||
wapp_persist c8 tmp[WAPP_PATH_MAX] = {0};
|
wapp_persist c8 tmp[WAPP_PATH_MAX] = {0};
|
||||||
memset(tmp, 0, WAPP_PATH_MAX);
|
memset(tmp, 0, WAPP_PATH_MAX);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ EXECUTE_COMMAND_CLOSE:
|
|||||||
wapp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf) {
|
wapp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf) {
|
||||||
Str8 out = wapp_str8_buf(OUT_BUF_LEN);
|
Str8 out = wapp_str8_buf(OUT_BUF_LEN);
|
||||||
|
|
||||||
out.size = fread((void *)out.buf, sizeof(u8), out.capacity, fp);
|
out.size = fread((void *)out.buf, sizeof(c8), out.capacity, fp);
|
||||||
if (out_handling == SHELL_OUTPUT_CAPTURE && out_buf != NULL) {
|
if (out_handling == SHELL_OUTPUT_CAPTURE && out_buf != NULL) {
|
||||||
if (out.size >= out_buf->capacity) {
|
if (out.size >= out_buf->capacity) {
|
||||||
return SHELL_ERR_OUT_BUF_FULL;
|
return SHELL_ERR_OUT_BUF_FULL;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// TODO (Abdelrahman): This module needs rethinking
|
||||||
|
|
||||||
#ifdef WAPP_PLATFORM_CPP
|
#ifdef WAPP_PLATFORM_CPP
|
||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
#endif // !WAPP_PLATFORM_CPP
|
#endif // !WAPP_PLATFORM_CPP
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ struct WUUID {
|
|||||||
#ifdef WAPP_PLATFORM_CPP
|
#ifdef WAPP_PLATFORM_CPP
|
||||||
#define wapp_uuid_gen_uuid4() ([&](){ \
|
#define wapp_uuid_gen_uuid4() ([&](){ \
|
||||||
wapp_persist WUUID uuid = wapp_uuid_create(); \
|
wapp_persist WUUID uuid = wapp_uuid_create(); \
|
||||||
return *(wapp_uuid_init_uuid4(&uuid)) \
|
return *(wapp_uuid_init_uuid4(&uuid)); \
|
||||||
}())
|
}())
|
||||||
#else
|
#else
|
||||||
#define wapp_uuid_gen_uuid4() *(wapp_uuid_init_uuid4(&wapp_uuid_create()))
|
#define wapp_uuid_gen_uuid4() *(wapp_uuid_init_uuid4(&wapp_uuid_create()))
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ TestFuncResult test_queue_push_alloc(void) {
|
|||||||
|
|
||||||
u64 remaining = wapp_queue_capacity(&queue) - queue.count;
|
u64 remaining = wapp_queue_capacity(&queue) - queue.count;
|
||||||
for (u64 i = 0; i < remaining; ++i) {
|
for (u64 i = 0; i < remaining; ++i) {
|
||||||
item = remaining + i;
|
item = (i32)(remaining + i);
|
||||||
wapp_queue_push(i32, &queue, &item);
|
wapp_queue_push(i32, &queue, &item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ TestFuncResult test_queue_push_alloc(void) {
|
|||||||
|
|
||||||
u64 remaining = wapp_queue_capacity(&queue) - queue.count;
|
u64 remaining = wapp_queue_capacity(&queue) - queue.count;
|
||||||
for (u64 i = 0; i < remaining; ++i) {
|
for (u64 i = 0; i < remaining; ++i) {
|
||||||
item = remaining + i;
|
item = (i32)(remaining + i);
|
||||||
wapp_queue_push(i32, &queue, &item);
|
wapp_queue_push(i32, &queue, &item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user