From 4c4eff9390c866c075486645613cfe61bf7f094d Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 18 Nov 2018 14:17:50 -0500 Subject: [PATCH] Replace cast with type pun. --- Makefile | 2 ++ ctest/system_test.c | 37 +++++++++++++++++++++++++++++++++++++ src/core/wrap.c | 3 ++- src/include/janet/janet.h | 1 + src/mainclient/line.c | 2 +- 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 ctest/system_test.c diff --git a/Makefile b/Makefile index 76bdedad..a47c1132 100644 --- a/Makefile +++ b/Makefile @@ -152,6 +152,7 @@ valgrind: $(JANET_TARGET) valgrind --leak-check=full -v ./$(JANET_TARGET) test: $(JANET_TARGET) $(TEST_PROGRAMS) + ctest/system_test.out ctest/array_test.out ctest/buffer_test.out ./$(JANET_TARGET) test/suite0.janet @@ -159,6 +160,7 @@ test: $(JANET_TARGET) $(TEST_PROGRAMS) ./$(JANET_TARGET) test/suite2.janet valtest: $(JANET_TARGET) $(TEST_PROGRAMS) + valgrind --leak-check=full -b ctest/system_test.out valgrind --leak-check=full -v ctest/array_test.out valgrind --leak-check=full -v ctest/buffer_test.out valgrind --leak-check=full -v ./$(JANET_TARGET) test/suite0.janet diff --git a/ctest/system_test.c b/ctest/system_test.c new file mode 100644 index 00000000..d177721b --- /dev/null +++ b/ctest/system_test.c @@ -0,0 +1,37 @@ + +/* +* Copyright (c) 2018 Calvin Rose +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to +* deal in the Software without restriction, including without limitation the +* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +* sell copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +*/ + +#include +#include +#include + +int main() { + +#ifdef JANET_32 + assert(sizeof(void *) == 4); +#else + assert(sizeof(void *) == 8); +#endif + + return 0; +} diff --git a/src/core/wrap.c b/src/core/wrap.c index 5c2d2179..0d65bdcd 100644 --- a/src/core/wrap.c +++ b/src/core/wrap.c @@ -36,7 +36,8 @@ void *janet_nanbox_to_pointer(Janet x) { #else x.i64 = (x.i64 << 16) >> 16; #endif - return (void *)x.i64; + + return x.pointer; } Janet janet_nanbox_from_pointer(void *p, uint64_t tagmask) { diff --git a/src/include/janet/janet.h b/src/include/janet/janet.h index a221dc10..e58095d1 100644 --- a/src/include/janet/janet.h +++ b/src/include/janet/janet.h @@ -342,6 +342,7 @@ union Janet { uint64_t u64; int64_t i64; double real; + void *pointer; }; #define janet_u64(x) ((x).u64) diff --git a/src/mainclient/line.c b/src/mainclient/line.c index 23463f21..3a43fa71 100644 --- a/src/mainclient/line.c +++ b/src/mainclient/line.c @@ -35,7 +35,7 @@ int janet_line_getter(JanetArgs args) { static void simpleline(JanetBuffer *buffer) { buffer->count = 0; - char c; + int c; for (;;) { c = fgetc(stdin); if (feof(stdin) || c < 0) {