Yzena
/
Yc
2
1
Fork 0
Browse Source

Make everything build with -Wdeclaration-after-statement

I decided to use this because it will actually help in enforcing the
declaration of variables in functions. I also wanted to do it as soon as
possible so that it wouldn't be hard later.

Signed-off-by: Gavin Howard <gavin@yzena.com>
afl_persistent_mode
Gavin Howard 2 months ago
parent
commit
934e4dde7d
Signed by: gavin
GPG Key ID: C08038BDF280D33E
  1. 1
      CMakeLists.txt
  2. 27
      benchmarks/arith.c
  3. 16
      benchmarks/listdir.c
  4. 12
      benchmarks/memcpy.c
  5. 42
      benchmarks/xxh3_v_spooky.c
  6. 60
      include/yc/arith.h
  7. 14
      samples/io/file_open.c
  8. 3
      samples/io/interactive.c
  9. 11
      samples/io/iterate.c
  10. 21
      samples/io/list_to_file.c
  11. 13
      samples/io/random_access.c
  12. 6
      src/concurrency/condvar.c
  13. 6
      src/concurrency/mutex.c
  14. 16
      src/concurrency/os/posix/condvar.c
  15. 7
      src/concurrency/os/posix/strucon.c
  16. 4
      src/concurrency/os/windows/threadset.c
  17. 9
      src/concurrency/rwlock.c
  18. 9
      src/concurrency/semaphore.c
  19. 27
      src/concurrency/strucon.c
  20. 51
      src/container/imap.c
  21. 336
      src/container/list.c
  22. 256
      src/container/map.c
  23. 164
      src/container/ntree.c
  24. 249
      src/container/nvector.c
  25. 78
      src/container/smap.c
  26. 6
      src/container/svec.h
  27. 70
      src/container/svector.c
  28. 188
      src/container/tree.c
  29. 10
      src/container/vec.c
  30. 178
      src/container/vector.c
  31. 39
      src/gaml/gaml.c
  32. 19
      src/gaml/lex.c
  33. 31
      src/gaml/parse.c
  34. 121
      src/io/dir.c
  35. 3
      src/io/dirent.c
  36. 95
      src/io/file.c
  37. 11
      src/io/fs.c
  38. 12
      src/io/io.c
  39. 7
      src/io/os/posix/bareio.c
  40. 6
      src/io/os/posix/dir.c
  41. 9
      src/io/os/posix/file.c
  42. 61
      src/io/os/posix/fs.c
  43. 5
      src/io/os/posix/io.c
  44. 8
      src/io/os/windows/bareio.c
  45. 17
      src/io/os/windows/file.c
  46. 50
      src/io/os/windows/fs.c
  47. 19
      src/io/os/windows/io.c
  48. 75
      src/io/path.c
  49. 6
      src/main.c
  50. 74
      src/pool/mappool.c
  51. 4
      src/pool/os/posix/alloc.c
  52. 9
      src/pool/os/windows/alloc.c
  53. 108
      src/pool/setpool.c
  54. 79
      src/pool/stackpool.c
  55. 102
      src/rig/build.c
  56. 8
      src/rig/db.c
  57. 10
      src/rig/main.c
  58. 15
      src/rig/rig.c
  59. 6
      src/rig/target.c
  60. 12
      src/str/os/windows/str.c
  61. 36
      src/str/str.c
  62. 100
      src/str/string.c
  63. 8
      src/sys/os/posix/multiplex.c
  64. 16
      src/sys/os/posix/proc.c
  65. 25
      src/sys/os/posix/sys.c
  66. 12
      src/sys/os/windows/multiplex.c
  67. 42
      src/sys/os/windows/proc.c
  68. 17
      src/sys/os/windows/sys.c
  69. 23
      src/sys/proc.c
  70. 8
      src/time/os/posix/timer.c
  71. 7
      src/time/os/windows/clock.c
  72. 7
      src/time/os/windows/time.c
  73. 6
      src/time/os/windows/timer.c
  74. 123
      src/util/hash.c
  75. 28
      src/util/opt.c
  76. 69
      src/yao/lex.c
  77. 84
      src/yao/parse.c
  78. 7
      src/yao/yao.c
  79. 58
      src/yc.c
  80. 5
      src/yc.h
  81. 36
      src/yvm/exec.c
  82. 93
      src/yvm/yvm.c
  83. 9
      tests/container/array_all.c
  84. 36
      tests/container/map_all.c
  85. 72
      tests/container/map_countwords.c
  86. 8
      tests/container/map_stress.c
  87. 16
      tests/container/ntree_add.c
  88. 30
      tests/container/ntree_copy.c
  89. 31
      tests/container/ntree_empty.c
  90. 136
      tests/container/ntree_iterator.c
  91. 26
      tests/container/ntree_remove.c
  92. 16
      tests/container/ntree_tests.c
  93. 9
      tests/container/nvec_add.c
  94. 24
      tests/container/nvec_copy.c
  95. 9
      tests/container/nvec_nadd.c
  96. 9
      tests/container/nvec_npop.c
  97. 13
      tests/container/nvec_npush.c
  98. 13
      tests/container/nvec_nremove.c
  99. 9
      tests/container/nvec_pop.c
  100. 17
      tests/container/nvec_push.c
  101. Some files were not shown because too many files have changed in this diff Show More

