diff options
Diffstat (limited to 'include/std')
-rw-r--r-- | include/std/buffer.h | 2 | ||||
-rw-r--r-- | include/std/file.h | 4 | ||||
-rw-r--r-- | include/std/log.h | 1 | ||||
-rw-r--r-- | include/std/misc.h | 16 | ||||
-rw-r--r-- | include/std/scoped_allocator.h | 2 | ||||
-rw-r--r-- | include/std/thread.h | 3 |
6 files changed, 23 insertions, 5 deletions
diff --git a/include/std/buffer.h b/include/std/buffer.h index c961b6e..a1bfb01 100644 --- a/include/std/buffer.h +++ b/include/std/buffer.h @@ -21,7 +21,7 @@ CHECK_RESULT int buffer_append(Buffer *self, const void *data, usize size); void* buffer_get(Buffer *self, usize index, usize type_size); CHECK_RESULT int buffer_pop(Buffer *self, void *data, usize size); void* buffer_start(Buffer *self); -void *buffer_end(Buffer *self); +void* buffer_end(Buffer *self); usize __buffer_get_size(Buffer *self, usize type_size); #define buffer_get_size(self, type) __buffer_get_size((self), sizeof(type)) diff --git a/include/std/file.h b/include/std/file.h index 120e7bb..c6753fd 100644 --- a/include/std/file.h +++ b/include/std/file.h @@ -4,6 +4,7 @@ #include "misc.h" #include "types.h" #include "buffer_view.h" +#include "buffer.h" /* Return bool_true if you want to continue scanning, otherwise return bool_false */ typedef bool (*scan_dir_callback_func)(const char *filepath, int filepath_length, void *userdata); @@ -31,7 +32,10 @@ CHECK_RESULT int mapped_file_init(MappedFile *self, const char *filepath, Mapped CHECK_RESULT int mapped_file_deinit(MappedFile *self); #endif +/* @data will be allocated with am_malloc, should be deallocated with am_free */ CHECK_RESULT int read_whole_file(const char *filepath, char **data, usize *size); +/* @result_path will be allocated with am_malloc, should be deallocated with am_free */ +CHECK_RESULT int file_get_canonical_path(const char *filepath, char **result_path, usize *result_path_size); BufferView file_get_parent_directory(BufferView filepath); BufferView file_get_name(BufferView filepath); diff --git a/include/std/log.h b/include/std/log.h index d13c5bf..cd376c6 100644 --- a/include/std/log.h +++ b/include/std/log.h @@ -8,6 +8,5 @@ void amal_log_debug(const char *fmt, ...); void amal_log_error(const char *fmt, ...); void amal_log_info(const char *fmt, ...); void amal_log_warning(const char *fmt, ...); -void amal_log_perror(const char *prefix); #endif diff --git a/include/std/misc.h b/include/std/misc.h index b979d9c..e28ed48 100644 --- a/include/std/misc.h +++ b/include/std/misc.h @@ -1,15 +1,27 @@ #ifndef AMALGAM_MISC_H #define AMALGAM_MISC_H +#include <stdio.h> + +#ifdef AMAL_PEDANTIC + #define return_if_debug_msg do {} while(0) + #define cleanup_if_debug_msg do {} while(0) +#else + #define return_if_debug_msg do { fprintf(stderr, "Return from %s:%d\n", __FUNCTION__, __LINE__); } while(0) + #define cleanup_if_debug_msg do { fprintf(stderr, "cleanup from %s:%d\n", __FUNCTION__, __LINE__); } while(0) +#endif + #define return_if_error(result) \ do { \ int return_if_result; \ return_if_result = (result); \ - if((return_if_result) != 0) \ + if((return_if_result) != 0) { \ + return_if_debug_msg; \ return return_if_result; \ + } \ } while(0) -#define cleanup_if_error(result) do { if((result) != 0) goto cleanup; } while(0) +#define cleanup_if_error(result) do { if((result) != 0) { cleanup_if_debug_msg; goto cleanup; } } while(0) #if defined(__GNUC__) && __GNUC__ >= 4 #define CHECK_RESULT __attribute__ ((warn_unused_result)) diff --git a/include/std/scoped_allocator.h b/include/std/scoped_allocator.h index 0de4f04..9090767 100644 --- a/include/std/scoped_allocator.h +++ b/include/std/scoped_allocator.h @@ -15,7 +15,7 @@ struct ScopedAllocatorNode { struct ScopedAllocator { ScopedAllocatorNode head; ScopedAllocatorNode *current; - Buffer buffers; + Buffer/*<Buffer*>*/ buffers; }; CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self); diff --git a/include/std/thread.h b/include/std/thread.h index 915d6a9..6eedb08 100644 --- a/include/std/thread.h +++ b/include/std/thread.h @@ -29,6 +29,8 @@ typedef enum { struct amal_mutex { pthread_mutex_t mutex; const char *lock_identifier; + bool locked; + pthread_t owner_thread; }; CHECK_RESULT int amal_thread_create(amal_thread *self, amal_thread_type thread_type, const char *name, AmalThreadCallbackFunc callback_func, void *userdata); @@ -40,6 +42,7 @@ CHECK_RESULT int amal_thread_join(amal_thread *self, void **result); void amal_mutex_init(amal_mutex *self); void amal_mutex_deinit(amal_mutex *self); CHECK_RESULT int amal_mutex_lock(amal_mutex *self, const char *lock_identifier); +/* Safe to call unlock when another thread owns the lock or if the lock is not locked */ CHECK_RESULT int amal_mutex_unlock(amal_mutex *self); void amal_mutex_tryunlock(amal_mutex *self); |