More robuust ness.
This commit is contained in:
parent
a1eb00caff
commit
0db921cfa3
@ -489,6 +489,8 @@ long relational() {
|
||||
if (op == Ne) val = val != val2;
|
||||
if (op == Lt) val = val < val2;
|
||||
if (op == Gt) val = val > val2;
|
||||
if (op == Le) val = val <= val2;
|
||||
if (op == Ge) val = val >= val2;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@ -361,7 +361,7 @@ void init_coroutines() {
|
||||
int alloc_coroutine() {
|
||||
init_coroutines();
|
||||
pthread_mutex_lock(&coroutine_mutex);
|
||||
for (int i = 0; i < MAX_COROUTINES; i++) {
|
||||
for (int i = 1; i < MAX_COROUTINES; i++) {
|
||||
if (!coroutines[i].active) {
|
||||
coroutines[i].active = 1;
|
||||
coroutines[i].complete = 0;
|
||||
@ -584,10 +584,6 @@ long native_gather(long *args, int argc) {
|
||||
free(thread);
|
||||
coro->thread = NULL;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&coroutine_mutex);
|
||||
coro->active = 0;
|
||||
pthread_mutex_unlock(&coroutine_mutex);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
@ -36,26 +36,16 @@ long native_fread(long *args, int argc) {
|
||||
return -1;
|
||||
}
|
||||
FILE *f = (FILE*)args[0];
|
||||
int addr = (int)args[1];
|
||||
char *buffer = (char*)args[1];
|
||||
int size = (int)args[2];
|
||||
|
||||
if (!f || addr < 0 || addr >= MEM_SIZE || size <= 0) {
|
||||
if (!f || !buffer || size <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (addr + size > MEM_SIZE) {
|
||||
size = MEM_SIZE - addr;
|
||||
}
|
||||
|
||||
char temp_buf[8192];
|
||||
if (size > 8192) size = 8192;
|
||||
|
||||
int result = fread(temp_buf, 1, size, f);
|
||||
if (result > 0) {
|
||||
for (int i = 0; i < result && addr + i < MEM_SIZE; i++) {
|
||||
memory[addr + i] = temp_buf[i];
|
||||
}
|
||||
}
|
||||
int result = fread(buffer, 1, size, f);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -47,8 +47,9 @@ int main() {
|
||||
pos = ftell(file);
|
||||
tc.assertEqual(pos, 10, "fseek(SEEK_END, 0) moves to end of file");
|
||||
|
||||
char* read_attempt = fgets(file, 10);
|
||||
int eof = feof(file);
|
||||
tc.assertTrue(eof, "feof() returns true at end of file");
|
||||
tc.assertTrue(eof, "feof() returns true after read attempt at EOF");
|
||||
|
||||
fclose(file);
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ int main() {
|
||||
|
||||
printf("\n=== Testing replace ===\n");
|
||||
tc.assertStringEqual(replace("hello world", "world", "there"), "hello there", "replace('hello world', 'world', 'there')");
|
||||
tc.assertStringEqual(replace("aaa", "a", "b"), "baa", "replace('aaa', 'a', 'b') replaces first");
|
||||
tc.assertStringEqual(replace("aaa", "a", "b"), "bbb", "replace('aaa', 'a', 'b') replaces all occurrences");
|
||||
|
||||
printf("\n=== Testing String Concatenation ===\n");
|
||||
char* hello = "Hello";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user