Merge branch 'master' of git://factorcode.org/git/factor
commit
74d0ef4413
|
@ -10,6 +10,7 @@ Factor/factor
|
||||||
*.lib
|
*.lib
|
||||||
*.exp
|
*.exp
|
||||||
*.res
|
*.res
|
||||||
|
*.RES
|
||||||
*.image
|
*.image
|
||||||
*.dylib
|
*.dylib
|
||||||
factor
|
factor
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
USING: alien alien.syntax alien.c-types alien.parser
|
USING: alien alien.syntax alien.c-types alien.parser
|
||||||
eval kernel tools.test sequences system libc alien.strings
|
eval kernel tools.test sequences system libc alien.strings
|
||||||
io.encodings.utf8 math.constants classes.struct classes ;
|
io.encodings.utf8 math.constants classes.struct classes
|
||||||
|
accessors compiler.units ;
|
||||||
IN: alien.c-types.tests
|
IN: alien.c-types.tests
|
||||||
|
|
||||||
CONSTANT: xyz 123
|
CONSTANT: xyz 123
|
||||||
|
@ -100,3 +101,12 @@ DEFER: struct-redefined
|
||||||
\ struct-redefined class?
|
\ struct-redefined class?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[
|
||||||
|
"IN: alien.c-types.tests
|
||||||
|
USE: alien.syntax
|
||||||
|
USE: alien.c-types
|
||||||
|
TYPEDEF: int type-redefinition-test
|
||||||
|
TYPEDEF: int type-redefinition-test" eval( -- )
|
||||||
|
]
|
||||||
|
[ error>> error>> redefine-error? ]
|
||||||
|
must-fail-with
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
! Copyright (C) 2005, 2009 Slava Pestov, Alex Chapman.
|
! Copyright (C) 2005, 2010 Slava Pestov, Alex Chapman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays alien alien.c-types
|
USING: accessors arrays alien alien.c-types
|
||||||
alien.arrays alien.strings kernel math namespaces parser
|
alien.arrays alien.strings kernel math namespaces parser
|
||||||
|
@ -22,7 +22,7 @@ SYNTAX: CALLBACK:
|
||||||
(CALLBACK:) define-inline ;
|
(CALLBACK:) define-inline ;
|
||||||
|
|
||||||
SYNTAX: TYPEDEF:
|
SYNTAX: TYPEDEF:
|
||||||
scan-c-type CREATE-C-TYPE typedef ;
|
scan-c-type CREATE-C-TYPE dup save-location typedef ;
|
||||||
|
|
||||||
SYNTAX: C-ENUM:
|
SYNTAX: C-ENUM:
|
||||||
";" parse-tokens
|
";" parse-tokens
|
||||||
|
|
|
@ -56,15 +56,15 @@ big-endian off
|
||||||
|
|
||||||
[
|
[
|
||||||
! Load word
|
! Load word
|
||||||
temp0 0 MOV rc-absolute-cell rt-literal jit-rel
|
safe-reg 0 MOV rc-absolute-cell rt-literal jit-rel
|
||||||
! Bump profiling counter
|
! Bump profiling counter
|
||||||
temp0 profile-count-offset [+] 1 tag-fixnum ADD
|
safe-reg profile-count-offset [+] 1 tag-fixnum ADD
|
||||||
! Load word->code
|
! Load word->code
|
||||||
temp0 temp0 word-code-offset [+] MOV
|
safe-reg safe-reg word-code-offset [+] MOV
|
||||||
! Compute word entry point
|
! Compute word entry point
|
||||||
temp0 compiled-header-size ADD
|
safe-reg compiled-header-size ADD
|
||||||
! Jump to entry point
|
! Jump to entry point
|
||||||
temp0 JMP
|
safe-reg JMP
|
||||||
] jit-profiling jit-define
|
] jit-profiling jit-define
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
USING: accessors tools.profiler tools.test kernel memory math
|
USING: accessors tools.profiler tools.test kernel memory math
|
||||||
threads alien alien.c-types tools.profiler.private sequences
|
threads alien alien.c-types tools.profiler.private sequences
|
||||||
compiler.test compiler.units words ;
|
compiler.test compiler.units words arrays ;
|
||||||
IN: tools.profiler.tests
|
IN: tools.profiler.tests
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
|
@ -9,7 +9,7 @@ IN: tools.profiler.tests
|
||||||
\ length counter>> =
|
\ length counter>> =
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ ] [ [ 10 [ gc ] times ] profile ] unit-test
|
[ ] [ [ 3 [ gc ] times ] profile ] unit-test
|
||||||
|
|
||||||
[ ] [ [ 1000000 sleep ] profile ] unit-test
|
[ ] [ [ 1000000 sleep ] profile ] unit-test
|
||||||
|
|
||||||
|
@ -72,3 +72,8 @@ IN: tools.profiler.tests
|
||||||
] profile
|
] profile
|
||||||
counter>>
|
counter>>
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
! unwind_native_frames() would fail if profiling was enabled
|
||||||
|
! because the jit-profiling stub would clobber a parameter register
|
||||||
|
! on x86-64
|
||||||
|
[ [ -10 f <array> ] profile ] must-fail
|
||||||
|
|
|
@ -59,7 +59,7 @@ PRIVATE>
|
||||||
[ nip ] [ number>string ] if* ;
|
[ nip ] [ number>string ] if* ;
|
||||||
|
|
||||||
: group-id ( string -- id/f )
|
: group-id ( string -- id/f )
|
||||||
group-struct [ gr_gid>> ] [ f ] if* ;
|
group-struct dup [ gr_gid>> ] when ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ HELP: user-name
|
||||||
HELP: user-id
|
HELP: user-id
|
||||||
{ $values
|
{ $values
|
||||||
{ "string" string }
|
{ "string" string }
|
||||||
{ "id" integer } }
|
{ "id/f" "an integer or f" } }
|
||||||
{ $description "Returns the user id associated with the user-name." } ;
|
{ $description "Returns the user id associated with the user-name." } ;
|
||||||
|
|
||||||
HELP: with-effective-user
|
HELP: with-effective-user
|
||||||
|
|
|
@ -25,3 +25,5 @@ IN: unix.users.tests
|
||||||
[ "9999999999999999999" ] [ 9999999999999999999 user-name ] unit-test
|
[ "9999999999999999999" ] [ 9999999999999999999 user-name ] unit-test
|
||||||
|
|
||||||
[ f ] [ 89898989898989898989898989898 user-passwd ] unit-test
|
[ f ] [ 89898989898989898989898989898 user-passwd ] unit-test
|
||||||
|
|
||||||
|
[ f ] [ "thisusershouldnotexistabcdefg12345asdfasdfasdfasdfasdfasdfasdf" user-id ] unit-test
|
||||||
|
|
|
@ -61,8 +61,8 @@ M: string user-passwd ( string -- passwd/f )
|
||||||
dup user-passwd
|
dup user-passwd
|
||||||
[ nip user-name>> ] [ number>string ] if* ;
|
[ nip user-name>> ] [ number>string ] if* ;
|
||||||
|
|
||||||
: user-id ( string -- id )
|
: user-id ( string -- id/f )
|
||||||
user-passwd uid>> ;
|
user-passwd dup [ uid>> ] when ;
|
||||||
|
|
||||||
: real-user-id ( -- id )
|
: real-user-id ( -- id )
|
||||||
unix.ffi:getuid ; inline
|
unix.ffi:getuid ; inline
|
||||||
|
|
|
@ -72,7 +72,7 @@ STRUCT: DICONFIGUREDEVICESPARAMSW
|
||||||
{ dics DICOLORSET }
|
{ dics DICOLORSET }
|
||||||
{ lpUnkDDSTarget IUnknown* } ;
|
{ lpUnkDDSTarget IUnknown* } ;
|
||||||
TYPEDEF: DICONFIGUREDEVICESPARAMSW* LPDICONFIGUREDEVICESPARAMSW
|
TYPEDEF: DICONFIGUREDEVICESPARAMSW* LPDICONFIGUREDEVICESPARAMSW
|
||||||
TYPEDEF: DICONFIGUREDEVICESPARAMSW* LPDICONFIGUREDEVICESPARAMSW
|
TYPEDEF: DICONFIGUREDEVICESPARAMSW* LPCDICONFIGUREDEVICESPARAMSW
|
||||||
|
|
||||||
STRUCT: DIDEVCAPS
|
STRUCT: DIDEVCAPS
|
||||||
{ dwSize DWORD }
|
{ dwSize DWORD }
|
||||||
|
|
|
@ -36,12 +36,10 @@ TYPEDEF: int HFILE
|
||||||
|
|
||||||
TYPEDEF: long LONG
|
TYPEDEF: long LONG
|
||||||
TYPEDEF: long* LPLONG
|
TYPEDEF: long* LPLONG
|
||||||
TYPEDEF: long LONG_PTR
|
TYPEDEF: intptr_t LONG_PTR
|
||||||
TYPEDEF: long* PLONG_PTR
|
|
||||||
|
|
||||||
TYPEDEF: uint ULONG
|
TYPEDEF: uint ULONG
|
||||||
TYPEDEF: void* ULONG_PTR
|
TYPEDEF: uintptr_t ULONG_PTR
|
||||||
TYPEDEF: void* PULONG_PTR
|
|
||||||
|
|
||||||
TYPEDEF: void VOID
|
TYPEDEF: void VOID
|
||||||
TYPEDEF: void* PVOID
|
TYPEDEF: void* PVOID
|
||||||
|
@ -55,9 +53,6 @@ TYPEDEF: intptr_t UHALF_PTR
|
||||||
TYPEDEF: intptr_t INT_PTR
|
TYPEDEF: intptr_t INT_PTR
|
||||||
TYPEDEF: intptr_t UINT_PTR
|
TYPEDEF: intptr_t UINT_PTR
|
||||||
|
|
||||||
TYPEDEF: int LONG_PTR
|
|
||||||
TYPEDEF: ulong ULONG_PTR
|
|
||||||
|
|
||||||
TYPEDEF: int INT32
|
TYPEDEF: int INT32
|
||||||
TYPEDEF: uint UINT32
|
TYPEDEF: uint UINT32
|
||||||
TYPEDEF: uint DWORD32
|
TYPEDEF: uint DWORD32
|
||||||
|
@ -88,7 +83,6 @@ TYPEDEF: TCHAR TBYTE
|
||||||
|
|
||||||
TYPEDEF: WORD ATOM
|
TYPEDEF: WORD ATOM
|
||||||
TYPEDEF: BYTE BOOLEAN
|
TYPEDEF: BYTE BOOLEAN
|
||||||
TYPEDEF: DWORD COLORREF
|
|
||||||
TYPEDEF: ULONGLONG DWORDLONG
|
TYPEDEF: ULONGLONG DWORDLONG
|
||||||
TYPEDEF: ULONG_PTR DWORD_PTR
|
TYPEDEF: ULONG_PTR DWORD_PTR
|
||||||
TYPEDEF: PVOID HANDLE
|
TYPEDEF: PVOID HANDLE
|
||||||
|
@ -135,7 +129,6 @@ TYPEDEF: DWORD LGRPID
|
||||||
TYPEDEF: LONG_PTR LPARAM
|
TYPEDEF: LONG_PTR LPARAM
|
||||||
TYPEDEF: BOOL* LPBOOL
|
TYPEDEF: BOOL* LPBOOL
|
||||||
TYPEDEF: BYTE* LPBYTE
|
TYPEDEF: BYTE* LPBYTE
|
||||||
TYPEDEF: DWORD* LPCOLORREF
|
|
||||||
TYPEDEF: WCHAR* LPCWSTR
|
TYPEDEF: WCHAR* LPCWSTR
|
||||||
! TYPEDEF: WCHAR* LPWSTR
|
! TYPEDEF: WCHAR* LPWSTR
|
||||||
|
|
||||||
|
@ -199,8 +192,6 @@ TYPEDEF: WCHAR* PWSTR
|
||||||
TYPEDEF: HANDLE SC_HANDLE
|
TYPEDEF: HANDLE SC_HANDLE
|
||||||
TYPEDEF: LPVOID SC_LOCK
|
TYPEDEF: LPVOID SC_LOCK
|
||||||
TYPEDEF: HANDLE SERVICE_STATUS_HANDLE
|
TYPEDEF: HANDLE SERVICE_STATUS_HANDLE
|
||||||
TYPEDEF: ULONG_PTR SIZE_T
|
|
||||||
TYPEDEF: LONG_PTR SSIZE_T
|
|
||||||
TYPEDEF: LONGLONG USN
|
TYPEDEF: LONGLONG USN
|
||||||
TYPEDEF: UINT_PTR WPARAM
|
TYPEDEF: UINT_PTR WPARAM
|
||||||
|
|
||||||
|
@ -335,7 +326,6 @@ TYPEDEF: RECT* LPRECT
|
||||||
TYPEDEF: PIXELFORMATDESCRIPTOR PFD
|
TYPEDEF: PIXELFORMATDESCRIPTOR PFD
|
||||||
TYPEDEF: PFD* LPPFD
|
TYPEDEF: PFD* LPPFD
|
||||||
TYPEDEF: HANDLE HGLRC
|
TYPEDEF: HANDLE HGLRC
|
||||||
TYPEDEF: HANDLE HRGN
|
|
||||||
|
|
||||||
TYPEDEF: void* PWNDCLASS
|
TYPEDEF: void* PWNDCLASS
|
||||||
TYPEDEF: void* PWNDCLASSEX
|
TYPEDEF: void* PWNDCLASSEX
|
||||||
|
|
|
@ -301,7 +301,7 @@ bool factor_vm::save_image(const vm_char *saving_filename, const vm_char *filena
|
||||||
if(safe_fwrite(&h,sizeof(image_header),1,file) != 1) ok = false;
|
if(safe_fwrite(&h,sizeof(image_header),1,file) != 1) ok = false;
|
||||||
if(safe_fwrite((void*)data->tenured->start,h.data_size,1,file) != 1) ok = false;
|
if(safe_fwrite((void*)data->tenured->start,h.data_size,1,file) != 1) ok = false;
|
||||||
if(safe_fwrite(code->allocator->first_block(),h.code_size,1,file) != 1) ok = false;
|
if(safe_fwrite(code->allocator->first_block(),h.code_size,1,file) != 1) ok = false;
|
||||||
if(safe_fclose(file)) ok = false;
|
safe_fclose(file);
|
||||||
|
|
||||||
if(!ok)
|
if(!ok)
|
||||||
std::cout << "save-image failed: " << strerror(errno) << std::endl;
|
std::cout << "save-image failed: " << strerror(errno) << std::endl;
|
||||||
|
|
174
vm/io.cpp
174
vm/io.cpp
|
@ -31,7 +31,38 @@ void factor_vm::io_error()
|
||||||
general_error(ERROR_IO,tag_fixnum(errno),false_object,NULL);
|
general_error(ERROR_IO,tag_fixnum(errno),false_object,NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream)
|
FILE *factor_vm::safe_fopen(char *filename, char *mode)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
do {
|
||||||
|
file = fopen(filename,mode);
|
||||||
|
if(file == NULL)
|
||||||
|
io_error();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} while(errno == EINTR);
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
int factor_vm::safe_fgetc(FILE *stream)
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
do {
|
||||||
|
c = fgetc(stream);
|
||||||
|
if(c == EOF)
|
||||||
|
{
|
||||||
|
if(feof(stream))
|
||||||
|
return EOF;
|
||||||
|
else
|
||||||
|
io_error();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} while(errno == EINTR);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -42,7 +73,17 @@ size_t safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream)
|
||||||
return items_read;
|
return items_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream)
|
void factor_vm::safe_fputc(int c, FILE *stream)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
if(fputc(c,stream) == EOF)
|
||||||
|
io_error();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} while(errno == EINTR);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -53,15 +94,55 @@ size_t safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream)
|
||||||
return items_written;
|
return items_written;
|
||||||
}
|
}
|
||||||
|
|
||||||
int safe_fclose(FILE *stream)
|
int factor_vm::safe_ftell(FILE *stream)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
off_t offset;
|
||||||
|
do {
|
||||||
|
if((offset = FTELL(stream)) == -1)
|
||||||
|
io_error();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} while(errno == EINTR);
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void factor_vm::safe_fseek(FILE *stream, off_t offset, int whence)
|
||||||
|
{
|
||||||
|
switch(whence)
|
||||||
|
{
|
||||||
|
case 0: whence = SEEK_SET; break;
|
||||||
|
case 1: whence = SEEK_CUR; break;
|
||||||
|
case 2: whence = SEEK_END; break;
|
||||||
|
default:
|
||||||
|
critical_error("Bad value for whence",whence);
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = fclose(stream);
|
if(FSEEK(stream,offset,whence) == -1)
|
||||||
} while(ret != 0 && errno == EINTR);
|
io_error();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} while(errno == EINTR);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
void factor_vm::safe_fflush(FILE *stream)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
if(fflush(stream) == EOF)
|
||||||
|
io_error();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} while(errno == EINTR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void factor_vm::safe_fclose(FILE *stream)
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
if(fclose(stream) == EOF)
|
||||||
|
io_error();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
} while(errno == EINTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_fopen()
|
void factor_vm::primitive_fopen()
|
||||||
|
@ -72,13 +153,8 @@ void factor_vm::primitive_fopen()
|
||||||
path.untag_check(this);
|
path.untag_check(this);
|
||||||
|
|
||||||
FILE *file;
|
FILE *file;
|
||||||
do {
|
file = safe_fopen((char *)(path.untagged() + 1),
|
||||||
file = fopen((char *)(path.untagged() + 1),
|
(char *)(mode.untagged() + 1));
|
||||||
(char *)(mode.untagged() + 1));
|
|
||||||
if(file == NULL)
|
|
||||||
io_error();
|
|
||||||
} while(errno == EINTR);
|
|
||||||
|
|
||||||
ctx->push(allot_alien(file));
|
ctx->push(allot_alien(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,24 +167,11 @@ void factor_vm::primitive_fgetc()
|
||||||
{
|
{
|
||||||
FILE *file = pop_file_handle();
|
FILE *file = pop_file_handle();
|
||||||
|
|
||||||
do {
|
int c = safe_fgetc(file);
|
||||||
int c = fgetc(file);
|
if(c == EOF && feof(file))
|
||||||
if(c == EOF)
|
ctx->push(false_object);
|
||||||
{
|
else
|
||||||
if(feof(file))
|
ctx->push(tag_fixnum(c));
|
||||||
{
|
|
||||||
ctx->push(false_object);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
io_error();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ctx->push(tag_fixnum(c));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while(errno == EINTR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_fread()
|
void factor_vm::primitive_fread()
|
||||||
|
@ -156,13 +219,7 @@ void factor_vm::primitive_fputc()
|
||||||
{
|
{
|
||||||
FILE *file = pop_file_handle();
|
FILE *file = pop_file_handle();
|
||||||
fixnum ch = to_fixnum(ctx->pop());
|
fixnum ch = to_fixnum(ctx->pop());
|
||||||
|
safe_fputc(ch, file);
|
||||||
do {
|
|
||||||
if(fputc(ch,file) == EOF)
|
|
||||||
io_error();
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
} while(errno == EINTR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_fwrite()
|
void factor_vm::primitive_fwrite()
|
||||||
|
@ -183,16 +240,7 @@ void factor_vm::primitive_fwrite()
|
||||||
void factor_vm::primitive_ftell()
|
void factor_vm::primitive_ftell()
|
||||||
{
|
{
|
||||||
FILE *file = pop_file_handle();
|
FILE *file = pop_file_handle();
|
||||||
off_t offset;
|
ctx->push(from_signed_8(safe_ftell(file)));
|
||||||
|
|
||||||
do {
|
|
||||||
if((offset = FTELL(file)) == -1)
|
|
||||||
io_error();
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
} while(errno == EINTR);
|
|
||||||
|
|
||||||
ctx->push(from_signed_8(offset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_fseek()
|
void factor_vm::primitive_fseek()
|
||||||
|
@ -200,41 +248,19 @@ void factor_vm::primitive_fseek()
|
||||||
int whence = to_fixnum(ctx->pop());
|
int whence = to_fixnum(ctx->pop());
|
||||||
FILE *file = pop_file_handle();
|
FILE *file = pop_file_handle();
|
||||||
off_t offset = to_signed_8(ctx->pop());
|
off_t offset = to_signed_8(ctx->pop());
|
||||||
|
safe_fseek(file,offset,whence);
|
||||||
switch(whence)
|
|
||||||
{
|
|
||||||
case 0: whence = SEEK_SET; break;
|
|
||||||
case 1: whence = SEEK_CUR; break;
|
|
||||||
case 2: whence = SEEK_END; break;
|
|
||||||
default:
|
|
||||||
critical_error("Bad value for whence",whence);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
if(FSEEK(file,offset,whence) == -1)
|
|
||||||
io_error();
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
} while(errno == EINTR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_fflush()
|
void factor_vm::primitive_fflush()
|
||||||
{
|
{
|
||||||
FILE *file = pop_file_handle();
|
FILE *file = pop_file_handle();
|
||||||
do {
|
safe_fflush(file);
|
||||||
if(fflush(file) == EOF)
|
|
||||||
io_error();
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
} while(errno == EINTR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void factor_vm::primitive_fclose()
|
void factor_vm::primitive_fclose()
|
||||||
{
|
{
|
||||||
FILE *file = pop_file_handle();
|
FILE *file = pop_file_handle();
|
||||||
if(safe_fclose(file) == EOF)
|
safe_fclose(file);
|
||||||
io_error();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is used by FFI I/O. Accessing the errno global directly is
|
/* This function is used by FFI I/O. Accessing the errno global directly is
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
namespace factor
|
namespace factor
|
||||||
{
|
{
|
||||||
|
|
||||||
size_t safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream);
|
|
||||||
size_t safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream);
|
|
||||||
int safe_fclose(FILE *stream);
|
|
||||||
|
|
||||||
/* Platform specific primitives */
|
/* Platform specific primitives */
|
||||||
|
|
||||||
VM_C_API int err_no();
|
VM_C_API int err_no();
|
||||||
|
|
|
@ -492,6 +492,15 @@ struct factor_vm
|
||||||
//io
|
//io
|
||||||
void init_c_io();
|
void init_c_io();
|
||||||
void io_error();
|
void io_error();
|
||||||
|
FILE* safe_fopen(char *filename, char *mode);
|
||||||
|
int safe_fgetc(FILE *stream);
|
||||||
|
size_t safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream);
|
||||||
|
void safe_fputc(int c, FILE* stream);
|
||||||
|
size_t safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream);
|
||||||
|
int safe_ftell(FILE *stream);
|
||||||
|
void safe_fseek(FILE *stream, off_t offset, int whence);
|
||||||
|
void safe_fflush(FILE *stream);
|
||||||
|
void safe_fclose(FILE *stream);
|
||||||
void primitive_fopen();
|
void primitive_fopen();
|
||||||
FILE *pop_file_handle();
|
FILE *pop_file_handle();
|
||||||
void primitive_fgetc();
|
void primitive_fgetc();
|
||||||
|
|
Loading…
Reference in New Issue