Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to compile on Linux w/ gcc and silence warnings #12

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
subprojects/*/
.meson_last
.vscode

21 changes: 17 additions & 4 deletions include/con4m/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
#if defined(__linux__)
#include <sys/random.h>
#include <threads.h>
#include <endian.h>
#endif

#if defined(__MACH__)
#include <machine/endian.h>
#endif

#ifdef HAVE_MUSL
Expand All @@ -48,21 +53,29 @@ extern pid_t
forkpty(int *, char *, struct termios *, struct winsize *);
#endif

#define min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); \
#define min(a, b) ({ __typeof__ (a) _a = (a), _b = (b); \
_a < _b ? _a : _b; })
#define max(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); \
#define max(a, b) ({ __typeof__ (a) _a = (a), _b = (b); \
_a > _b ? _a : _b; })

#include <vendor.h>
#include <hatrack.h>
#include <con4m/datatypes.h>

#if defined(__LITTLE_ENDIAN__)
#if BYTE_ORDER == LITTLE_ENDIAN
#define little_64(x)
#define little_32(x)
#define little_16(x)
#else // if defined(__BIG_ENDIAN__)
#elif BYTE_ORDER == BIG_ENDIAN
#if defined(linux)
#define little_64(x) x = htole64(x)
#define little_32(x) x = htole32(x)
#define little_16(x) x = htole16(x)
#else
#define little_64(x) x = htonll(x)
#define little_32(x) x = htonl(x)
#define little_16(x) x = htons(x)
#endif
#else
#error unknown endian
#endif
2 changes: 1 addition & 1 deletion include/con4m/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ get_stack_bounds(uint64_t *top, uint64_t *bottom)
uint64_t addr;

pthread_getattr_np(self, &attrs);
pthread_attr_getstack(&attrs, &addr, &size);
pthread_attr_getstack(&attrs, (void **)&addr, &size);

*bottom = (uint64_t)addr;
*top = size + (uint64_t)addr;
Expand Down
6 changes: 3 additions & 3 deletions include/con4m/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ style_debug(char *prefix, const any_str_t *p)
return;

if (p->styling == NULL) {
printf("debug (%s): len: %lld styles: nil\n", prefix, string_codepoint_len(p));
printf("debug (%s): len: %lld styles: nil\n", prefix, (long long)string_codepoint_len(p));
return;
}
else {
printf("debug (%s): len: %lld # styles: %lld\n", prefix, string_codepoint_len(p), p->styling->num_entries);
printf("debug (%s): len: %lld # styles: %lld\n", prefix, (long long)string_codepoint_len(p), (long long)p->styling->num_entries);
}
for (int i = 0; i < p->styling->num_entries; i++) {
style_entry_t entry = p->styling->styles[i];
printf("%d: %llx (%d:%d)\n", i + 1, p->styling->styles[i].info, entry.start, entry.end);
printf("%d: %llx (%d:%d)\n", i + 1, (long long)p->styling->styles[i].info, entry.start, entry.end);
}
}

Expand Down
2 changes: 1 addition & 1 deletion include/con4m/styledb.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ titlecase_on(render_style_t *style)
style->base_style |= TITLE_CASE;
}

const extern border_theme_t *registered_borders;
extern const border_theme_t *registered_borders;

static inline _Bool
set_border_theme(render_style_t *style, char *name)
Expand Down
2 changes: 1 addition & 1 deletion include/hatrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#ifdef __MACH__
#include <mach/clock.h>
#include <mach/mach.h>
#endif

typedef struct hatrack_queue_t queue_t;
#ifndef NO_CON4M
Expand Down Expand Up @@ -109,4 +110,3 @@ free_libc_allocation(void *ptr)
#include <hatrack/vector.h>
#include <hatrack/helpmanager.h>
#endif
#endif
2 changes: 1 addition & 1 deletion src/con4m/crypto/sha.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ sha_cstring_update(sha_ctx *ctx, char *str)
void
sha_int_update(sha_ctx *ctx, uint64_t n)
{
little_64(result);
little_64(n);
EVP_DigestUpdate(ctx->openssl_ctx, &n, sizeof(uint64_t));
}

Expand Down
2 changes: 2 additions & 0 deletions src/con4m/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ con4m_delete_arena(con4m_arena_t *arena)
}
rc_free(arena->late_mutations);

#if defined(MADV_ZERO_WIRED_PAGES)
char *start = ((char *)arena) - page_bytes;
char *end = ((char *)arena->heap_end) - page_bytes;
madvise(start, end - start, MADV_ZERO_WIRED_PAGES);
#endif

arena = prev_active;
}
Expand Down
2 changes: 1 addition & 1 deletion src/con4m/grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ calculate_col_widths(grid_t *grid, int16_t width, int16_t *render_width)
if (units == 0) {
continue;
}
/* fallthrough; */
/* fallthrough */
case DIM_UNSET:
case DIM_AUTO:
if (--num_flex == 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/con4m/lists.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ list_can_coerce_to(type_spec_t *my_type, type_spec_t *dst_type)
{
base_t base = type_spec_get_base(dst_type);

if (base == T_BOOL) {
if (base == (base_t)T_BOOL) {
return true;
}

if (base == T_LIST || base == T_XLIST) {
if (base == (base_t)T_LIST || base == (base_t)T_XLIST) {
type_spec_t *my_item = tspec_get_param(my_type, 0);
type_spec_t *dst_item = tspec_get_param(dst_type, 0);

Expand All @@ -136,11 +136,11 @@ list_coerce_to(flexarray_t *list, type_spec_t *dst_type)
type_spec_t *src_item_type = tspec_get_param(get_my_type(list), 0);
type_spec_t *dst_item_type = tspec_get_param(dst_type, 0);

if (base == T_BOOL) {
if (base == (base_t)T_BOOL) {
return (object_t)(int64_t)(flexarray_view_len(view) != 0);
}

if (base == T_LIST) {
if (base == (base_t)T_LIST) {
flexarray_t *res = con4m_new(dst_type, kw("length", ka(len)));

for (int i = 0; i < len; i++) {
Expand Down
4 changes: 3 additions & 1 deletion src/con4m/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ unmarshal_compact_type(stream_t *s)
return result;
case BT_func:
flags = unmarshal_u8(s);
// Fallthrough.
// fallthrough
case BT_list:
case BT_dict:
case BT_tuple:
Expand All @@ -195,6 +195,8 @@ unmarshal_compact_type(stream_t *s)
type_hash(result, global_type_env);
return result;
}
// unreachable
abort();
}

void
Expand Down
1 change: 1 addition & 0 deletions src/con4m/mixed.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ mixed_set_value(mixed_t *m, type_spec_t *type, void **ptr)
int64_t n = (int64_t)v;

m->held_value = (void *)n;
return;
}
case T_INT:
case T_UINT:
Expand Down
2 changes: 1 addition & 1 deletion src/con4m/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ internal_type_hash(type_spec_t *node, type_hash_ctx *ctx)
// Currently not hashing for future things.
case BT_func:
sha_int_update(ctx->sha, (uint64_t)deets->flags);

break;
case BT_type_var:
num_tvars = (uint64_t)hatrack_dict_get(ctx->memos,
(void *)node->typeid,
Expand Down
4 changes: 2 additions & 2 deletions src/con4m/xlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ xlist_coerce_to(xlist_t *list, type_spec_t *dst_type)
type_spec_t *dst_item_type = tspec_get_param(dst_type, 0);
int64_t len = xlist_len(list);

if (base == T_BOOL) {
if (base == (base_t)T_BOOL) {
return (object_t)(int64_t)(xlist_len(list) != 0);
}

if (base == T_XLIST) {
if (base == (base_t)T_XLIST) {
xlist_t *res = con4m_new(dst_type, kw("length", ka(len)));

for (int i = 0; i < len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/hash/performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ enum {
* ballpark the widest reasonable columns. If a column gets too
* wide, we don't truncate, we just let things look bad :)
*/
#define COL_WIDTH 25
#define COL_WIDTH 26
#define COL_PAD 1
#define FMT_READS "Reads: %u%%"
#define FMT_PUTS "Puts: %u%%"
Expand Down
6 changes: 3 additions & 3 deletions src/tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ test_rand64()
uint64_t random = 0;

random = con4m_rand64();
printf("Random value: %16llx\n", random);
printf("Random value: %16llx\n", (unsigned long long)random);
assert(random != 0);
}

Expand Down Expand Up @@ -505,7 +505,7 @@ main(int argc, char **argv, char **envp)
test4();
table_test();

printf("Sample style: %.16llx\n", style1);
printf("Sample style: %.16llx\n", (unsigned long long)style1);
sha_test();

type_tests();
Expand Down Expand Up @@ -550,6 +550,6 @@ main(int argc, char **argv, char **envp)
stream_putc(sout, '\n');

bottom = top + q;
printf("(start) = %p; (end) = %p (%llu bytes)\n", (void *)top, (void *)bottom, q);
printf("(start) = %p; (end) = %p (%llu bytes)\n", (void *)top, (void *)bottom, (unsigned long long)q);
}
}