Compare commits
6 Commits
d8e1d54f3d
...
db8389f7d5
Author | SHA1 | Date | |
---|---|---|---|
db8389f7d5 | |||
5e6291cdc6 | |||
596bb1ef76 | |||
595b7d06f1 | |||
6db36114d5 | |||
c3be4ce8ee |
70
gebs.h
70
gebs.h
@ -90,6 +90,10 @@ int main(int argc, char ** argv)
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
# include <pthread.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -302,6 +306,7 @@ typedef struct {
|
|||||||
for (size_t __i = 0; __i < __size; __i++) { \
|
for (size_t __i = 0; __i < __size; __i++) { \
|
||||||
gebs_sb_append_char_alloc((alloc), (sb), __buf[__i]); \
|
gebs_sb_append_char_alloc((alloc), (sb), __buf[__i]); \
|
||||||
} \
|
} \
|
||||||
|
gebs_free((alloc), __buf); \
|
||||||
} \
|
} \
|
||||||
__ret; \
|
__ret; \
|
||||||
})
|
})
|
||||||
@ -387,6 +392,9 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
|
|||||||
({ \
|
({ \
|
||||||
const char *__deps[] = { __VA_ARGS__ }; \
|
const char *__deps[] = { __VA_ARGS__ }; \
|
||||||
bool __ok = false; \
|
bool __ok = false; \
|
||||||
|
if (sizeof(__deps)/sizeof(__deps[0]) == 0) { \
|
||||||
|
__ok = true; \
|
||||||
|
} \
|
||||||
for (size_t __i = 0; __i < sizeof(__deps)/sizeof(__deps[0]); __i++) { \
|
for (size_t __i = 0; __i < sizeof(__deps)/sizeof(__deps[0]); __i++) { \
|
||||||
if (gebs_needs_rebuild((out), __deps[__i])) { \
|
if (gebs_needs_rebuild((out), __deps[__i])) { \
|
||||||
__ok = true; \
|
__ok = true; \
|
||||||
@ -396,6 +404,21 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
|
|||||||
__ok; \
|
__ok; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
#define gebs_needs_rebuild_many_array(out, array) \
|
||||||
|
({ \
|
||||||
|
bool __ok = false; \
|
||||||
|
if (sizeof((array))/sizeof((array)[0]) == 0) { \
|
||||||
|
__ok = true; \
|
||||||
|
} \
|
||||||
|
for (size_t __i = 0; __i < sizeof((array))/sizeof((array)[0]); __i++) { \
|
||||||
|
if (gebs_needs_rebuild((out), (array)[__i])) { \
|
||||||
|
__ok = true; \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
__ok; \
|
||||||
|
})
|
||||||
|
|
||||||
#define gebs_make_compile_flags(...) \
|
#define gebs_make_compile_flags(...) \
|
||||||
do { \
|
do { \
|
||||||
if (gebs_needs_rebuild("compile_flags.txt", __FILE__)) { \
|
if (gebs_needs_rebuild("compile_flags.txt", __FILE__)) { \
|
||||||
@ -415,12 +438,20 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define GEBS_RULE(target, ...) if (needs_rebuild_many(target, __VA_ARGS__))
|
#define GEBS_RULE(target, ...) if (needs_rebuild_many(target, __VA_ARGS__))
|
||||||
|
#define GEBS_RULE_ARRAY(target, array) if (gebs_needs_rebuild_many_array(target, (array)))
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Scratch arena
|
// Scratch arena
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
extern Gebs_Arena gebs_scratch_arena;
|
typedef struct {
|
||||||
|
Gebs_Arena value;
|
||||||
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_t lock;
|
||||||
|
#endif
|
||||||
|
} Gebs_Scratch_Arena;
|
||||||
|
|
||||||
|
extern Gebs_Scratch_Arena gebs_scratch_arena;
|
||||||
|
|
||||||
void gebs_scratch_arena_reset(void);
|
void gebs_scratch_arena_reset(void);
|
||||||
char *gebs_fmt(const char *fmt, ...);
|
char *gebs_fmt(const char *fmt, ...);
|
||||||
@ -796,22 +827,25 @@ void gebs_arena_destroy(Gebs_Arena *a)
|
|||||||
// Scratch arena
|
// Scratch arena
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
Gebs_Arena gebs_scratch_arena;
|
Gebs_Scratch_Arena gebs_scratch_arena;
|
||||||
|
|
||||||
__attribute__((constructor))
|
__attribute__((constructor))
|
||||||
void gebs_scratch_areana_init(void)
|
void gebs_scratch_areana_init(void)
|
||||||
{
|
{
|
||||||
gebs_scratch_arena = gebs_arena_get();
|
gebs_scratch_arena.value = gebs_arena_get();
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((destructor))
|
__attribute__((destructor))
|
||||||
void gebs_scratch_areana_free(void)
|
void gebs_scratch_areana_free(void)
|
||||||
{
|
{
|
||||||
gebs_arena_destroy(&gebs_scratch_arena);
|
gebs_arena_destroy(&gebs_scratch_arena.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *gebs_fmt(const char *fmt, ...)
|
char *gebs_fmt(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_lock(&gebs_scratch_arena.lock);
|
||||||
|
#endif
|
||||||
va_list list;
|
va_list list;
|
||||||
va_start(list, fmt);
|
va_start(list, fmt);
|
||||||
|
|
||||||
@ -820,23 +854,41 @@ char *gebs_fmt(const char *fmt, ...)
|
|||||||
size_t size = vsnprintf(nil, 0, fmt, list_copy);
|
size_t size = vsnprintf(nil, 0, fmt, list_copy);
|
||||||
va_end(list_copy);
|
va_end(list_copy);
|
||||||
|
|
||||||
char *buf = gebs_malloc(&gebs_scratch_arena, size+1);
|
char *buf = gebs_malloc(&gebs_scratch_arena.value, size+1);
|
||||||
vsprintf(buf, fmt, list);
|
vsprintf(buf, fmt, list);
|
||||||
va_end(list);
|
va_end(list);
|
||||||
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_unlock(&gebs_scratch_arena.lock);
|
||||||
|
#endif
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gebs_scratch_arena_reset(void)
|
void gebs_scratch_arena_reset(void)
|
||||||
{
|
{
|
||||||
gebs_arena_reset(&gebs_scratch_arena);
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_lock(&gebs_scratch_arena.lock);
|
||||||
|
#endif
|
||||||
|
gebs_arena_reset(&gebs_scratch_arena.value);
|
||||||
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_unlock(&gebs_scratch_arena.lock);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char *gebs_cwd(void)
|
char *gebs_cwd(void)
|
||||||
{
|
{
|
||||||
char *cwd = gebs_malloc(&gebs_scratch_arena, PATH_MAX);
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_lock(&gebs_scratch_arena.lock);
|
||||||
|
#endif
|
||||||
|
char *cwd = gebs_malloc(&gebs_scratch_arena.value, PATH_MAX);
|
||||||
if (getcwd(cwd, PATH_MAX) == nil) {
|
if (getcwd(cwd, PATH_MAX) == nil) {
|
||||||
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_unlock(&gebs_scratch_arena.lock);
|
||||||
|
#endif
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
#ifdef GEBS_ENABLE_PTHREAD_FEATURES
|
||||||
|
pthread_mutex_unlock(&gebs_scratch_arena.lock);
|
||||||
|
#endif
|
||||||
return cwd;
|
return cwd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -967,6 +1019,7 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
|
|||||||
#define sb_finish gebs_sb_finish
|
#define sb_finish gebs_sb_finish
|
||||||
#define sb_append_nstr gebs_sb_append_nstr
|
#define sb_append_nstr gebs_sb_append_nstr
|
||||||
#define sb_read_file gebs_sb_read_file
|
#define sb_read_file gebs_sb_read_file
|
||||||
|
#define sb_read_file_alloc gebs_sb_read_file_alloc
|
||||||
|
|
||||||
#define rename1 gebs_rename
|
#define rename1 gebs_rename
|
||||||
#define remove1 gebs_remove
|
#define remove1 gebs_remove
|
||||||
@ -975,7 +1028,7 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
|
|||||||
|
|
||||||
#define Cmd Gebs_Cmd
|
#define Cmd Gebs_Cmd
|
||||||
#define cmd_append_alloc gebs_cmd_append_alloc
|
#define cmd_append_alloc gebs_cmd_append_alloc
|
||||||
#define cmd_free_aloc gebs_cmd_free_alloc
|
#define cmd_free_alloc gebs_cmd_free_alloc
|
||||||
#define cmd_append gebs_cmd_append
|
#define cmd_append gebs_cmd_append
|
||||||
#define cmd_free gebs_cmd_free
|
#define cmd_free gebs_cmd_free
|
||||||
#define cmd_run_alloc gebs_cmd_run_alloc
|
#define cmd_run_alloc gebs_cmd_run_alloc
|
||||||
@ -999,6 +1052,7 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
|
|||||||
#define rebuild_self gebs_rebuild_self
|
#define rebuild_self gebs_rebuild_self
|
||||||
#define make_compile_flags gebs_make_compile_flags
|
#define make_compile_flags gebs_make_compile_flags
|
||||||
#define RULE GEBS_RULE
|
#define RULE GEBS_RULE
|
||||||
|
#define RULE_ARRAY GEBS_RULE_ARRAY
|
||||||
|
|
||||||
#define scratch_arena gebs_scratch_arena
|
#define scratch_arena gebs_scratch_arena
|
||||||
#define fmt gebs_fmt
|
#define fmt gebs_fmt
|
||||||
|
Reference in New Issue
Block a user