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

Use size_t for Janet types length and capacity and the API those types use #1438

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

GrayJack
Copy link
Contributor

Use size_t for Janet types length and capacity and the API those types use, as discussed on Zulip

src/core/asm.c Show resolved Hide resolved
src/core/asm.c Show resolved Hide resolved
@@ -1384,7 +1384,7 @@
/* Build grammar table */
const JanetKV *st = janet_unwrap_struct(peg);
JanetTable *new_grammar = janet_table(2 * janet_struct_capacity(st));
for (int32_t i = 0; i < janet_struct_capacity(st); i++) {
for (size_t i = 0; i < janet_struct_capacity(st); i++) {

Check notice

Code scanning / CodeQL

Declaration hides variable Note

Variable i hides another variable of the same name (on
line 1293
).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is noise

janet_fixarity(argc, 2);
JanetBuffer *buffer = janet_getbuffer(argv, 0);
double x = janet_getnumber(argv, 1);
int64_t bitindex = (int64_t) x;
int64_t byteindex = bitindex >> 3;
int which_bit = bitindex & 7;
if (bitindex != x || bitindex < 0 || byteindex >= buffer->count)
if (bitindex != x || bitindex < 0 || (size_t) byteindex >= buffer->count)

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note

Equality checks on floating point values can yield unexpected results.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteindex and bitindex are not floats at the time of the comparison

src/core/string.c Fixed Show resolved Hide resolved
src/core/util.c Fixed Show resolved Hide resolved
@pepe
Copy link
Member

pepe commented Apr 16, 2024

On Alpine Linux I see these warnings:

export CFLAGS='-fPIC -O2 -flto'; make -j; make test
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/abstract.boot.o -c src/core/abstract.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/array.boot.o -c src/core/array.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/asm.boot.o -c src/core/asm.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/buffer.boot.o -c src/core/buffer.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/bytecode.boot.o -c src/core/bytecode.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/capi.boot.o -c src/core/capi.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/cfuns.boot.o -c src/core/cfuns.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/compile.boot.o -c src/core/compile.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/corelib.boot.o -c src/core/corelib.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/debug.boot.o -c src/core/debug.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/emit.boot.o -c src/core/emit.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/ev.boot.o -c src/core/ev.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/ffi.boot.o -c src/core/ffi.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/fiber.boot.o -c src/core/fiber.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/gc.boot.o -c src/core/gc.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/inttypes.boot.o -c src/core/inttypes.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/io.boot.o -c src/core/io.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/marsh.boot.o -c src/core/marsh.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/math.boot.o -c src/core/math.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/net.boot.o -c src/core/net.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/os.boot.o -c src/core/os.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/parse.boot.o -c src/core/parse.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/peg.boot.o -c src/core/peg.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/pp.boot.o -c src/core/pp.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/regalloc.boot.o -c src/core/regalloc.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/run.boot.o -c src/core/run.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/specials.boot.o -c src/core/specials.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/state.boot.o -c src/core/state.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/string.boot.o -c src/core/string.c
src/core/array.c: In function 'janet_array_setcount':
src/core/array.c:93:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
   93 |     if (count < 0)
      |               ^
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/strtod.boot.o -c src/core/strtod.c
src/core/buffer.c: In function 'janet_pointer_buffer_unsafe':
src/core/buffer.c:65:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
   65 |     if (count < 0) janet_panic("count < 0");
      |               ^
src/core/buffer.c: In function 'janet_buffer_setcount':
src/core/buffer.c:107:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  107 |     if (count < 0)
      |               ^
src/core/array.c: In function 'cfun_array_remove':
src/core/buffer.c: In function 'cfun_buffer_new_filled':
src/core/array.c:325:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  325 |         if (n < 0)
      |               ^
src/core/buffer.c:213:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  213 |     if (count < 0) count = 0;
      |               ^
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/struct.boot.o -c src/core/struct.c
src/core/buffer.c: In function 'cfun_buffer_push_at':
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/symcache.boot.o -c src/core/symcache.c
src/core/buffer.c:481:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  481 |     if (index < 0 || index > old_count) {
      |               ^
src/core/buffer.c: In function 'cfun_buffer_popn':
src/core/buffer.c:521:11: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  521 |     if (n < 0) janet_panic("n must be non-negative");
      |           ^
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/table.boot.o -c src/core/table.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/tuple.boot.o -c src/core/tuple.c
src/core/buffer.c: In function 'cfun_buffer_blit':
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/util.boot.o -c src/core/util.c
src/core/buffer.c:623:24: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  623 |         if (length_src < 0) length_src = 0;
      |                        ^
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/value.boot.o -c src/core/value.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/vector.boot.o -c src/core/vector.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/vm.boot.o -c src/core/vm.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/core/wrap.boot.o -c src/core/wrap.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/boot/array_test.boot.o -c src/boot/array_test.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/boot/boot.boot.o -c src/boot/boot.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/boot/buffer_test.boot.o -c src/boot/buffer_test.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/boot/number_test.boot.o -c src/boot/number_test.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/boot/system_test.boot.o -c src/boot/system_test.c
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/boot/table_test.boot.o -c src/boot/table_test.c
cc -fPIC -O2 -flto -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -c build/c/shell.c -o build/shell.o
src/core/value.c: In function 'janet_next_impl':
src/core/value.c:182:30: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
  182 |             if (i < len && i >= 0) {
      |                              ^~
src/core/parse.c: In function 'cfun_parse_consume':
src/core/parse.c:924:20: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  924 |         if (offset < 0 || offset > view.len)
      |                    ^
src/core/value.c: In function 'janet_get':
src/core/value.c:533:23: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  533 |             if (index < 0) return janet_wrap_nil();
      |                       ^
src/core/value.c:552:23: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  552 |             if (index < 0) return janet_wrap_nil();
      |                       ^
src/core/value.c: In function 'janet_getindex':
src/core/value.c:587:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  587 |     if (index < 0) janet_panic("expected non-negative index");
      |               ^
src/core/value.c: At top level:
src/core/value.c:442:16: warning: 'getter_checkint' defined but not used [-Wunused-function]
  442 | static int32_t getter_checkint(JanetType type, Janet key, int32_t max) {
      |                ^~~~~~~~~~~~~~~
src/core/string.c: In function 'trim_help_rightedge':
src/core/string.c:586:36: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
  586 |     for (size_t i = str.len - 1; i >= 0; i--)
      |                                    ^~
src/core/pp.c: In function 'janet_formatbv':
src/core/pp.c:899:37: warning: operand of '?:' changes signedness from 'int' to 'size_t' {aka 'long unsigned int'} due to unsignedness of other operand [-Wsign-compare]
  899 |                                   ? (int32_t) strlen(str)
      |                                     ^~~~~~~~~~~~~~~~~~~~~
build/c/shell.c: In function 'longest_common_prefix':
build/c/shell.c:630:37: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
  630 |             for (bv.len = 0; bv.len < minlen; bv.len++) {
      |                                     ^
src/core/util.c: In function 'janet_sorted_keys':
src/core/util.c:864:34: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
  864 |         for (size_t j = i - 1; j >= 0; j--) {
      |                                  ^~
build/c/shell.c: In function 'doc_format':
build/c/shell.c:694:27: warning: comparison of integer expressions of different signedness: 'int32_t' {aka 'int'} and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
  694 |     for (int32_t i = 0; i < janet_string_length(doc); i++) {
      |                           ^
build/c/shell.c: In function 'kshowcomp':
build/c/shell.c:817:32: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
  817 |     for (int i = prefix.len; i < lcp.len; i++) {
      |                                ^
build/c/shell.c:825:32: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int32_t' {aka 'int'} [-Wsign-compare]
  825 |         if (gbl_matches[i].len > maxlen)
      |                                ^
cc -DJANET_BOOTSTRAP -DJANET_BUILD="\"1c5745f6\"" -O0 -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -g -o build/janet_boot build/core/abstract.boot.o build/core/array.boot.o build/core/asm.boot.o build/core/buffer.boot.o build/core/bytecode.boot.o build/core/capi.boot.o build/core/cfuns.boot.o build/core/compile.boot.o build/core/corelib.boot.o build/core/debug.boot.o build/core/emit.boot.o build/core/ev.boot.o build/core/ffi.boot.o build/core/fiber.boot.o build/core/gc.boot.o build/core/inttypes.boot.o build/core/io.boot.o build/core/marsh.boot.o build/core/math.boot.o build/core/net.boot.o build/core/os.boot.o build/core/parse.boot.o build/core/peg.boot.o build/core/pp.boot.o build/core/regalloc.boot.o build/core/run.boot.o build/core/specials.boot.o build/core/state.boot.o build/core/string.boot.o build/core/strtod.boot.o build/core/struct.boot.o build/core/symcache.boot.o build/core/table.boot.o build/core/tuple.boot.o build/core/util.boot.o build/core/value.boot.o build/core/vector.boot.o build/core/vm.boot.o build/core/wrap.boot.o build/boot/array_test.boot.o build/boot/boot.boot.o build/boot/buffer_test.boot.o build/boot/number_test.boot.o build/boot/system_test.boot.o build/boot/table_test.boot.o -lm -lpthread -lrt -ldl
build/janet_boot . JANET_PATH '/home/pp/.local/lib/janet' > build/c/janet.c
cksum build/c/janet.c
4183454676 2919342 build/c/janet.c
cc -fPIC -O2 -flto -std=c99 -Wall -Wextra -Isrc/include -Isrc/conf -fvisibility=hidden -fPIC -c build/c/janet.c -o build/janet.o
src/core/array.c: In function 'janet_array_setcount':
src/core/array.c:93:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
   93 |     if (count < 0)
      |               ^
src/core/array.c: In function 'cfun_array_remove':
src/core/array.c:325:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  325 |         if (n < 0)
      |               ^
src/core/buffer.c: In function 'janet_pointer_buffer_unsafe':
src/core/buffer.c:65:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
   65 |     if (count < 0) janet_panic("count < 0");
      |               ^
src/core/buffer.c: In function 'janet_buffer_setcount':
src/core/buffer.c:107:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  107 |     if (count < 0)
      |               ^
src/core/buffer.c: In function 'cfun_buffer_new_filled':
src/core/buffer.c:213:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  213 |     if (count < 0) count = 0;
      |               ^
src/core/buffer.c: In function 'cfun_buffer_push_at':
src/core/buffer.c:481:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  481 |     if (index < 0 || index > old_count) {
      |               ^
src/core/buffer.c: In function 'cfun_buffer_popn':
src/core/buffer.c:521:11: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  521 |     if (n < 0) janet_panic("n must be non-negative");
      |           ^
src/core/buffer.c: In function 'cfun_buffer_blit':
src/core/buffer.c:623:24: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  623 |         if (length_src < 0) length_src = 0;
      |                        ^
src/core/parse.c: In function 'cfun_parse_consume':
src/core/parse.c:924:20: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  924 |         if (offset < 0 || offset > view.len)
      |                    ^
src/core/pp.c: In function 'janet_formatbv':
src/core/pp.c:899:37: warning: operand of '?:' changes signedness from 'int' to 'size_t' {aka 'long unsigned int'} due to unsignedness of other operand [-Wsign-compare]
  899 |                                   ? (int32_t) strlen(str)
      |                                     ^~~~~~~~~~~~~~~~~~~~~
src/core/string.c: In function 'trim_help_rightedge':
src/core/string.c:586:36: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
  586 |     for (size_t i = str.len - 1; i >= 0; i--)
      |                                    ^~
src/core/util.c: In function 'janet_sorted_keys':
src/core/util.c:864:34: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
  864 |         for (size_t j = i - 1; j >= 0; j--) {
      |                                  ^~
src/core/value.c: In function 'janet_next_impl':
src/core/value.c:182:30: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
  182 |             if (i < len && i >= 0) {
      |                              ^~
src/core/value.c: In function 'janet_get':
src/core/value.c:533:23: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  533 |             if (index < 0) return janet_wrap_nil();
      |                       ^
src/core/value.c:552:23: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  552 |             if (index < 0) return janet_wrap_nil();
      |                       ^
src/core/value.c: In function 'janet_getindex':
src/core/value.c:587:15: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits]
  587 |     if (index < 0) janet_panic("expected non-negative index");
      |               ^
src/core/value.c: At top level:
src/core/value.c:442:16: warning: 'getter_checkint' defined but not used [-Wunused-function]
  442 | static int32_t getter_checkint(JanetType type, Janet key, int32_t max) {

@pepe
Copy link
Member

pepe commented Apr 16, 2024

There aren't any of them at the master branch.

Copy link
Member

@bakpakin bakpakin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General issue right now seems to be some code that won't work on 32 bit platforms and some dubious casts. Making arrays support more than 2^31 elements is not useful unless all user functions can actually access them.

Also some issues with marshalling where arrays might not be representable on all platforms. I'm not sure what the best solution/compromise there is - just disallow marshalling things with lengths that don't fit in 32 bits?

Realistically, I'm not sure I can merge this kind of thing without extensive testing since it will break lots of packages. I would want to go through all packages in pkg.Janet and see if they compile. I think many would probably compile with warnings and many will error out.

src/core/array.c Show resolved Hide resolved
src/core/array.c Show resolved Hide resolved
src/core/buffer.c Outdated Show resolved Hide resolved
@GrayJack GrayJack force-pushed the use-size_t branch 6 times, most recently from 6fd6eef to ff1b324 Compare April 18, 2024 22:37
@GrayJack GrayJack force-pushed the use-size_t branch 2 times, most recently from e8b3d81 to 1baa045 Compare April 19, 2024 06:03
Copy link
Member

@bakpakin bakpakin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more minor changes to address possible integer overflow - also please run make format

src/core/buffer.c Outdated Show resolved Hide resolved
src/core/buffer.c Outdated Show resolved Hide resolved
src/include/janet.h Outdated Show resolved Hide resolved
src/core/string.c Outdated Show resolved Hide resolved
src/core/struct.c Outdated Show resolved Hide resolved
src/core/string.c Outdated Show resolved Hide resolved
Co-authored-by: John W Higgins <wishdev@gmail.com>
@bakpakin
Copy link
Member

So this does seem to work locally by itself, but as evidenced by the extensive changes to janet.h, I probably won't merge this as is - at the very least it would need to be a compile time option. This broke every C extension and program I tried it with completely, spork, jaylib, sqlite, some of personal projects, etc. at a source code leve - literally 0 percent compatibility. Not unexpected. I'm not opposed to breaking the ABI minorly or even majorly on version changes, but incremental upgrades should be fairly easy at a source code level.

That said, if several other huge changes interface breaking come down the line that would also require a huge version bump (new GC / new C API, new compiler, rework of core data structures, etc.), this would be good to merge in. But as is, frankly not tenable. If useful to you though, I would recommend keeping synced with master.

One idea - I wonder if defining ssize_t as jsize_t (which could be, by default int32_t) would solve the problem while allowing for an easy backwards compatibility switch.

#ifdef JANET_USE_SIZE_T
typedef ssize_t jss_t;
typedef size_t js_t;
#else
typedef int32_t jss_t;
typedef uint32_t js_t;
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants