Compare commits

...

4 Commits

Author SHA1 Message Date
Doug Coleman 9b8a786b44 .travis: Try clang6 2018-07-15 18:02:44 -05:00
Doug Coleman e43e85a083 .travis: Update apt 2018-07-15 16:45:52 -05:00
Doug Coleman 1c44962647 factor: Install libc++ 2018-07-15 15:23:22 -05:00
Doug Coleman 1ad7609a5d vm: WIP remove warnings, use C++ style casts...there are hundreds of warnings left. 2018-07-15 14:18:42 -05:00
36 changed files with 173 additions and 162 deletions

View File

@ -21,6 +21,7 @@ branches:
- clean-macosx-x86-32 - clean-macosx-x86-32
addons: addons:
apt: apt:
update: true
packages: packages:
- links - links
- libblas-dev - libblas-dev
@ -31,6 +32,7 @@ addons:
- cmake - cmake
- libaio-dev - libaio-dev
- libsnappy-dev - libsnappy-dev
- clang-6.0
before_install: before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./build.sh deps-macosx ; else ./build.sh deps-apt-get ; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./build.sh deps-macosx ; else ./build.sh deps-apt-get ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew ls --versions snappy > /dev/null || brew install snappy; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew ls --versions snappy > /dev/null || brew install snappy; fi
@ -60,6 +62,7 @@ before_install:
- git remote set-branches --add origin clean-macosx-x86-64 - git remote set-branches --add origin clean-macosx-x86-64
- git remote set-branches --add origin clean-macosx-x86-32 - git remote set-branches --add origin clean-macosx-x86-32
- git fetch # so we can see which vocabs changed versus origin/master... - git fetch # so we can see which vocabs changed versus origin/master...
- clang --version
script: script:
- echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, TRAVIS_PULL_REQUEST_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH" - echo "TRAVIS_BRANCH=$TRAVIS_BRANCH, TRAVIS_PULL_REQUEST_BRANCH=$TRAVIS_PULL_REQUEST_BRANCH"
- export CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}" - export CI_BRANCH="${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}"

View File

@ -6,13 +6,13 @@ ifdef CONFIG
include $(CONFIG) include $(CONFIG)
CFLAGS = -Wall \ CFLAGS = -Wall -Weverything -Wno-c++98-compat-pedantic -Wno-padded \
-pedantic \ -pedantic \
-DFACTOR_VERSION="$(VERSION)" \ -DFACTOR_VERSION="$(VERSION)" \
-DFACTOR_GIT_LABEL="$(GIT_LABEL)" \ -DFACTOR_GIT_LABEL="$(GIT_LABEL)" \
$(SITE_CFLAGS) $(SITE_CFLAGS)
CXXFLAGS += -std=c++11 CXXFLAGS += -std=c++14
ifdef DEBUG ifdef DEBUG
CFLAGS += -g -DFACTOR_DEBUG CFLAGS += -g -DFACTOR_DEBUG

View File

@ -8,7 +8,7 @@ struct aging_space : bump_allocator {
object* allot(cell size) { object* allot(cell size) {
if (here + size > end) if (here + size > end)
return NULL; return nullptr;
object* obj = bump_allocator::allot(size); object* obj = bump_allocator::allot(size);
starts.record_object_start_offset(obj); starts.record_object_start_offset(obj);

View File

@ -16,10 +16,10 @@ char* factor_vm::pinned_alien_offset(cell obj) {
return (char*)ptr->address; return (char*)ptr->address;
} }
case F_TYPE: case F_TYPE:
return NULL; return nullptr;
default: default:
type_error(ALIEN_TYPE, obj); type_error(ALIEN_TYPE, obj);
return NULL; // can't happen return nullptr; // can't happen
} }
} }
@ -118,12 +118,12 @@ void factor_vm::primitive_dlsym() {
if (to_boolean(library.value())) { if (to_boolean(library.value())) {
dll* d = untag_check<dll>(library.value()); dll* d = untag_check<dll>(library.value());
if (d->handle == NULL) if (d->handle == nullptr)
ctx->replace(false_object); ctx->replace(false_object);
else else
ctx->replace(allot_alien(ffi_dlsym(d, sym))); ctx->replace(allot_alien(ffi_dlsym(d, sym)));
} else } else
ctx->replace(allot_alien(ffi_dlsym(NULL, sym))); ctx->replace(allot_alien(ffi_dlsym(nullptr, sym)));
} }
// look up a symbol in a native library // look up a symbol in a native library
@ -138,25 +138,25 @@ void factor_vm::primitive_dlsym_raw() {
if (to_boolean(library.value())) { if (to_boolean(library.value())) {
dll* d = untag_check<dll>(library.value()); dll* d = untag_check<dll>(library.value());
if (d->handle == NULL) if (d->handle == nullptr)
ctx->replace(false_object); ctx->replace(false_object);
else else
ctx->replace(allot_alien(ffi_dlsym_raw(d, sym))); ctx->replace(allot_alien(ffi_dlsym_raw(d, sym)));
} else } else
ctx->replace(allot_alien(ffi_dlsym_raw(NULL, sym))); ctx->replace(allot_alien(ffi_dlsym_raw(nullptr, sym)));
} }
// close a native library handle // close a native library handle
void factor_vm::primitive_dlclose() { void factor_vm::primitive_dlclose() {
dll* d = untag_check<dll>(ctx->pop()); dll* d = untag_check<dll>(ctx->pop());
if (d->handle != NULL) if (d->handle != nullptr)
ffi_dlclose(d); ffi_dlclose(d);
} }
void factor_vm::primitive_dll_validp() { void factor_vm::primitive_dll_validp() {
cell library = ctx->peek(); cell library = ctx->peek();
if (to_boolean(library)) if (to_boolean(library))
ctx->replace(tag_boolean(untag_check<dll>(library)->handle != NULL)); ctx->replace(tag_boolean(untag_check<dll>(library)->handle != nullptr));
else else
ctx->replace(special_objects[OBJ_CANONICAL_TRUE]); ctx->replace(special_objects[OBJ_CANONICAL_TRUE]);
} }
@ -169,10 +169,10 @@ char* factor_vm::alien_offset(cell obj) {
case ALIEN_TYPE: case ALIEN_TYPE:
return (char*)untag<alien>(obj)->address; return (char*)untag<alien>(obj)->address;
case F_TYPE: case F_TYPE:
return NULL; return nullptr;
default: default:
type_error(ALIEN_TYPE, obj); type_error(ALIEN_TYPE, obj);
return NULL; // can't happen return nullptr; // can't happen
} }
} }

View File

