Merge branch 'master' of git://factorcode.org/git/factor
commit
b55cddf969
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2008 Slava Pestov
|
! Copyright (C) 2008, 2010 Slava Pestov
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien alien.c-types alien.syntax kernel math
|
USING: accessors alien alien.c-types alien.syntax kernel math
|
||||||
namespaces sequences destructors combinators threads heaps
|
namespaces sequences destructors combinators threads heaps
|
||||||
|
@ -92,7 +92,10 @@ TUPLE: run-loop fds sources timers ;
|
||||||
] bi ;
|
] bi ;
|
||||||
|
|
||||||
: invalidate-run-loop-timers ( -- )
|
: invalidate-run-loop-timers ( -- )
|
||||||
run-loop [ [ [ CFRunLoopTimerInvalidate ] [ CFRelease ] bi ] each V{ } ] change-timers drop ;
|
run-loop [
|
||||||
|
[ [ CFRunLoopTimerInvalidate ] [ CFRelease ] bi ] each
|
||||||
|
V{ } clone
|
||||||
|
] change-timers drop ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types alien.syntax combinators
|
USING: accessors alien alien.c-types alien.syntax combinators
|
||||||
io.backend io.files io.files.info io.files.unix kernel math system unix
|
io.backend io.files io.files.info io.files.unix kernel math system unix
|
||||||
unix.statfs.freebsd unix.statvfs.freebsd unix.getfsstat.freebsd
|
unix.statfs.freebsd unix.statvfs.freebsd unix.getfsstat.freebsd
|
||||||
sequences grouping alien.strings io.encodings.utf8 unix.types
|
sequences grouping alien.strings io.encodings.utf8 unix.types
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.syntax kernel unix.stat math unix
|
USING: alien alien.syntax kernel unix.stat math unix
|
||||||
combinators system io.backend accessors alien.c-types
|
combinators system io.backend accessors alien.c-types
|
||||||
io.encodings.utf8 alien.strings unix.types io.files.unix
|
io.encodings.utf8 alien.strings unix.types io.files.unix
|
||||||
io.files io.files.info unix.statvfs.netbsd unix.getfsstat.netbsd arrays
|
io.files io.files.info unix.statvfs.netbsd unix.getfsstat.netbsd arrays
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008 Doug Coleman.
|
! Copyright (C) 2008 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types alien.strings alien.syntax
|
USING: accessors alien alien.c-types alien.strings alien.syntax
|
||||||
combinators io.backend io.files io.files.info io.files.unix kernel math
|
combinators io.backend io.files io.files.info io.files.unix kernel math
|
||||||
sequences system unix unix.getfsstat.openbsd grouping
|
sequences system unix unix.getfsstat.openbsd grouping
|
||||||
unix.statfs.openbsd unix.statvfs.openbsd unix.types
|
unix.statfs.openbsd unix.statvfs.openbsd unix.types
|
||||||
|
|
66
vm/io.cpp
66
vm/io.cpp
|
@ -34,20 +34,22 @@ void factor_vm::io_error()
|
||||||
FILE *factor_vm::safe_fopen(char *filename, char *mode)
|
FILE *factor_vm::safe_fopen(char *filename, char *mode)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
do {
|
for(;;)
|
||||||
|
{
|
||||||
file = fopen(filename,mode);
|
file = fopen(filename,mode);
|
||||||
if(file == NULL)
|
if(file == NULL)
|
||||||
io_error();
|
io_error();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while(errno == EINTR);
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
int factor_vm::safe_fgetc(FILE *stream)
|
int factor_vm::safe_fgetc(FILE *stream)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
do {
|
for(;;)
|
||||||
|
{
|
||||||
c = fgetc(stream);
|
c = fgetc(stream);
|
||||||
if(c == EOF)
|
if(c == EOF)
|
||||||
{
|
{
|
||||||
|
@ -58,38 +60,53 @@ int factor_vm::safe_fgetc(FILE *stream)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while(errno == EINTR);
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t factor_vm::safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream)
|
size_t factor_vm::safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream)
|
||||||
{
|
{
|
||||||
size_t items_read = 0;
|
size_t items_read = 0;
|
||||||
|
size_t ret = 0;
|
||||||
|
|
||||||
do {
|
do
|
||||||
items_read += fread((void*)((int*)ptr+items_read*size),size,nitems-items_read,stream);
|
{
|
||||||
} while(items_read != nitems && errno == EINTR);
|
ret = fread((void*)((int*)ptr+items_read*size),size,nitems-items_read,stream);
|
||||||
|
if(ret == 0)
|
||||||
|
{
|
||||||
|
if(feof(stream))
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
io_error();
|
||||||
|
}
|
||||||
|
items_read += ret;
|
||||||
|
} while(items_read != nitems);
|
||||||
|
|
||||||
return items_read;
|
return items_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::safe_fputc(int c, FILE *stream)
|
void factor_vm::safe_fputc(int c, FILE *stream)
|
||||||
{
|
{
|
||||||
do {
|
for(;;)
|
||||||
|
{
|
||||||
if(fputc(c,stream) == EOF)
|
if(fputc(c,stream) == EOF)
|
||||||
io_error();
|
io_error();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while(errno == EINTR);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t factor_vm::safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream)
|
size_t factor_vm::safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream)
|
||||||
{
|
{
|
||||||
size_t items_written = 0;
|
size_t items_written = 0;
|
||||||
|
size_t ret = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
items_written += fwrite((void*)((int*)ptr+items_written*size),size,nitems-items_written,stream);
|
ret = fwrite((void*)((int*)ptr+items_written*size),size,nitems-items_written,stream);
|
||||||
} while(items_written != nitems && errno == EINTR);
|
if(ret == 0)
|
||||||
|
io_error();
|
||||||
|
items_written += ret;
|
||||||
|
} while(items_written != nitems);
|
||||||
|
|
||||||
return items_written;
|
return items_written;
|
||||||
}
|
}
|
||||||
|
@ -97,12 +114,13 @@ size_t factor_vm::safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *strea
|
||||||
int factor_vm::safe_ftell(FILE *stream)
|
int factor_vm::safe_ftell(FILE *stream)
|
||||||
{
|
{
|
||||||
off_t offset;
|
off_t offset;
|
||||||
do {
|
for(;;)
|
||||||
|
{
|
||||||
if((offset = FTELL(stream)) == -1)
|
if((offset = FTELL(stream)) == -1)
|
||||||
io_error();
|
io_error();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while(errno == EINTR);
|
}
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,32 +135,35 @@ void factor_vm::safe_fseek(FILE *stream, off_t offset, int whence)
|
||||||
critical_error("Bad value for whence",whence);
|
critical_error("Bad value for whence",whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
for(;;)
|
||||||
|
{
|
||||||
if(FSEEK(stream,offset,whence) == -1)
|
if(FSEEK(stream,offset,whence) == -1)
|
||||||
io_error();
|
io_error();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while(errno == EINTR);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::safe_fflush(FILE *stream)
|
void factor_vm::safe_fflush(FILE *stream)
|
||||||
{
|
{
|
||||||
do {
|
for(;;)
|
||||||
|
{
|
||||||
if(fflush(stream) == EOF)
|
if(fflush(stream) == EOF)
|
||||||
io_error();
|
io_error();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while(errno == EINTR);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::safe_fclose(FILE *stream)
|
void factor_vm::safe_fclose(FILE *stream)
|
||||||
{
|
{
|
||||||
do {
|
for(;;)
|
||||||
|
{
|
||||||
if(fclose(stream) == EOF)
|
if(fclose(stream) == EOF)
|
||||||
io_error();
|
io_error();
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
} while(errno == EINTR);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_fopen()
|
void factor_vm::primitive_fopen()
|
||||||
|
@ -189,12 +210,7 @@ void factor_vm::primitive_fread()
|
||||||
|
|
||||||
int c = safe_fread(buf.untagged() + 1,1,size,file);
|
int c = safe_fread(buf.untagged() + 1,1,size,file);
|
||||||
if(c == 0)
|
if(c == 0)
|
||||||
{
|
ctx->push(false_object);
|
||||||
if(feof(file))
|
|
||||||
ctx->push(false_object);
|
|
||||||
else
|
|
||||||
io_error();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(feof(file))
|
if(feof(file))
|
||||||
|
|
Loading…
Reference in New Issue