1
CMakeLists.txt

@ -119,7 +119,6 @@ if(NOT "${MSVC}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-c++98-compat")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-disabled-macro-expansion")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch-enum")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-declaration-after-statement")
endif()
endif()

27
benchmarks/arith.c

@ -75,28 +75,29 @@
int
main(int argc, char* argv[])
{
y_UNUSED(argc);
y_UNUSED(argv);
int32_t i;
int32_t isum = 0;
int32_t ioflow = 0;
y_Time stop;
y_Time ystart;
y_Time ystop;
y_s32 yi;
y_s32 ysum = 0;
y_s32 yoflow = 0;
y_Time start = y_time_time_start();
y_UNUSED(argc);
y_UNUSED(argv);
for (i = 0; i < NITERATIONS; ++i)
{
bool o = __builtin_add_overflow(isum, i, &isum);
ioflow += (o);
}
y_Time stop = y_time_time_stop(start);
y_s32 yi;
y_s32 ysum = 0;
y_s32 yoflow = 0;
y_Time y_start = y_time_time_start();
stop = y_time_time_stop(start);
ystart = y_time_time_start();
for (yi = 0; yi < NITERATIONS; yi += 1)
{
@ -105,7 +106,7 @@ main(int argc, char* argv[])
yoflow += o.o;
}
y_Time ystop = y_time_time_stop(y_start);
ystop = y_time_time_stop(ystart);
y_printf("When using overflow:\n\n");
@ -133,14 +134,14 @@ main(int argc, char* argv[])
ysum = 0;
y_start = y_time_time_start();
ystart = y_time_time_start();
for (yi = 0; yi < NITERATIONS; yi += 1)
{
ysum = y_s32aw(ysum, yi);
}
ystop = y_time_time_stop(y_start);
ystop = y_time_time_stop(ystart);
y_printf("\nWhen NOT using overflow:\n\n");

16
benchmarks/listdir.c

@ -67,19 +67,21 @@
int
main(int argc, char* argv[])
{
if (argc < 2) return 1;
y_Status s;
y_Error e;
y_Path dirp;
y_Stat st;
size_t nentries;
y_Status s = y_fs_path_init_cstr(&dirp, argv[1]);
if (s != y_STATUS_SUCCESS) return 1;
if (argc < 2) return 1;
y_Stat st;
s = y_fs_path_init_cstr(&dirp, argv[1]);
if (s != y_STATUS_SUCCESS) return 1;
y_Error e = y_fs_path_stat(dirp, &st);
e = y_fs_path_stat(dirp, &st);
if (e != y_ERROR_SUCCESS) return 1;
size_t nentries = st.size / sizeof(struct dirent);
nentries = st.size / sizeof(struct dirent);
y_printf("nentries: %zu, size: %llu, sizeof dirent: %zu\n", nentries,
st.size, sizeof(struct dirent));

12
benchmarks/memcpy.c

@ -95,9 +95,10 @@ bench(void)
for (size = 1; size <= BUF_SIZE; ++size)
{
size_t amt;
y_Time stop1;
y_Time stop2;
y_Time start2;
const size_t max = size > 32 ? 32 : size;
y_Time start1 = y_time_time_start();
for (amt = 0; amt < NITERATIONS; ++amt)
@ -116,9 +117,8 @@ bench(void)
}
}
y_Time stop1 = y_time_time_stop(start1);
y_Time start2 = y_time_time_start();
stop1 = y_time_time_stop(start1);
start2 = y_time_time_start();
for (amt = 0; amt < NITERATIONS; ++amt)
{
@ -135,7 +135,7 @@ bench(void)
}
}
y_Time stop2 = y_time_time_stop(start2);
stop2 = y_time_time_stop(start2);
printf("%zu %.24f %.24f\n", size,
y_time_time_double(stop1) / (double) (NITERATIONS * max * max),

42
benchmarks/xxh3_v_spooky.c

@ -105,47 +105,49 @@ print_runs(const char* title, const y_Time arr[RUNS])
int
main(int argc, char* argv[])
{
unsigned char line[MAX_CHARS + 1];
y_Status s;
y_Vector words;
y_Map spooky;
y_Map xxh3;
size_t i;
y_Time start, stop;
y_Time start;
y_Time stop;
char* name;
y_Path path;
y_File f;
size_t nread;
size_t len;
size_t l;
y_Time spooky_inserts[RUNS];
y_Time spooky_queries[RUNS];
y_Time spooky_removes[RUNS];
y_Time xxh3_inserts[RUNS];
y_Time xxh3_queries[RUNS];
y_Time xxh3_removes[RUNS];
unsigned char line[MAX_CHARS + 1];
int errors;
s = y_main(false, false, false);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
int errors = 0;
y_Vector words = y_vec_createStringVec(8192);
y_Map spooky = y_map_createStringKeyMap(0.96f, sizeof(size_t), NULL);
y_Map xxh3 = y_map_create(0.96f, sizeof(y_str), sizeof(size_t), xxh3_hasher,
errors = 0;
words = y_vec_createStringVec(8192);
spooky = y_map_createStringKeyMap(0.96f, sizeof(size_t), NULL);
xxh3 = y_map_create(0.96f, sizeof(y_str), sizeof(size_t), xxh3_hasher,
y_str_eq, y_str_free, NULL);
char* name = "/usr/share/dict/words";
name = "/usr/share/dict/words";
if (argc > 1) name = argv[1];
y_Path path;
s = y_fs_path_init_cstr(&path, name);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
y_File f;
s = y_fs_file_open(&f, path, y_FILE_READ);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
s = y_strucon_stack_pushErrorHandler(y_err_ignore_eof);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
size_t nread;
do
{
s = y_fgets(f, line, MAX_CHARS, &nread);
@ -158,16 +160,14 @@ main(int argc, char* argv[])
y_fs_file_close(f);
size_t len = y_vec_len(words);
size_t l;
len = y_vec_len(words);
for (l = 0; l < RUNS; ++l)
{
start = y_time_time_start();
size_t j;
start = y_time_time_start();
for (i = 0; i < len; ++i)
{
const char* str = y_str_str((y_str*) y_vec_get(words, i));

60
include/yc/arith.h

@ -793,9 +793,11 @@ t ## o \
t ## do(t a, t b) \
{ \
t ## o i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i.n = a / b; \
@ -810,9 +812,11 @@ t ## o \
t ## remo(t a, t b) \
{ \
t ## o i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i.n = a % b; \
@ -827,9 +831,11 @@ t ## o \
t ## modo(t a, t b) \
{ \
t ## o i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i.n = a % b; \
@ -890,9 +896,11 @@ t ## dreso \
t ## dro(t a, t b) \
{ \
t ## dreso i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i.q = a / b; \
@ -908,9 +916,11 @@ t ## dreso \
t ## dmo(t a, t b) \
{ \
t ## dreso i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i.q = a / b; \
@ -967,9 +977,11 @@ t \
t ## dw(t a, t b) \
{ \
t i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i = a / b; \
@ -983,9 +995,11 @@ t \
t ## remw(t a, t b) \
{ \
t i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i = a % b; \
@ -999,9 +1013,11 @@ t \
t ## modw(t a, t b) \
{ \
t i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i = a % b; \
@ -1016,9 +1032,11 @@ t ## dres \
t ## drw(t a, t b) \
{ \
t ## dres i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i.q = a / b; \
@ -1033,9 +1051,11 @@ t ## dres \
t ## dmw(t a, t b) \
{ \
t ## dres i; \
bool aneg; \
bool bneg; \
if (b == 0) y_panica("division by zero"); \
const bool aneg = (a >= t ## _min); \
const bool bneg = (b >= t ## _min); \
aneg = (a >= t ## _min); \
bneg = (b >= t ## _min); \
if (aneg) a = t ## sneg(a); \
if (bneg) b = t ## sneg(b); \
i.q = a / b; \

14
samples/io/file_open.c

@ -99,8 +99,12 @@ static const char no[] = "no";
int
main(int argc, char* argv[])
{
y_Status s = y_main(false, false, false);
y_Status s;
y_Error e;
y_Path path;
y_Stat st;
s = y_main(false, false, false);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
// Make sure we have a file name.
@ -111,17 +115,11 @@ main(int argc, char* argv[])
}
// Copy the path.
y_Path path;
s = y_fs_path_init_cstr(&path, argv[1]);
if (y_err(s != y_STATUS_SUCCESS)) return (int) s;
y_Stat st;
// Stat the file.
y_Error e = y_fs_path_stat(path, &st);
// Check the status.
e = y_fs_path_stat(path, &st);
if (e != y_ERROR_SUCCESS)
{
y_eprintf("Error opening file");

3
samples/io/interactive.c

@ -127,6 +127,7 @@ main(void)
for (;;)
{
uint32_t i;
int choice;
y_uchar input[256];
y_printf("==========\nDIRECTORY: %s\n==========\n\n",
@ -155,7 +156,7 @@ main(void)
if (y_gets(input, 256, NULL) != y_STATUS_SUCCESS) break;
// Get the choice number.
int choice = atoi((char*) input);
choice = atoi((char*) input);
// If the choice is valid...
if (choice >= 0 && (uint32_t) choice < y_fs_dir_numEntries(dir))

11
samples/io/iterate.c

@ -97,21 +97,18 @@
int
main(void)
{
y_Status s = y_main(false, false, false);
y_Status s;
y_Path path;
y_Dir dir;
s = y_main(false, false, false);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
y_Path path;
s = y_fs_path_init_cstr(&path, ".");
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
// Open the directory.
y_Dir dir;
s = y_fs_dir_open(&dir, path);
// Get the status and check it.
if (y_err(s != y_STATUS_SUCCESS))
{
y_eprintf("Error opening file");

21
samples/io/list_to_file.c

@ -100,11 +100,14 @@
int
main(void)
{
// Get the temp directory name.
y_Status s;
y_Path path;
y_Path temp;
y_Path base;
y_Status s;
y_Path home;
y_Dir dir;
uint32_t nfiles;
y_File fp;
s = y_main(false, false, false);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
@ -116,33 +119,23 @@ main(void)
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
// Open the temp file.
y_Path path;
s = y_fs_file_temp(&path, temp, base);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
y_File fp;
// Open the temp file.
s = y_fs_file_open(&fp, path, y_FILE_WRITE | y_FILE_BINARY);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
// Get the home directory path.
y_Path home;
s = y_fs_path_home(&home);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
// Open the directory.
y_Dir dir;
s = y_fs_dir_open(&dir, home);
// Check for error.
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
// Get the number of files.
uint32_t nfiles = y_fs_dir_numEntries(dir);
nfiles = y_fs_dir_numEntries(dir);
// Loop through the files.
for (uint32_t i = 0; i < nfiles; ++i)

13
samples/io/random_access.c

@ -97,24 +97,21 @@
int
main(int argc, char* argv[])
{
y_Status s;
y_Dir dir;
y_Path path;
const char* name;
unsigned int i;
y_Status s = y_main(false, false, false);
s = y_main(false, false, false);
if (y_err(s != y_STATUS_SUCCESS)) y_exit(y_status_exits[s]);
// Open the directory.
const char* name = argc >= 2 ? argv[1] : ".";
y_Path path;
name = argc >= 2 ? argv[1] : ".";
s = y_fs_path_init_cstr(&path, name);
if (y_err(s != y_STATUS_SUCCESS)) return (int) s;
s = y_fs_dir_open(&dir, path);
// Check for error.
if (y_err(s != y_STATUS_SUCCESS))
{
y_eprintf("Error opening file");

6
src/concurrency/condvar.c

@ -69,6 +69,7 @@
y_Status
y_strucon_condvar_init(y_strucon_condvar* v)
{
y_Status s;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(v != NULL, YC_ASSERT_NULL);
@ -76,7 +77,7 @@ y_strucon_condvar_init(y_strucon_condvar* v)
y_THREAD_TRYLOCK1(d);
y_Status s = y_strucon_condvar_os_init(v);
s = y_strucon_condvar_os_init(v);
y_THREAD_TRYUNLOCK1(d);
@ -133,6 +134,7 @@ y_Error
y_strucon_condvar_timedwait(y_StruconCondvar v, y_StruconMutex m,
y_ulong millis)
{
y_Error e;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(v != NULL, YC_ASSERT_NULL);
@ -141,7 +143,7 @@ y_strucon_condvar_timedwait(y_StruconCondvar v, y_StruconMutex m,
y_THREAD_TRYLOCK1(d);
y_Error e = y_strucon_condvar_os_timedwait(v, m, millis);
e = y_strucon_condvar_os_timedwait(v, m, millis);
y_THREAD_TRYUNLOCK1(d);

6
src/concurrency/mutex.c

@ -69,6 +69,7 @@
y_Status
y_strucon_mutex_init(y_StruconMutex m)
{
y_Status s;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(m != NULL, YC_ASSERT_NULL);
@ -76,7 +77,7 @@ y_strucon_mutex_init(y_StruconMutex m)
y_THREAD_TRYLOCK1(d);
y_Status s = y_strucon_mutex_os_init(m);
s = y_strucon_mutex_os_init(m);
y_THREAD_TRYUNLOCK1(d);
@ -101,6 +102,7 @@ y_strucon_mutex_lock(y_StruconMutex m)
y_Error
y_strucon_mutex_trylock(y_StruconMutex m)
{
y_Error e;
y_ThreadData d = y_strucon_thread_os_get();
// There cannot be any printing asserts in this function because it could be
@ -110,7 +112,7 @@ y_strucon_mutex_trylock(y_StruconMutex m)
y_THREAD_TRYLOCK1(d);
y_Error e = y_strucon_mutex_os_trylock(m);
e = y_strucon_mutex_os_trylock(m);
if (y_err(e != y_ERROR_SUCCESS))
{

16
src/concurrency/os/posix/condvar.c

@ -72,8 +72,9 @@
y_Status
y_strucon_condvar_os_init(y_strucon_condvar* v)
{
int r = pthread_cond_init(&v->v, NULL);
int r;
r = pthread_cond_init(&v->v, NULL);
if (y_err(r != 0)) return y_strucon_handleError(y_io_os_errno(r));
return y_STATUS_SUCCESS;
@ -82,8 +83,9 @@ y_strucon_condvar_os_init(y_strucon_condvar* v)
void
y_strucon_condvar_os_signal(y_strucon_condvar* v)
{
int r = pthread_cond_signal(&v->v);
int r;
r = pthread_cond_signal(&v->v);
if (y_err(r != 0))
{
y_panica("Could not signal condition variable");
@ -93,8 +95,9 @@ y_strucon_condvar_os_signal(y_strucon_condvar* v)
void
y_strucon_condvar_os_broadcast(y_strucon_condvar* v)
{
int r = pthread_cond_broadcast(&v->v);
int r;
r = pthread_cond_broadcast(&v->v);
if (y_err(r != 0))
{
y_panica("Could not broadcast on condition variable");
@ -104,8 +107,9 @@ y_strucon_condvar_os_broadcast(y_strucon_condvar* v)
void
y_strucon_condvar_os_wait(y_strucon_condvar* v, y_strucon_mutex* m)
{
int r = pthread_cond_wait(&v->v, &m->m);
int r;
r = pthread_cond_wait(&v->v, &m->m);
if (y_err(r != 0))
{
if (r == ENOTRECOVERABLE || r == EOWNERDEAD)
@ -122,12 +126,12 @@ y_strucon_condvar_os_timedwait(y_strucon_condvar* v, y_strucon_mutex* m,
y_ulong millis)
{
struct timespec ts;
int r;
ts.tv_sec = millis / 1000;
ts.tv_nsec = (millis % 1000) * 1000000;
int r = pthread_cond_timedwait(&v->v, &m->m, &ts);
r = pthread_cond_timedwait(&v->v, &m->m, &ts);
if (y_err(r != 0))
{
if (r == ENOTRECOVERABLE || r == EOWNERDEAD)

7
src/concurrency/os/posix/strucon.c

@ -89,8 +89,9 @@ y_strucon_thread_sig(int sig)
y_Status
y_strucon_os_init(void)
{
int r = pthread_key_create(&key, NULL);
int r;
r = pthread_key_create(&key, NULL);
if (y_err(r == EAGAIN || r == ENOMEM))
{
return y_strucon_handleError(y_ERROR_MALLOC_FAIL);
@ -128,6 +129,7 @@ y_Status
y_strucon_thread_os_set(y_ThreadData d)
{
struct sigaction sa;
int r;
sigfillset(&sa.sa_mask);
sigdelset(&sa.sa_mask, SIGUSR2);
@ -139,8 +141,7 @@ y_strucon_thread_os_set(y_ThreadData d)
d->sysid = pthread_self();
int r = pthread_setspecific(key, d);
r = pthread_setspecific(key, d);
if (y_err(r == ENOMEM)) return y_strucon_handleError(y_ERROR_MALLOC_FAIL);
return y_STATUS_SUCCESS;

4
src/concurrency/os/windows/threadset.c

@ -65,6 +65,7 @@ void
y_threadset_child_os_destroy(y_threadsetchild* c)
{
DWORD r;
bool good;
y_threaddata* td = y_strucon_thread_os_get();
do
@ -80,8 +81,7 @@ y_threadset_child_os_destroy(y_threadsetchild* c)
y_panica("Could not join thread");
}
bool good = GetExitCodeThread(c->data->sysid.handle, &r);
good = GetExitCodeThread(c->data->sysid.handle, &r);
if (y_err(!good))
{
y_panica("Could not get thread return status");

9
src/concurrency/rwlock.c

@ -69,6 +69,7 @@
y_Status
y_strucon_rwlock_init(y_strucon_rwlock* l)
{
y_Status s;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(l != NULL, YC_ASSERT_NULL);
@ -76,7 +77,7 @@ y_strucon_rwlock_init(y_strucon_rwlock* l)
y_THREAD_TRYLOCK1(d);
y_Status s = y_strucon_rwlock_os_init(l);
s = y_strucon_rwlock_os_init(l);
y_THREAD_TRYUNLOCK1(d);
@ -99,6 +100,7 @@ y_strucon_rwlock_rdlock(y_strucon_rwlock* l)
y_Error
y_strucon_rwlock_tryrdlock(y_strucon_rwlock* l)
{
y_Error e;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(l != NULL, YC_ASSERT_NULL);
@ -106,7 +108,7 @@ y_strucon_rwlock_tryrdlock(y_strucon_rwlock* l)
y_THREAD_TRYLOCK1(d);
y_Error e = y_strucon_rwlock_os_tryrdlock(l);
e = y_strucon_rwlock_os_tryrdlock(l);
if (y_err(e != y_ERROR_SUCCESS))
{
@ -145,6 +147,7 @@ y_strucon_rwlock_wrlock(y_strucon_rwlock* l)
y_Error
y_strucon_rwlock_trywrlock(y_strucon_rwlock* l)
{
y_Error e;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(l != NULL, YC_ASSERT_NULL);
@ -152,7 +155,7 @@ y_strucon_rwlock_trywrlock(y_strucon_rwlock* l)
y_THREAD_TRYLOCK1(d);
y_Error e = y_strucon_rwlock_os_trywrlock(l);
e = y_strucon_rwlock_os_trywrlock(l);
if (y_err(e != y_ERROR_SUCCESS))
{

9
src/concurrency/semaphore.c

@ -69,6 +69,7 @@
y_Status
y_strucon_sem_init(y_strucon_sem* sm, y_uint initial)
{
y_Status s;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(sm != NULL, YC_ASSERT_NULL);
@ -76,7 +77,7 @@ y_strucon_sem_init(y_strucon_sem* sm, y_uint initial)
y_THREAD_TRYLOCK1(d);
y_Status s = y_strucon_sem_os_init(sm, initial);
s = y_strucon_sem_os_init(sm, initial);
y_THREAD_TRYUNLOCK1(d);
@ -101,6 +102,7 @@ y_strucon_sem_wait(y_StruconSem sm)
y_Error
y_strucon_sem_trywait(y_StruconSem sm)
{
y_Error e;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(sm != NULL, YC_ASSERT_NULL);
@ -108,7 +110,7 @@ y_strucon_sem_trywait(y_StruconSem sm)
y_THREAD_TRYLOCK1(d);
y_Error e = y_strucon_sem_os_trywait(sm);
e = y_strucon_sem_os_trywait(sm);
y_THREAD_TRYUNLOCK1(d);
@ -118,6 +120,7 @@ y_strucon_sem_trywait(y_StruconSem sm)
y_Error
y_strucon_sem_timedwait(y_StruconSem sm, y_ulong millis)
{
y_Error e;
y_ThreadData d = y_strucon_thread_os_get();
yc_assert(sm != NULL, YC_ASSERT_NULL);
@ -125,7 +128,7 @@ y_strucon_sem_timedwait(y_StruconSem sm, y_ulong millis)
y_THREAD_TRYLOCK1(d);
y_Error e = y_strucon_sem_os_timedwait(sm, millis);
e = y_strucon_sem_os_timedwait(sm, millis);
y_THREAD_TRYUNLOCK1(d);

27
src/concurrency/strucon.c

@ -85,6 +85,7 @@ y_strucon_init(void)
{
y_threaddata d;
y_threaddata* dptr;
y_threaddata* data;
y_Status s = y_strucon_os_init();
if (y_err(s != y_STATUS_SUCCESS)) return s;
@ -118,7 +119,7 @@ y_strucon_init(void)
if (y_err(s != y_STATUS_SUCCESS)) goto thread_err;
// We need to take away the cancel lock.
y_threaddata* data = y_strucon_thread_os_get();
data = y_strucon_thread_os_get();
y_atomic_os_store_uint(&data->cancel_lock, 0);
// Make sure the parent is properly set.
@ -165,10 +166,12 @@ y_strucon_id(void)
y_Status
y_strucon_status(void)
{
y_threaddata* d;
// Ignore the return value.
y_call();
y_threaddata* d = y_strucon_thread_os_get();
d = y_strucon_thread_os_get();
y_return(d->status);
}
@ -185,6 +188,7 @@ y_Status
y_strucon_stack_push(const char* key, void* data, size_t len)
{
y_Status s;
y_vec* stack;
y_threaddata* d = y_strucon_thread_os_get();
if (d->contexts == NULL)
@ -194,8 +198,6 @@ y_strucon_stack_push(const char* key, void* data, size_t len)
if (y_err(d == NULL)) return y_strucon_status();
}
y_vec* stack;
#ifdef YC_DEBUG
stack = NULL;
#endif // YC_DEBUG
@ -280,17 +282,20 @@ y_strucon_handleError(y_Error e)
y_map_existsStringKey_v(d->contexts, y_STRUCON_ERROR_HANDLER_KEY,
&stack))
{
size_t i;
size_t len;
y_strucon_mutex_unlock(&threads_mutex);
size_t i;
size_t len = y_vec_len(stack);
len = y_vec_len(stack);
for (i = 0; i < len; ++i)
{
hptr = y_vec_get_r(stack, i);
bool handled;
bool handled = (*hptr)(e, &ret);
hptr = y_vec_get_r(stack, i);
handled = (*hptr)(e, &ret);
if (handled)
{
orig->status = ret;
@ -371,6 +376,8 @@ y_strucon_thread_init(y_threaddata** data, y_ThreadID parent,
{
y_Status s;
y_threaddata d;
y_ListElem elem;
y_threaddata* dptr;
// NOLINTNEXTLINE
memset(&d, 0, sizeof(y_threaddata));
@ -393,8 +400,8 @@ y_strucon_thread_init(y_threaddata** data, y_ThreadID parent,
s = y_list_append(&threads, &d);
if (y_err(s != y_STATUS_SUCCESS)) goto append_err;
y_ListElem elem = y_list_tail(&threads);
y_threaddata* dptr = elem.item;
elem = y_list_tail(&threads);
dptr = elem.item;
dptr->id = elem.id;

51
src/container/imap.c

@ -133,6 +133,8 @@ y_imap_init(y_imap* m, const float load, const size_t ksize, const size_t esize,
const y_Hasher hash, const y_Equal eq, const y_Destructor kdtor,
const y_Destructor vdtor)
{
y_Status s;
yc_assert(m, YC_ASSERT_MAP_NULL);
yc_assert(esize, YC_ASSERT_ESIZE_ZERO);
yc_assert(ksize, YC_ASSERT_KSIZE_ZERO);
@ -143,13 +145,11 @@ y_imap_init(y_imap* m, const float load, const size_t ksize, const size_t esize,
YC_ASSERT_MAP_INVALID_EQ);
yc_assert(load <= 1.0f && load > 0.0f, YC_ASSERT_MAP_LOAD_RANGE);
y_Status s = y_map_init(&m->map, load, ksize, esize, hash, eq, kdtor,
s = y_map_init(&m->map, load, ksize, esize, hash, eq, kdtor,
vdtor);
if (y_err(s != y_STATUS_SUCCESS)) return s;
s = y_vec_init(&m->order, y_MAP_INITIAL_CAP, ksize, NULL, NULL);
if (y_err(s != y_STATUS_SUCCESS))
{
y_map_destroy(&m->map);
@ -163,6 +163,9 @@ y_imap_create(const float load, const size_t ksize, const size_t esize,
const y_Hasher hash, const y_Equal eq, const y_Destructor kdtor,
const y_Destructor vdtor)
{
y_Status s;
y_imap* m;
yc_assert(esize, YC_ASSERT_ESIZE_ZERO);
yc_assert(ksize, YC_ASSERT_KSIZE_ZERO);
@ -170,11 +173,10 @@ y_imap_create(const float load, const size_t ksize, const size_t esize,
yc_assert(eq || ksize == sizeof(uint64_t), YC_ASSERT_MAP_INVALID_EQ);
yc_assert(load <= 1.0f && load > 0.0f, YC_ASSERT_MAP_LOAD_RANGE);
y_imap* m = y_calloc(1, sizeof(y_imap) + y_MAP_EXTRA(ksize, esize));
m = y_calloc(1, sizeof(y_imap) + y_MAP_EXTRA(ksize, esize));
if (y_err(m == NULL)) return NULL;
y_Status s = y_imap_init(m, load, ksize, esize, hash, eq, kdtor, vdtor);
s = y_imap_init(m, load, ksize, esize, hash, eq, kdtor, vdtor);
if (y_err(s != y_STATUS_SUCCESS))
{
y_free(m);
@ -326,12 +328,12 @@ y_imap_load(const y_IMap m)
y_Status
y_imap_insert(y_IMap m, const void* key, const void* val)
{
y_Status s;
yc_assert(m, YC_ASSERT_MAP_NULL);
yc_assert(key, YC_ASSERT_KEY_NULL);
yc_assert(val, YC_ASSERT_VAL_NULL);
y_Status s;
if (m->map.size + 1 > m->map.max)
{
s = y_imap_grow(m);
@ -339,11 +341,9 @@ y_imap_insert(y_IMap m, const void* key, const void* val)
}
s = y_map_insert(&m->map, key, val);
if (y_err(s != y_STATUS_SUCCESS)) return s;
s = y_vec_push(&m->order, key);
if (y_err(s != y_STATUS_SUCCESS))
{
y_map_remove(&m->map, key);
@ -359,6 +359,9 @@ y_imap_insert(y_IMap m, const void* key, const void* val)
y_Status
y_imap_insertStringKey(y_IMap m, const char* key, const void* val)
{
y_Status s;
y_str* keyptr;
yc_assert(m, YC_ASSERT_MAP_NULL);
yc_assert(key, YC_ASSERT_KEY_NULL);
yc_assert(val, YC_ASSERT_VAL_NULL);
@ -366,11 +369,9 @@ y_imap_insertStringKey(y_IMap m, const char* key, const void* val)
yc_assert(m->map.key_dtor == y_str_free && m->map.val_dtor != y_str_free,
YC_ASSERT_MAP_STRING_KEY);
y_Status s = y_map_insertStringKey(&m->map, key, val);
s = y_map_insertStringKey(&m->map, key, val);
if (y_err(s != y_STATUS_SUCCESS)) return s;
y_str* keyptr;
#ifdef YC_DEBUG
keyptr = NULL;
#endif // YC_DEBUG
@ -399,13 +400,15 @@ y_imap_insertStringKey(y_IMap m, const char* key, const void* val)
void
y_imap_remove(y_IMap m, const void* key)
{
size_t i;
size_t len;
y_Equal eq;
yc_assert(m, YC_ASSERT_MAP_NULL);
yc_assert(key, YC_ASSERT_KEY_NULL);
y_Equal eq = m->map.eq;
size_t i;
size_t len = m->order.len;
eq = m->map.eq;
len = m->order.len;
for (i = 0; i < len; ++i)
{
@ -448,32 +451,40 @@ y_imap_rbegin(const y_IMap m)
y_Iterator
y_imap_next(const y_IMap m, const y_Iterator it)
{
size_t idx;
yc_assert(m, YC_ASSERT_MAP_NULL);
yc_assert(it, YC_ASSERT_ITERATOR_NULL);
size_t idx = (size_t) (uintptr_t) it;
idx = (size_t) (uintptr_t) it;
return idx < m->map.size ? (void*) (uintptr_t) (idx + 1) : NULL;
}
y_Iterator
y_imap_rnext(const y_IMap m, const y_Iterator it)
{
size_t idx;
yc_assert(m, YC_ASSERT_MAP_NULL);
yc_assert(it, YC_ASSERT_ITERATOR_NULL);
y_UNUSED(m);
size_t idx = (size_t) (uintptr_t) it;
idx = (size_t) (uintptr_t) it;
return idx > 0 ? (void*) (uintptr_t) (idx - 1) : NULL;
}
void*
y_imap_key(const y_IMap m, const y_Iterator it)
{
size_t idx;
yc_assert(m, YC_ASSERT_MAP_NULL);
yc_assert(it, YC_ASSERT_ITERATOR_NULL);
size_t idx = (size_t) (uintptr_t) it;
idx = (size_t) (uintptr_t) it;
return y_vec_get(&m->order, idx - 1);
}

336
src/container/list.c

@ -91,12 +91,16 @@ y_list_checkId(y_list* l, y_ListID id)
for (i = l->emptyHead; i != y_LIST_INVALID_ID;)
{
size_t arrayIdx;
size_t itemIdx;
y_ListIdxs* idxs;
yc_assert(i != id, YC_ASSERT_LIST_INVALID_ID);
size_t arrayIdx = y_LIST_ARRAY_IDX(i);
size_t itemIdx = y_LIST_ITEM_IDX(arrayIdx, i);
arrayIdx = y_LIST_ARRAY_IDX(i);
itemIdx = y_LIST_ITEM_IDX(arrayIdx, i);
y_ListIdxs* idxs = y_LIST_IDXS(l, arrayIdx, itemIdx);
idxs = y_LIST_IDXS(l, arrayIdx, itemIdx);
i = idxs->next;
}
@ -216,6 +220,7 @@ y_list_grow(y_list* l)
if (need_array_realloc)
{
unsigned char** arrays;
y_ListIdxs** idxs;
arrays = y_realloc(l->arrays, (narrays << 1) * sizeof(char*));
if (y_err(arrays == NULL))
@ -226,8 +231,6 @@ y_list_grow(y_list* l)
l->arrays = arrays;
y_ListIdxs** idxs;
idxs = y_realloc(l->idxs, (narrays << 1) * sizeof(y_ListIdxs*));
if (y_err(idxs == NULL))
{
@ -322,14 +325,16 @@ arrays0_err:
y_List
y_list_create(size_t esize, y_Destructor dtor, y_Copier copy)
{
y_Status s;
y_list* l;
yc_assert(esize, YC_ASSERT_ESIZE_ZERO);
y_list* l = y_malloc(sizeof(y_list));
l = y_malloc(sizeof(y_list));
if (y_err(l == NULL)) return NULL;
y_Status status = y_list_init(l, esize, dtor, copy);
if (y_err(status))
s = y_list_init(l, esize, dtor, copy);
if (y_err(s != y_STATUS_SUCCESS))
{
y_free(l);
return NULL;
@ -377,6 +382,10 @@ y_list_esize(const y_List l)
y_ListElem
y_list_head(const y_List l)
{
size_t arrayIdx;
size_t itemIdx;
y_ListElem elem;
yc_assert(l, YC_ASSERT_LIST_NULL);
yc_assert((l->head == y_LIST_INVALID_ID) == (l->tail == y_LIST_INVALID_ID),
YC_ASSERT_LIST_MISMATCH);
@ -390,10 +399,8 @@ y_list_head(const y_List l)