@ -9,7 +9,7 @@ inline code_block* factor_vm::allot_code_block(cell size,
cell block_size = size + sizeof(code_block); cell block_size = size + sizeof(code_block);
code_block* block = code->allocator->allot(block_size); code_block* block = code->allocator->allot(block_size);
if (block == NULL) { if (block == nullptr) {
// If allocation failed, do a full GC and compact the code heap. // If allocation failed, do a full GC and compact the code heap.
// A full GC that occurs as a result of the data heap filling up does not // A full GC that occurs as a result of the data heap filling up does not
// trigger a compaction. This setup ensures that most GCs do not compact // trigger a compaction. This setup ensures that most GCs do not compact
@ -19,7 +19,7 @@ inline code_block* factor_vm::allot_code_block(cell size,
block = code->allocator->allot(block_size); block = code->allocator->allot(block_size);
// Insufficient room even after code GC, give up // Insufficient room even after code GC, give up
if (block == NULL) { if (block == nullptr) {
std::cout << "Code heap used: " << code->allocator->occupied_space() std::cout << "Code heap used: " << code->allocator->occupied_space()
<< "\n"; << "\n";
std::cout << "Code heap free: " << code->allocator->free_space << "\n"; std::cout << "Code heap free: " << code->allocator->free_space << "\n";

View File

@ -776,7 +776,7 @@ void factor_vm::bignum_divide_unsigned_large_denominator(
} }
} }
if (quotient != NULL) { if (quotient != nullptr) {
bignum *q_ = allot_bignum(length_n - length_d, q_negative_p); bignum *q_ = allot_bignum(length_n - length_d, q_negative_p);
data_root<bignum> q(q_, this); data_root<bignum> q(q_, this);
@ -793,7 +793,7 @@ void factor_vm::bignum_divide_unsigned_large_denominator(
shift); shift);
bignum_destructive_normalization(denominator.untagged(), v, shift); bignum_destructive_normalization(denominator.untagged(), v, shift);
bignum_divide_unsigned_normalized(u.untagged(), v, q.untagged()); bignum_divide_unsigned_normalized(u.untagged(), v, q.untagged());
if (remainder != NULL) if (remainder != nullptr)
bignum_destructive_unnormalization(u.untagged(), shift); bignum_destructive_unnormalization(u.untagged(), shift);
} }
@ -806,7 +806,7 @@ void factor_vm::bignum_divide_unsigned_large_denominator(
(BIGNUM_REF(u.untagged(), (length_n - 1))) = 0; (BIGNUM_REF(u.untagged(), (length_n - 1))) = 0;
bignum_divide_unsigned_normalized(u.untagged(), bignum_divide_unsigned_normalized(u.untagged(),
denominator.untagged(), denominator.untagged(),
NULL); nullptr);
} else { } else {
bignum* v = allot_bignum(length_d, 0); bignum* v = allot_bignum(length_d, 0);
bignum_destructive_normalization(numerator.untagged(), bignum_destructive_normalization(numerator.untagged(),
@ -815,14 +815,14 @@ void factor_vm::bignum_divide_unsigned_large_denominator(
bignum_destructive_normalization(denominator.untagged(), bignum_destructive_normalization(denominator.untagged(),
v, v,
shift); shift);
bignum_divide_unsigned_normalized(u.untagged(), v, NULL); bignum_divide_unsigned_normalized(u.untagged(), v, nullptr);
if (remainder != NULL) if (remainder != nullptr)
bignum_destructive_unnormalization(u.untagged(), shift); bignum_destructive_unnormalization(u.untagged(), shift);
} }
} }
u.set_untagged(bignum_trim(u.untagged())); u.set_untagged(bignum_trim(u.untagged()));
if (remainder != NULL) if (remainder != nullptr)
*remainder = u.untagged(); *remainder = u.untagged();
} }
@ -836,7 +836,7 @@ void factor_vm::bignum_divide_unsigned_normalized(bignum* u, bignum* v,
bignum_digit_type* u_scan_start = (u_scan - v_length); bignum_digit_type* u_scan_start = (u_scan - v_length);
bignum_digit_type* v_start = (BIGNUM_START_PTR(v)); bignum_digit_type* v_start = (BIGNUM_START_PTR(v));
bignum_digit_type* v_end = (v_start + v_length); bignum_digit_type* v_end = (v_start + v_length);
bignum_digit_type* q_scan = NULL; bignum_digit_type* q_scan = nullptr;
bignum_digit_type v1 = (v_end[-1]); bignum_digit_type v1 = (v_end[-1]);
bignum_digit_type v2 = (v_end[-2]); bignum_digit_type v2 = (v_end[-2]);
bignum_digit_type ph; // high half of double-digit product bignum_digit_type ph; // high half of double-digit product
@ -1422,7 +1422,7 @@ bignum* factor_vm::bignum_magnitude_ash(bignum* arg1_, fixnum n) {
data_root<bignum> arg1(arg1_, this); data_root<bignum> arg1(arg1_, this);
bignum* result = NULL; bignum* result = nullptr;
bignum_digit_type* scan1; bignum_digit_type* scan1;
bignum_digit_type* scanr; bignum_digit_type* scanr;
bignum_digit_type* end; bignum_digit_type* end;

View File

@ -21,9 +21,9 @@ callback_heap::callback_heap(cell size, factor_vm* parent) {
callback_heap::~callback_heap() { callback_heap::~callback_heap() {
delete allocator; delete allocator;
allocator = NULL; allocator = nullptr;
delete seg; delete seg;
seg = NULL; seg = nullptr;
} }
instruction_operand callback_heap::callback_operand(code_block* stub, instruction_operand callback_heap::callback_operand(code_block* stub,

View File

@ -140,11 +140,11 @@ cell factor_vm::compute_dlsym_address(array* parameters,
bool toc) { bool toc) {
cell symbol = array_nth(parameters, index); cell symbol = array_nth(parameters, index);
cell library = array_nth(parameters, index + 1); cell library = array_nth(parameters, index + 1);
dll* d = to_boolean(library) ? untag<dll>(library) : NULL; dll* d = to_boolean(library) ? untag<dll>(library) : nullptr;
cell undef = (cell)factor::undefined_symbol; cell undef = (cell)factor::undefined_symbol;
undef = toc ? FUNCTION_TOC_POINTER(undef) : FUNCTION_CODE_POINTER(undef); undef = toc ? FUNCTION_TOC_POINTER(undef) : FUNCTION_CODE_POINTER(undef);
if (d != NULL && !d->handle) if (d != nullptr && !d->handle)
return undef; return undef;
FACTOR_ASSERT(TAG(symbol) == BYTE_ARRAY_TYPE); FACTOR_ASSERT(TAG(symbol) == BYTE_ARRAY_TYPE);
@ -188,7 +188,7 @@ cell factor_vm::compute_external_address(instruction_operand op) {
code_block* compiled = op.compiled; code_block* compiled = op.compiled;
array* parameters = to_boolean(compiled->parameters) array* parameters = to_boolean(compiled->parameters)
? untag<array>(compiled->parameters) ? untag<array>(compiled->parameters)
: NULL; : nullptr;
cell idx = op.index; cell idx = op.index;
relocation_type rel_type = op.rel.type(); relocation_type rel_type = op.rel.type();

View File

@ -20,9 +20,9 @@ code_heap::code_heap(cell size) {
code_heap::~code_heap() { code_heap::~code_heap() {
delete allocator; delete allocator;
allocator = NULL; allocator = nullptr;
delete seg; delete seg;
seg = NULL; seg = nullptr;
} }
void code_heap::write_barrier(code_block* compiled) { void code_heap::write_barrier(code_block* compiled) {

View File

@ -277,8 +277,8 @@ void factor_vm::primitive_load_locals() {
memcpy((cell*)(ctx->retainstack + sizeof(cell)), memcpy((cell*)(ctx->retainstack + sizeof(cell)),
(cell*)(ctx->datastack - sizeof(cell) * (count - 1)), (cell*)(ctx->datastack - sizeof(cell) * (count - 1)),
sizeof(cell) * count); sizeof(cell) * count);
ctx->datastack -= sizeof(cell) * count; ctx->datastack -= sizeof(cell) * (cell)count;
ctx->retainstack += sizeof(cell) * count; ctx->retainstack += sizeof(cell) * (cell)count;
} }
} }

View File

@ -60,7 +60,7 @@ void factor_vm::dispatch_resumable_signal(cell* sp, cell* pc, cell handler) {
index = SIGNAL_HANDLER_WORD; index = SIGNAL_HANDLER_WORD;
} else if (offset == 16 - sizeof(cell)) { } else if (offset == 16 - sizeof(cell)) {
// Make a fake frame for the leaf procedure // Make a fake frame for the leaf procedure
FACTOR_ASSERT(code->code_block_for_address(*pc) != NULL); FACTOR_ASSERT(code->code_block_for_address(*pc) != nullptr);
delta = LEAF_FRAME_SIZE; delta = LEAF_FRAME_SIZE;
index = LEAF_SIGNAL_HANDLER_WORD; index = LEAF_SIGNAL_HANDLER_WORD;
} else { } else {

View File

@ -19,7 +19,7 @@ static const unsigned char call_opcode = 0xe8;
static const unsigned char jmp_opcode = 0xe9; static const unsigned char jmp_opcode = 0xe9;
inline static unsigned char call_site_opcode(cell return_address) { inline static unsigned char call_site_opcode(cell return_address) {
return *(unsigned char*)(return_address - 5); return *reinterpret_cast<unsigned char*>(return_address - 5);
} }
inline static void check_call_site(cell return_address) { inline static void check_call_site(cell return_address) {

View File

@ -56,7 +56,7 @@ void factor_vm::init_factor(vm_parameters* p) {
p->executable_path = vm_executable_path(); p->executable_path = vm_executable_path();
if (p->image_path == NULL) { if (p->image_path == nullptr) {
if (embedded_image_p()) { if (embedded_image_p()) {
p->embedded_image = true; p->embedded_image = true;
p->image_path = safe_strdup(p->executable_path); p->image_path = safe_strdup(p->executable_path);
@ -71,7 +71,7 @@ void factor_vm::init_factor(vm_parameters* p) {
retainstack_size = p->retainstack_size; retainstack_size = p->retainstack_size;
callstack_size = p->callstack_size; callstack_size = p->callstack_size;
ctx = NULL; ctx = nullptr;
spare_ctx = new_context(); spare_ctx = new_context();
callbacks = new callback_heap(p->callback_size, this); callbacks = new callback_heap(p->callback_size, this);

View File

@ -84,7 +84,10 @@ FACTOR_STDCALL(struct bar) ffi_test_19(long x, long y, long z) {
} }
void ffi_test_20(double x1, double x2, double x3, double y1, double y2, void ffi_test_20(double x1, double x2, double x3, double y1, double y2,
double y3, double z1, double z2, double z3) {} double y3, double z1, double z2, double z3) {
(void) x1, (void) x2, (void) x3, (void) y1, (void) y2,
(void) y3, (void) z1, (void) z2, (void) z3;
}
long long ffi_test_21(long x, long y) { return (long long) x * (long long) y; } long long ffi_test_21(long x, long y) { return (long long) x * (long long) y; }
@ -309,7 +312,7 @@ unsigned long long ffi_test_60(unsigned long long x) {
/* C99 features */ /* C99 features */
#ifndef _MSC_VER #ifndef _MSC_VER
struct bool_and_ptr ffi_test_61() { struct bool_and_ptr ffi_test_61(void) {
struct bool_and_ptr bap; struct bool_and_ptr bap;
bap.b = true; bap.b = true;
bap.ptr = NULL; bap.ptr = NULL;
@ -318,14 +321,14 @@ struct bool_and_ptr ffi_test_61() {
#endif #endif
struct uint_pair ffi_test_62() { struct uint_pair ffi_test_62(void) {
struct uint_pair uip; struct uint_pair uip;
uip.a = 0xabcdefab; uip.a = 0xabcdefab;
uip.b = 0x12345678; uip.b = 0x12345678;
return uip; return uip;
} }
struct ulonglong_pair ffi_test_63() { struct ulonglong_pair ffi_test_63(void) {
struct ulonglong_pair ullp; struct ulonglong_pair ullp;
ullp.a = 0xabcdefabcdefabcd; ullp.a = 0xabcdefabcdefabcd;
ullp.b = 0x1234567891234567; ullp.b = 0x1234567891234567;
@ -360,6 +363,8 @@ void* bug1021_test_1(void* x, int y) {
} }
int bug1021_test_2(int x, char *y, void *z) { int bug1021_test_2(int x, char *y, void *z) {
(void) x;
(void) z;
return y[0]; return y[0];
} }

View File

@ -161,7 +161,7 @@ struct test_struct_16 {
FACTOR_EXPORT struct test_struct_16 ffi_test_43(float x, int a); FACTOR_EXPORT struct test_struct_16 ffi_test_43(float x, int a);
FACTOR_EXPORT struct test_struct_14 ffi_test_44(); FACTOR_EXPORT struct test_struct_14 ffi_test_44(void);
/* C99 features */ /* C99 features */
#ifndef _MSC_VER #ifndef _MSC_VER
@ -211,7 +211,7 @@ struct bool_and_ptr {
void* ptr; void* ptr;
}; };
FACTOR_EXPORT struct bool_and_ptr ffi_test_61(); FACTOR_EXPORT struct bool_and_ptr ffi_test_61(void);
#endif #endif
@ -220,14 +220,14 @@ struct uint_pair {
unsigned int b; unsigned int b;
}; };
FACTOR_EXPORT struct uint_pair ffi_test_62(); FACTOR_EXPORT struct uint_pair ffi_test_62(void);
struct ulonglong_pair { struct ulonglong_pair {
unsigned long long a; unsigned long long a;
unsigned long long b; unsigned long long b;
}; };
FACTOR_EXPORT struct ulonglong_pair ffi_test_63(); FACTOR_EXPORT struct ulonglong_pair ffi_test_63(void);
FACTOR_EXPORT int ffi_test_64(int n, ...); FACTOR_EXPORT int ffi_test_64(int n, ...);
FACTOR_EXPORT double ffi_test_65(int n, ...); FACTOR_EXPORT double ffi_test_65(int n, ...);

View File

@ -155,7 +155,7 @@ free_heap_block* free_list_allocator<Block>::find_free_block(cell size) {
// Allocate a block this big // Allocate a block this big
free_heap_block* large_block = find_free_block(large_block_size); free_heap_block* large_block = find_free_block(large_block_size);
if (!large_block) if (!large_block)
return NULL; return nullptr;
large_block = split_free_block(large_block, large_block_size); large_block = split_free_block(large_block, large_block_size);
@ -192,7 +192,7 @@ free_heap_block* free_list_allocator<Block>::find_free_block(cell size) {
return block; return block;
} }
return NULL; return nullptr;
} }
} }
@ -206,7 +206,7 @@ Block* free_list_allocator<Block>::allot(cell size) {
block = split_free_block(block, size); block = split_free_block(block, size);
return (Block*)block; return (Block*)block;
} }
return NULL; return nullptr;
} }
template <typename Block> template <typename Block>
@ -299,7 +299,7 @@ template <typename Iterator, typename Fixup>
void free_list_allocator<Block>::iterate(Iterator& iter, Fixup fixup) { void free_list_allocator<Block>::iterate(Iterator& iter, Fixup fixup) {
cell scan = this->start; cell scan = this->start;
while (scan != this->end) { while (scan != this->end) {
Block* block = (Block*)scan; Block* block = reinterpret_cast<Block*>(scan);
cell size = fixup.size(block); cell size = fixup.size(block);
if (!block->free_p()) if (!block->free_p())
iter(block, size); iter(block, size);

View File

@ -31,13 +31,13 @@ gc_state::gc_state(gc_op op, factor_vm* parent) : op(op) {
event = new gc_event(op, parent); event = new gc_event(op, parent);
start_time = nano_count(); start_time = nano_count();
} else } else
event = NULL; event = nullptr;
} }
gc_state::~gc_state() { gc_state::~gc_state() {
if (event) { if (event) {
delete event; delete event;
event = NULL; event = nullptr;
} }
} }
@ -139,7 +139,7 @@ void factor_vm::gc(gc_op op, cell requested_size) {
if (ctx) if (ctx)
ctx->callstack_seg->set_border_locked(true); ctx->callstack_seg->set_border_locked(true);
delete current_gc; delete current_gc;
current_gc = NULL; current_gc = nullptr;
// Check the invariant again, just in case. // Check the invariant again, just in case.
FACTOR_ASSERT(!data->high_fragmentation_p()); FACTOR_ASSERT(!data->high_fragmentation_p());
@ -168,7 +168,7 @@ void factor_vm::primitive_disable_gc_events() {
growable_array result(this); growable_array result(this);
std::vector<gc_event>* gc_events = this->gc_events; std::vector<gc_event>* gc_events = this->gc_events;
this->gc_events = NULL; this->gc_events = nullptr;
FACTOR_FOR_EACH(*gc_events) { FACTOR_FOR_EACH(*gc_events) {
gc_event event = *iter; gc_event event = *iter;

View File

@ -13,8 +13,8 @@ bool factor_arg(const vm_char* str, const vm_char* arg, cell* value) {
vm_parameters::vm_parameters() { vm_parameters::vm_parameters() {
embedded_image = false; embedded_image = false;
image_path = NULL; image_path = nullptr;
executable_path = NULL; executable_path = nullptr;
datastack_size = 32 * sizeof(cell); datastack_size = 32 * sizeof(cell);
retainstack_size = 32 * sizeof(cell); retainstack_size = 32 * sizeof(cell);
@ -36,7 +36,7 @@ vm_parameters::vm_parameters() {
signals = true; signals = true;
#ifdef WINDOWS #ifdef WINDOWS
console = GetConsoleWindow() != NULL; console = GetConsoleWindow() != nullptr;
#else #else
console = true; console = true;
#endif #endif
@ -231,7 +231,7 @@ char *threadsafe_strerror(int errnum) {
void factor_vm::load_image(vm_parameters* p) { void factor_vm::load_image(vm_parameters* p) {
FILE* file = OPEN_READ(p->image_path); FILE* file = OPEN_READ(p->image_path);
if (file == NULL) { if (file == nullptr) {
std::cout << "Cannot open image file: " << p->image_path << std::endl; std::cout << "Cannot open image file: " << p->image_path << std::endl;
char *msg = threadsafe_strerror(errno); char *msg = threadsafe_strerror(errno);
std::cout << "strerror:2: " << msg << std::endl; std::cout << "strerror:2: " << msg << std::endl;
@ -289,7 +289,7 @@ bool factor_vm::save_image(const vm_char* saving_filename,
(save_special_p(i) ? special_objects[i] : false_object); (save_special_p(i) ? special_objects[i] : false_object);
FILE* file = OPEN_WRITE(saving_filename); FILE* file = OPEN_WRITE(saving_filename);
if (file == NULL) if (file == nullptr)
return false; return false;
if (safe_fwrite(&h, sizeof(image_header), 1, file) != 1) if (safe_fwrite(&h, sizeof(image_header), 1, file) != 1)
return false; return false;

View File

@ -53,7 +53,7 @@ FILE* factor_vm::safe_fopen(char* filename, const char* mode) {
FILE* file; FILE* file;
for (;;) { for (;;) {
file = fopen(filename, mode); file = fopen(filename, mode);
if (file == NULL) if (file == nullptr)
io_error_if_not_EINTR(); io_error_if_not_EINTR();
else else
break; break;

View File

@ -12,12 +12,12 @@ static const cell data_alignment = 16;
// Must match leaf-stack-frame-size in core/layouts/layouts.factor // Must match leaf-stack-frame-size in core/layouts/layouts.factor
#define LEAF_FRAME_SIZE 16 #define LEAF_FRAME_SIZE 16
#define WORD_SIZE (signed)(sizeof(cell) * 8) #define WORD_SIZE static_cast<signed>(sizeof(cell) * 8)
#define TAG_MASK 15 #define TAG_MASK 15
#define TAG_BITS 4 #define TAG_BITS 4
#define TAG(x) ((cell)(x) & TAG_MASK) #define TAG(x) (reinterpret_cast<cell>(x) & static_cast<cell>(TAG_MASK))
#define UNTAG(x) ((cell)(x) & ~TAG_MASK) #define UNTAG(x) (reinterpret_cast<cell>(x) & static_cast<cell>(~TAG_MASK))
#define RETAG(x, tag) (UNTAG(x) | (tag)) #define RETAG(x, tag) (UNTAG(x) | (tag))
// Type tags, should be kept in sync with: // Type tags, should be kept in sync with:
@ -100,11 +100,11 @@ inline static bool immediate_p(cell obj) {
inline static fixnum untag_fixnum(cell tagged) { inline static fixnum untag_fixnum(cell tagged) {
FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE); FACTOR_ASSERT(TAG(tagged) == FIXNUM_TYPE);
return ((fixnum)tagged) >> TAG_BITS; return static_cast<fixnum>(tagged) >> TAG_BITS;
} }
inline static cell tag_fixnum(fixnum untagged) { inline static cell tag_fixnum(fixnum untagged) {
return ( (cell)untagged << TAG_BITS) | FIXNUM_TYPE; return ( static_cast<cell>(untagged) << TAG_BITS) | FIXNUM_TYPE;
} }
#define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT #define NO_TYPE_CHECK static const cell type_number = TYPE_COUNT
@ -128,7 +128,7 @@ struct object {
cell slot_count() const; cell slot_count() const;
template <typename Fixup> cell slot_count(Fixup fixup) const; template <typename Fixup> cell slot_count(Fixup fixup) const;
cell* slots() const { return (cell*)this; } cell* slots() const { return const_cast<cell*>(reinterpret_cast<const cell*>(this)); }
template <typename Iterator> void each_slot(Iterator& iter); template <typename Iterator> void each_slot(Iterator& iter);
@ -148,9 +148,9 @@ struct object {
bool forwarding_pointer_p() const { return (header & 2) == 2; } bool forwarding_pointer_p() const { return (header & 2) == 2; }
object* forwarding_pointer() const { return (object*)UNTAG(header); } object* forwarding_pointer() const { return reinterpret_cast<object*>(UNTAG(header)); }
void forward_to(object* pointer) { header = ((cell)pointer | 2); } void forward_to(object* pointer) { header = reinterpret_cast<cell>(pointer) | 2; }
}; };
// Assembly code makes assumptions about the layout of this struct // Assembly code makes assumptions about the layout of this struct
@ -160,7 +160,7 @@ struct array : public object {
// tagged // tagged
cell capacity; cell capacity;
cell* data() const { return (cell*)(this + 1); } cell* data() const { return const_cast<cell*>(reinterpret_cast<const cell*>(this + 1)); }
}; };
// These are really just arrays, but certain elements have special // These are really just arrays, but certain elements have special
@ -181,7 +181,7 @@ struct bignum : public object {
// tagged // tagged
cell capacity; cell capacity;
cell* data() const { return (cell*)(this + 1); } cell* data() const { return const_cast<cell*>(reinterpret_cast<const cell*>(this + 1)); }
}; };
struct byte_array : public object { struct byte_array : public object {
@ -196,7 +196,7 @@ struct byte_array : public object {
#endif #endif
template <typename Scalar> Scalar* data() const { template <typename Scalar> Scalar* data() const {
return (Scalar*)(this + 1); return const_cast<Scalar*>(reinterpret_cast<const Scalar*>(this + 1));
} }
}; };
@ -210,7 +210,7 @@ struct string : public object {
// tagged // tagged
cell hashcode; cell hashcode;
uint8_t* data() const { return (uint8_t*)(this + 1); } uint8_t* data() const { return const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(this + 1)); }
}; };
struct code_block; struct code_block;
@ -319,12 +319,12 @@ struct callstack : public object {
cell length; cell length;
cell frame_top_at(cell offset) const { cell frame_top_at(cell offset) const {
return (cell)(this + 1) + offset; return reinterpret_cast<cell>(this + 1) + offset;
} }
void* top() const { return (void*)(this + 1); } void* top() const { return const_cast<void*>(static_cast<const void*>(this + 1)); }
void* bottom() const { void* bottom() const {
return (void*)((cell)(this + 1) + untag_fixnum(length)); return const_cast<void*>(reinterpret_cast<const void*>((this + 1) + untag_fixnum(length)));
} }
}; };
@ -333,11 +333,11 @@ struct tuple : public object {
// tagged layout // tagged layout
cell layout; cell layout;
cell* data() const { return (cell*)(this + 1); } cell* data() const { return const_cast<cell*>(reinterpret_cast<const cell*>(this + 1)); }
}; };
inline static cell tuple_capacity(const tuple_layout *layout) { inline static cell tuple_capacity(const tuple_layout *layout) {
return untag_fixnum(layout->size); return static_cast<cell>(untag_fixnum(layout->size));
} }
inline static cell tuple_size(const tuple_layout* layout) { inline static cell tuple_size(const tuple_layout* layout) {
@ -345,7 +345,7 @@ inline static cell tuple_size(const tuple_layout* layout) {
} }
inline static cell string_capacity(const string* str) { inline static cell string_capacity(const string* str) {
return untag_fixnum(str->length); return static_cast<cell>(untag_fixnum(str->length));
} }
inline static cell string_size(cell size) { return sizeof(string) + size; } inline static cell string_size(cell size) { return sizeof(string) + size; }

View File

@ -183,7 +183,7 @@ static void* mach_exception_thread(void* arg) {
abort(); abort();
} }
} }
return NULL; // quiet warning return nullptr; // quiet warning
} }
// Initialize the Mach exception handler thread. // Initialize the Mach exception handler thread.
@ -210,7 +210,7 @@ void mach_initialize() {
mask = EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC; mask = EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION | EXC_MASK_ARITHMETIC;
// Create the thread listening on the exception port. // Create the thread listening on the exception port.
start_thread(mach_exception_thread, NULL); start_thread(mach_exception_thread, nullptr);
// Replace the exception port info for these exceptions with our own. // Replace the exception port info for these exceptions with our own.
// Note that we replace the exception port for the entire task, not only // Note that we replace the exception port for the entire task, not only

View File

@ -26,9 +26,9 @@ struct mark_bits {
~mark_bits() { ~mark_bits() {
delete[] marked; delete[] marked;
marked = NULL; marked = nullptr;
delete[] forwarding; delete[] forwarding;
forwarding = NULL; forwarding = nullptr;
} }
cell block_line(cell address) { cell block_line(cell address) {

View File

@ -1,13 +1,13 @@
#ifndef __FACTOR_MASTER_H__ #ifndef FACTOR_MASTER_H
#define __FACTOR_MASTER_H__ #define FACTOR_MASTER_H
#ifndef _THREAD_SAFE //#ifndef _THREAD_SAFE
#define _THREAD_SAFE //#define _THREAD_SAFE
#endif //#endif
#ifndef _REENTRANT //#ifndef _REENTRANT
#define _REENTRANT //#define _REENTRANT
#endif //#endif
#include <errno.h> #include <errno.h>
@ -139,4 +139,4 @@ namespace factor { struct factor_vm; }
#include "mvm.hpp" #include "mvm.hpp"
#include "factor.hpp" #include "factor.hpp"
#endif // __FACTOR_MASTER_H__ #endif // FACTOR_MASTER_H

View File

@ -40,18 +40,18 @@ inline double factor_vm::untag_float_check(cell tagged) {
} }
inline fixnum factor_vm::float_to_fixnum(cell tagged) { inline fixnum factor_vm::float_to_fixnum(cell tagged) {
return (fixnum)untag_float(tagged); return static_cast<fixnum>(untag_float(tagged));
} }
inline double factor_vm::fixnum_to_float(cell tagged) { inline double factor_vm::fixnum_to_float(cell tagged) {
return (double)untag_fixnum(tagged); return static_cast<double>(untag_fixnum(tagged));
} }
inline cell factor_vm::unbox_array_size() { inline cell factor_vm::unbox_array_size() {
cell obj = ctx->pop(); cell obj = ctx->pop();
fixnum n = to_fixnum_strict(obj); fixnum n = to_fixnum_strict(obj);
if (n >= 0 && n < (fixnum)array_size_max) { if (n >= 0 && n < static_cast<fixnum>(array_size_max)) {
return n; return static_cast<cell>(n);
} }
general_error(ERROR_ARRAY_SIZE, obj, tag_fixnum(array_size_max)); general_error(ERROR_ARRAY_SIZE, obj, tag_fixnum(array_size_max));
return 0; // can't happen return 0; // can't happen

View File

@ -4,7 +4,7 @@ namespace factor {
factor_vm* global_vm; factor_vm* global_vm;
void init_mvm() { global_vm = NULL; } void init_mvm() { global_vm = nullptr; }
void register_vm_with_thread(factor_vm* vm) { void register_vm_with_thread(factor_vm* vm) {
FACTOR_ASSERT(!global_vm); FACTOR_ASSERT(!global_vm);

View File

@ -5,7 +5,7 @@ namespace factor {
pthread_key_t current_vm_tls_key; pthread_key_t current_vm_tls_key;
void init_mvm() { void init_mvm() {
if (pthread_key_create(&current_vm_tls_key, NULL) != 0) if (pthread_key_create(&current_vm_tls_key, nullptr) != 0)
fatal_error("pthread_key_create() failed", 0); fatal_error("pthread_key_create() failed", 0);
} }

View File

@ -6,7 +6,7 @@ factor_vm* current_vm_p();
inline factor_vm* current_vm() { inline factor_vm* current_vm() {
factor_vm* vm = current_vm_p(); factor_vm* vm = current_vm_p();
FACTOR_ASSERT(vm != NULL); FACTOR_ASSERT(vm != nullptr);
return vm; return vm;
} }

View File

@ -23,6 +23,7 @@ THREADHANDLE start_thread(void* (*start_routine)(void*), void* args) {
static void* null_dll; static void* null_dll;
void sleep_nanos(uint64_t nsec) { void sleep_nanos(uint64_t nsec) {
timespec ts; timespec ts;
timespec ts_rem; timespec ts_rem;
@ -39,7 +40,7 @@ void sleep_nanos(uint64_t nsec) {
fatal_error("nanosleep failed", 0); fatal_error("nanosleep failed", 0);
} }
void factor_vm::init_ffi() { null_dll = dlopen(NULL, RTLD_LAZY); } void factor_vm::init_ffi() { null_dll = dlopen(nullptr, RTLD_LAZY); }
void factor_vm::ffi_dlopen(dll* dll) { void factor_vm::ffi_dlopen(dll* dll) {
dll->handle = dlopen(alien_offset(dll->path), RTLD_LAZY | RTLD_GLOBAL); dll->handle = dlopen(alien_offset(dll->path), RTLD_LAZY | RTLD_GLOBAL);
@ -56,7 +57,7 @@ cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
void factor_vm::ffi_dlclose(dll* dll) { void factor_vm::ffi_dlclose(dll* dll) {
if (dlclose(dll->handle)) if (dlclose(dll->handle))
general_error(ERROR_FFI, false_object, false_object); general_error(ERROR_FFI, false_object, false_object);
dll->handle = NULL; dll->handle = nullptr;
} }
void factor_vm::primitive_existsp() { void factor_vm::primitive_existsp() {
@ -86,7 +87,7 @@ segment::segment(cell size_, bool executable_p) {
prot = PROT_READ | PROT_WRITE; prot = PROT_READ | PROT_WRITE;
cell alloc_size = 2 * pagesize + size; cell alloc_size = 2 * pagesize + size;
char* array = (char*)mmap(NULL, alloc_size, prot, char* array = (char*)mmap(nullptr, alloc_size, prot,
MAP_ANON | MAP_PRIVATE, -1, 0); MAP_ANON | MAP_PRIVATE, -1, 0);
if (array == (char*)-1) if (array == (char*)-1)
@ -110,13 +111,13 @@ void factor_vm::start_sampling_profiler_timer() {
memset((void*)&timer, 0, sizeof(struct itimerval)); memset((void*)&timer, 0, sizeof(struct itimerval));
timer.it_value.tv_usec = 1000000 / samples_per_second; timer.it_value.tv_usec = 1000000 / samples_per_second;
timer.it_interval.tv_usec = 1000000 / samples_per_second; timer.it_interval.tv_usec = 1000000 / samples_per_second;
setitimer(ITIMER_REAL, &timer, NULL); setitimer(ITIMER_REAL, &timer, nullptr);
} }
void factor_vm::end_sampling_profiler_timer() { void factor_vm::end_sampling_profiler_timer() {
struct itimerval timer; struct itimerval timer;
memset((void*)&timer, 0, sizeof(struct itimerval)); memset((void*)&timer, 0, sizeof(struct itimerval));
setitimer(ITIMER_REAL, &timer, NULL); setitimer(ITIMER_REAL, &timer, nullptr);
} }
void factor_vm::dispatch_signal(void* uap, void(handler)()) { void factor_vm::dispatch_signal(void* uap, void(handler)()) {
@ -176,7 +177,7 @@ void fep_signal_handler(int signal, siginfo_t* siginfo, void* uap) {
void sample_signal_handler(int signal, siginfo_t* siginfo, void* uap) { void sample_signal_handler(int signal, siginfo_t* siginfo, void* uap) {
factor_vm* vm = current_vm_p(); factor_vm* vm = current_vm_p();
bool foreign_thread = false; bool foreign_thread = false;
if (vm == NULL) { if (vm == nullptr) {
foreign_thread = true; foreign_thread = true;
vm = thread_vms.begin()->second; vm = thread_vms.begin()->second;
} }
@ -255,43 +256,43 @@ void factor_vm::unix_init_signals() {
signal_callstack.ss_size = signal_callstack_seg->size; signal_callstack.ss_size = signal_callstack_seg->size;
signal_callstack.ss_flags = 0; signal_callstack.ss_flags = 0;
if (sigaltstack(&signal_callstack, (stack_t*)NULL) < 0) if (sigaltstack(&signal_callstack, nullptr) < 0)
fatal_error("sigaltstack() failed", 0); fatal_error("sigaltstack() failed", 0);
{ {
struct sigaction memory_sigaction; struct sigaction memory_sigaction;
init_sigaction_with_handler(&memory_sigaction, memory_signal_handler); init_sigaction_with_handler(&memory_sigaction, memory_signal_handler);
sigaction_safe(SIGBUS, &memory_sigaction, NULL); sigaction_safe(SIGBUS, &memory_sigaction, nullptr);
sigaction_safe(SIGSEGV, &memory_sigaction, NULL); sigaction_safe(SIGSEGV, &memory_sigaction, nullptr);
sigaction_safe(SIGTRAP, &memory_sigaction, NULL); sigaction_safe(SIGTRAP, &memory_sigaction, nullptr);
} }
{ {
struct sigaction fpe_sigaction; struct sigaction fpe_sigaction;
init_sigaction_with_handler(&fpe_sigaction, fpe_signal_handler); init_sigaction_with_handler(&fpe_sigaction, fpe_signal_handler);
sigaction_safe(SIGFPE, &fpe_sigaction, NULL); sigaction_safe(SIGFPE, &fpe_sigaction, nullptr);
} }
{ {
struct sigaction synchronous_sigaction; struct sigaction synchronous_sigaction;
init_sigaction_with_handler(&synchronous_sigaction, init_sigaction_with_handler(&synchronous_sigaction,
synchronous_signal_handler); synchronous_signal_handler);
sigaction_safe(SIGILL, &synchronous_sigaction, NULL); sigaction_safe(SIGILL, &synchronous_sigaction, nullptr);
sigaction_safe(SIGABRT, &synchronous_sigaction, NULL); sigaction_safe(SIGABRT, &synchronous_sigaction, nullptr);
} }
{ {
struct sigaction enqueue_sigaction; struct sigaction enqueue_sigaction;
init_sigaction_with_handler(&enqueue_sigaction, enqueue_signal_handler); init_sigaction_with_handler(&enqueue_sigaction, enqueue_signal_handler);
sigaction_safe(SIGWINCH, &enqueue_sigaction, NULL); sigaction_safe(SIGWINCH, &enqueue_sigaction, nullptr);
sigaction_safe(SIGUSR1, &enqueue_sigaction, NULL); sigaction_safe(SIGUSR1, &enqueue_sigaction, nullptr);
sigaction_safe(SIGCONT, &enqueue_sigaction, NULL); sigaction_safe(SIGCONT, &enqueue_sigaction, nullptr);
sigaction_safe(SIGURG, &enqueue_sigaction, NULL); sigaction_safe(SIGURG, &enqueue_sigaction, nullptr);
sigaction_safe(SIGIO, &enqueue_sigaction, NULL); sigaction_safe(SIGIO, &enqueue_sigaction, nullptr);
sigaction_safe(SIGPROF, &enqueue_sigaction, NULL); sigaction_safe(SIGPROF, &enqueue_sigaction, nullptr);
sigaction_safe(SIGVTALRM, &enqueue_sigaction, NULL); sigaction_safe(SIGVTALRM, &enqueue_sigaction, nullptr);
#ifdef SIGINFO #ifdef SIGINFO
sigaction_safe(SIGINFO, &enqueue_sigaction, NULL); sigaction_safe(SIGINFO, &enqueue_sigaction, nullptr);
#endif #endif
} }
@ -300,7 +301,7 @@ void factor_vm::unix_init_signals() {
{ {
struct sigaction sample_sigaction; struct sigaction sample_sigaction;
init_sigaction_with_handler(&sample_sigaction, sample_signal_handler); init_sigaction_with_handler(&sample_sigaction, sample_signal_handler);
sigaction_safe(SIGALRM, &sample_sigaction, NULL); sigaction_safe(SIGALRM, &sample_sigaction, nullptr);
} }
// We don't use SA_IGN here because then the ignore action is inherited // We don't use SA_IGN here because then the ignore action is inherited
@ -309,9 +310,9 @@ void factor_vm::unix_init_signals() {
{ {
struct sigaction ignore_sigaction; struct sigaction ignore_sigaction;
init_sigaction_with_handler(&ignore_sigaction, ignore_signal_handler); init_sigaction_with_handler(&ignore_sigaction, ignore_signal_handler);
sigaction_safe(SIGPIPE, &ignore_sigaction, NULL); sigaction_safe(SIGPIPE, &ignore_sigaction, nullptr);
// We send SIGUSR2 to the stdin_loop thread to interrupt it on FEP // We send SIGUSR2 to the stdin_loop thread to interrupt it on FEP
sigaction_safe(SIGUSR2, &ignore_sigaction, NULL); sigaction_safe(SIGUSR2, &ignore_sigaction, nullptr);
} }
} }
@ -359,7 +360,7 @@ void safe_write(int fd, void* data, ssize_t size) {
void safe_write_nonblock(int fd, void* data, ssize_t size) { void safe_write_nonblock(int fd, void* data, ssize_t size) {
if (!check_write(fd, data, size) && errno != EAGAIN) if (!check_write(fd, data, size) && errno != EAGAIN)
fatal_error("error writing fd", errno); fatal_error("error writing fd", static_cast<cell>(errno));
} }
bool safe_read(int fd, void* data, ssize_t size) { bool safe_read(int fd, void* data, ssize_t size) {
@ -376,6 +377,7 @@ bool safe_read(int fd, void* data, ssize_t size) {
} }
void* stdin_loop(void* arg) { void* stdin_loop(void* arg) {
(void) arg;
unsigned char buf[4096]; unsigned char buf[4096];
bool loop_running = true; bool loop_running = true;
@ -385,7 +387,7 @@ void* stdin_loop(void* arg) {
sigdelset(&mask, SIGTTIN); sigdelset(&mask, SIGTTIN);
sigdelset(&mask, SIGTERM); sigdelset(&mask, SIGTERM);
sigdelset(&mask, SIGQUIT); sigdelset(&mask, SIGQUIT);
pthread_sigmask(SIG_SETMASK, &mask, NULL); pthread_sigmask(SIG_SETMASK, &mask, nullptr);
int unused; int unused;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &unused); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &unused);
@ -424,7 +426,7 @@ void* stdin_loop(void* arg) {
safe_close(stdin_write); safe_close(stdin_write);
safe_close(control_read); safe_close(control_read);
return NULL; return nullptr;
} }
void open_console() { void open_console() {
@ -432,9 +434,9 @@ void open_console() {
safe_pipe(&control_read, &control_write); safe_pipe(&control_read, &control_write);
safe_pipe(&size_read, &size_write); safe_pipe(&size_read, &size_write);
safe_pipe(&stdin_read, &stdin_write); safe_pipe(&stdin_read, &stdin_write);
stdin_thread = start_thread(stdin_loop, NULL); stdin_thread = start_thread(stdin_loop, nullptr);
stdin_thread_initialized_p = true; stdin_thread_initialized_p = true;
pthread_mutex_init(&stdin_mutex, NULL); pthread_mutex_init(&stdin_mutex, nullptr);
} }
// This method is used to kill the stdin_loop before exiting from factor. // This method is used to kill the stdin_loop before exiting from factor.
@ -443,7 +445,7 @@ void open_console() {
void close_console() { void close_console() {
if (stdin_thread_initialized_p) { if (stdin_thread_initialized_p) {
pthread_cancel(stdin_thread); pthread_cancel(stdin_thread);
pthread_join(stdin_thread, 0); pthread_join(stdin_thread, nullptr);
} }
} }
@ -471,7 +473,7 @@ void ignore_ctrl_c() {
void handle_ctrl_c() { void handle_ctrl_c() {
struct sigaction fep_sigaction; struct sigaction fep_sigaction;
init_sigaction_with_handler(&fep_sigaction, fep_signal_handler); init_sigaction_with_handler(&fep_sigaction, fep_signal_handler);
sigaction_safe(SIGINT, &fep_sigaction, NULL); sigaction_safe(SIGINT, &fep_sigaction, nullptr);
} }
void factor_vm::primitive_disable_ctrl_break() { void factor_vm::primitive_disable_ctrl_break() {
@ -482,7 +484,7 @@ void factor_vm::primitive_enable_ctrl_break() {
stop_on_ctrl_break = true; stop_on_ctrl_break = true;
} }
void abort() { __attribute__((noreturn)) void abort() {
sig_t ret; sig_t ret;
do { do {
ret = signal(SIGABRT, SIG_DFL); ret = signal(SIGABRT, SIG_DFL);

View File

@ -50,8 +50,10 @@ inline static THREADHANDLE thread_id() { return pthread_self(); }
uint64_t nano_count(); uint64_t nano_count();
void sleep_nanos(uint64_t nsec); void sleep_nanos(uint64_t nsec);
void* stdin_loop(void* arg);
void check_ENOMEM(const char* msg); void check_ENOMEM(const char* msg);
static inline void breakpoint() { __builtin_trap(); } __attribute__((noreturn)) static inline void breakpoint() { __builtin_trap(); }
} }

View File

@ -12,13 +12,13 @@ bool set_memory_locked(cell base, cell size, bool locked) {
} }
void factor_vm::init_ffi() { void factor_vm::init_ffi() {
hFactorDll = GetModuleHandle(NULL); hFactorDll = GetModuleHandle(nullptr);
if (!hFactorDll) if (!hFactorDll)
fatal_error("GetModuleHandle() failed", 0); fatal_error("GetModuleHandle() failed", 0);
} }
void factor_vm::ffi_dlopen(dll* dll) { void factor_vm::ffi_dlopen(dll* dll) {
dll->handle = LoadLibraryEx((WCHAR*)alien_offset(dll->path), NULL, 0); dll->handle = LoadLibraryEx((WCHAR*)alien_offset(dll->path), nullptr, 0);
} }
cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) { cell factor_vm::ffi_dlsym(dll* dll, symbol_char* symbol) {
@ -32,13 +32,13 @@ cell factor_vm::ffi_dlsym_raw(dll* dll, symbol_char* symbol) {
void factor_vm::ffi_dlclose(dll* dll) { void factor_vm::ffi_dlclose(dll* dll) {
FreeLibrary((HMODULE) dll->handle); FreeLibrary((HMODULE) dll->handle);
dll->handle = NULL; dll->handle = nullptr;
} }
BOOL factor_vm::windows_stat(vm_char* path) { BOOL factor_vm::windows_stat(vm_char* path) {
BY_HANDLE_FILE_INFORMATION bhfi; BY_HANDLE_FILE_INFORMATION bhfi;
HANDLE h = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, HANDLE h = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
// FindFirstFile is the only call that can stat c:\pagefile.sys // FindFirstFile is the only call that can stat c:\pagefile.sys
@ -61,7 +61,7 @@ const vm_char* factor_vm::default_image_path() {
vm_char* ptr; vm_char* ptr;
vm_char temp_path[MAX_UNICODE_PATH]; vm_char temp_path[MAX_UNICODE_PATH];
if (!GetModuleFileName(NULL, full_path, MAX_UNICODE_PATH)) if (!GetModuleFileName(nullptr, full_path, MAX_UNICODE_PATH))
fatal_error("GetModuleFileName() failed", 0); fatal_error("GetModuleFileName() failed", 0);
if ((ptr = wcsrchr(full_path, '.'))) if ((ptr = wcsrchr(full_path, '.')))
@ -79,7 +79,7 @@ const vm_char* factor_vm::default_image_path() {
// You must free() this yourself. // You must free() this yourself.
const vm_char* factor_vm::vm_executable_path() { const vm_char* factor_vm::vm_executable_path() {
vm_char full_path[MAX_UNICODE_PATH]; vm_char full_path[MAX_UNICODE_PATH];
if (!GetModuleFileName(NULL, full_path, MAX_UNICODE_PATH)) if (!GetModuleFileName(nullptr, full_path, MAX_UNICODE_PATH))
fatal_error("GetModuleFileName() failed", 0); fatal_error("GetModuleFileName() failed", 0);
return safe_strdup(full_path); return safe_strdup(full_path);
} }
@ -95,7 +95,7 @@ segment::segment(cell size_, bool executable_p) {
char* mem; char* mem;
cell alloc_size = getpagesize() * 2 + size; cell alloc_size = getpagesize() * 2 + size;
if ((mem = (char*)VirtualAlloc( if ((mem = (char*)VirtualAlloc(
NULL, alloc_size, MEM_COMMIT, nullptr, alloc_size, MEM_COMMIT,
executable_p ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE)) == executable_p ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE)) ==
0) { 0) {
fatal_error("Out of memory in VirtualAlloc", alloc_size); fatal_error("Out of memory in VirtualAlloc", alloc_size);
@ -141,7 +141,7 @@ bool move_file(const vm_char* path1, const vm_char* path2) {
void factor_vm::init_signals() {} void factor_vm::init_signals() {}
THREADHANDLE start_thread(void* (*start_routine)(void*), void* args) { THREADHANDLE start_thread(void* (*start_routine)(void*), void* args) {
return (void*)CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) start_routine, return (void*)CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE) start_routine,
args, 0, 0); args, 0, 0);
} }
@ -254,7 +254,7 @@ static void wake_up_thread(HANDLE thread) {
// CancelSynchronousIo() didn't find anything to cancel, let's try // CancelSynchronousIo() didn't find anything to cancel, let's try
// with QueueUserAPC() instead. // with QueueUserAPC() instead.
if (err == ERROR_NOT_FOUND) { if (err == ERROR_NOT_FOUND) {
if (!QueueUserAPC(&dummy_cb, thread, NULL)) { if (!QueueUserAPC(&dummy_cb, thread, nullptr)) {
fatal_error("QueueUserAPC() failed", GetLastError()); fatal_error("QueueUserAPC() failed", GetLastError());
} }
} else { } else {
@ -307,7 +307,7 @@ static DWORD WINAPI ctrl_break_thread_proc(LPVOID parent_vm) {
} else if (!ctrl_break_handled) { } else if (!ctrl_break_handled) {
/* Check if the VM thread has the same Id as the thread Id of the /* Check if the VM thread has the same Id as the thread Id of the
currently active window. Note that thread Id is not a handle. */ currently active window. Note that thread Id is not a handle. */
DWORD fg_thd_id = GetWindowThreadProcessId(GetForegroundWindow(), NULL); DWORD fg_thd_id = GetWindowThreadProcessId(GetForegroundWindow(), nullptr);
if ((fg_thd_id == vm->thread_id) && !vm->fep_p) { if ((fg_thd_id == vm->thread_id) && !vm->fep_p) {
vm->enqueue_fep(); vm->enqueue_fep();
ctrl_break_handled = true; ctrl_break_handled = true;
@ -320,22 +320,22 @@ static DWORD WINAPI ctrl_break_thread_proc(LPVOID parent_vm) {
void factor_vm::primitive_disable_ctrl_break() { void factor_vm::primitive_disable_ctrl_break() {
stop_on_ctrl_break = false; stop_on_ctrl_break = false;
if (ctrl_break_thread != NULL) { if (ctrl_break_thread != nullptr) {
DWORD wait_result = WaitForSingleObject(ctrl_break_thread, DWORD wait_result = WaitForSingleObject(ctrl_break_thread,
2 * ctrl_break_sleep); 2 * ctrl_break_sleep);
if (wait_result != WAIT_OBJECT_0) if (wait_result != WAIT_OBJECT_0)
TerminateThread(ctrl_break_thread, 0); TerminateThread(ctrl_break_thread, 0);
CloseHandle(ctrl_break_thread); CloseHandle(ctrl_break_thread);
ctrl_break_thread = NULL; ctrl_break_thread = nullptr;
} }
} }
void factor_vm::primitive_enable_ctrl_break() { void factor_vm::primitive_enable_ctrl_break() {
stop_on_ctrl_break = true; stop_on_ctrl_break = true;
if (ctrl_break_thread == NULL) { if (ctrl_break_thread == nullptr) {
DisableProcessWindowsGhosting(); DisableProcessWindowsGhosting();
ctrl_break_thread = CreateThread(NULL, 0, factor::ctrl_break_thread_proc, ctrl_break_thread = CreateThread(nullptr, 0, factor::ctrl_break_thread_proc,
static_cast<LPVOID>(this), 0, NULL); static_cast<LPVOID>(this), 0, nullptr);
SetThreadPriority(ctrl_break_thread, THREAD_PRIORITY_ABOVE_NORMAL); SetThreadPriority(ctrl_break_thread, THREAD_PRIORITY_ABOVE_NORMAL);
} }
} }
@ -397,8 +397,8 @@ static DWORD WINAPI sampler_thread_entry(LPVOID parent_vm) {
} }
void factor_vm::start_sampling_profiler_timer() { void factor_vm::start_sampling_profiler_timer() {
sampler_thread = CreateThread(NULL, 0, &sampler_thread_entry, sampler_thread = CreateThread(nullptr, 0, &sampler_thread_entry,
static_cast<LPVOID>(this), 0, NULL); static_cast<LPVOID>(this), 0, nullptr);
} }
void factor_vm::end_sampling_profiler_timer() { void factor_vm::end_sampling_profiler_timer() {
@ -408,7 +408,7 @@ void factor_vm::end_sampling_profiler_timer() {
if (wait_result != WAIT_OBJECT_0) if (wait_result != WAIT_OBJECT_0)
TerminateThread(sampler_thread, 0); TerminateThread(sampler_thread, 0);
CloseHandle(sampler_thread); CloseHandle(sampler_thread);
sampler_thread = NULL; sampler_thread = nullptr;
} }
void abort() { ::abort(); } void abort() { ::abort(); }

View File

@ -79,7 +79,7 @@ inline static THREADHANDLE thread_id() {
HANDLE threadHandle = OpenThread( HANDLE threadHandle = OpenThread(
THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME, FALSE, THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME, FALSE,
id); id);
FACTOR_ASSERT(threadHandle != NULL); FACTOR_ASSERT(threadHandle != nullptr);
return threadHandle; return threadHandle;
} }

View File

@ -10,7 +10,6 @@ struct quotation_jit : public jit {
elements(false_object, vm), elements(false_object, vm),
compiling(compiling), compiling(compiling),
relocate(relocate) {} relocate(relocate) {}
;
cell nth(cell index); cell nth(cell index);
void init_quotation(cell quot); void init_quotation(cell quot);

View File

@ -374,7 +374,7 @@ template <typename Fixup>
void slot_visitor<Fixup>::visit_object_code_block(object* obj) { void slot_visitor<Fixup>::visit_object_code_block(object* obj) {
switch (obj->type()) { switch (obj->type()) {
case WORD_TYPE: { case WORD_TYPE: {
word* w = (word*)obj; word* w = static_cast<word*>(obj);
if (w->entry_point) if (w->entry_point)
w->entry_point = fixup.fixup_code(w->code())->entry_point(); w->entry_point = fixup.fixup_code(w->code())->entry_point();
break; break;

View File

@ -12,7 +12,7 @@ struct tenured_space : free_list_allocator<object> {
starts.record_object_start_offset(obj); starts.record_object_start_offset(obj);
return obj; return obj;
} }
return NULL; return nullptr;
} }
cell next_allocated_object_after(cell scan) { cell next_allocated_object_after(cell scan) {

View File

@ -6,8 +6,8 @@ namespace factor {
void* fill_function_descriptor(void* ptr, void* code) { void* fill_function_descriptor(void* ptr, void* code) {
void** descriptor = (void**)ptr; void** descriptor = (void**)ptr;
descriptor[0] = code; descriptor[0] = code;
descriptor[1] = NULL; descriptor[1] = nullptr;
descriptor[2] = NULL; descriptor[2] = nullptr;
return descriptor; return descriptor;
} }

View File

@ -3,33 +3,33 @@
namespace factor { namespace factor {
factor_vm::factor_vm(THREADHANDLE thread) factor_vm::factor_vm(THREADHANDLE thread)
: ctx(NULL), : ctx(nullptr),
nursery(0, 0), nursery(0, 0),
faulting_p(false), faulting_p(false),
thread(thread), thread(thread),
#if defined(WINDOWS) #if defined(WINDOWS)
thread_id(GetCurrentThreadId()), thread_id(GetCurrentThreadId()),
ctrl_break_thread(NULL), ctrl_break_thread(nullptr),
#endif #endif
callback_id(0), callback_id(0),
c_to_factor_func(NULL), c_to_factor_func(nullptr),
sampling_profiler_p(false), sampling_profiler_p(false),
signal_pipe_input(0), signal_pipe_input(0),
signal_pipe_output(0), signal_pipe_output(0),
current_sample(0, 0, 0, 0, 0), current_sample(0, 0, 0, 0, 0),
gc_off(false), gc_off(false),
data(NULL), code(NULL), callbacks(NULL), data(nullptr), code(nullptr), callbacks(nullptr),
current_gc(NULL), current_gc(nullptr),
current_gc_p(false), current_gc_p(false),
current_jit_count(0), current_jit_count(0),
gc_events(NULL), gc_events(nullptr),
fep_p(false), fep_p(false),
fep_help_was_shown(false), fep_help_was_shown(false),
fep_disabled(false), fep_disabled(false),
full_output(false), full_output(false),
object_counter(0), object_counter(0),
last_nano_count(0), last_nano_count(0),
signal_callstack_seg(NULL), signal_callstack_seg(nullptr),
safepoint_fep_p(false), safepoint_fep_p(false),
stop_on_ctrl_break(false) { stop_on_ctrl_break(false) {
primitive_reset_dispatch_stats(); primitive_reset_dispatch_stats();
@ -54,7 +54,7 @@ factor_vm::~factor_vm() {
delete code; delete code;
if (signal_callstack_seg) { if (signal_callstack_seg) {
delete signal_callstack_seg; delete signal_callstack_seg;
signal_callstack_seg = NULL; signal_callstack_seg = nullptr;
} }
FACTOR_FOR_EACH(function_descriptors) { FACTOR_FOR_EACH(function_descriptors) {
delete[] * iter; delete[] * iter;