]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <arcata@gmail.com>
Sat, 6 Feb 2010 04:13:45 +0000 (20:13 -0800)
committerJoe Groff <arcata@gmail.com>
Sat, 6 Feb 2010 04:13:45 +0000 (20:13 -0800)
15 files changed:
.gitignore
basis/alien/c-types/c-types-tests.factor
basis/alien/syntax/syntax.factor
basis/cpu/x86/bootstrap.factor
basis/tools/profiler/profiler-tests.factor
basis/unix/groups/groups.factor
basis/unix/users/users-docs.factor
basis/unix/users/users-tests.factor
basis/unix/users/users.factor
basis/windows/directx/dinput/dinput.factor
basis/windows/types/types.factor
vm/image.cpp
vm/io.cpp
vm/io.hpp
vm/vm.hpp

index ef3acdb280ccd3697a59da41ab267f6c8ae907d1..3bc5a6ffdafb1a4f6338b8a7035ddb0ce31023b1 100644 (file)
@@ -10,6 +10,7 @@ Factor/factor
 *.lib
 *.exp
 *.res
+*.RES
 *.image
 *.dylib
 factor
index d134d571896c9f79c8c068320fafb61db890daaa..faee8955e934e20149b933d74d9dd5299e457437 100644 (file)
@@ -1,6 +1,7 @@
 USING: alien alien.syntax alien.c-types alien.parser
 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
 
 CONSTANT: xyz 123
@@ -100,3 +101,12 @@ DEFER: struct-redefined
     \ struct-redefined class?
 ] 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
index 609ed2826d9d526c2ee40487e18442b82b9feb94..295bcff089393c68f80dad36dd4102344164f3bb 100644 (file)
@@ -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.
 USING: accessors arrays alien alien.c-types
 alien.arrays alien.strings kernel math namespaces parser
@@ -22,7 +22,7 @@ SYNTAX: CALLBACK:
     (CALLBACK:) define-inline ;
 
 SYNTAX: TYPEDEF:
-    scan-c-type CREATE-C-TYPE typedef ;
+    scan-c-type CREATE-C-TYPE dup save-location typedef ;
 
 SYNTAX: C-ENUM:
     ";" parse-tokens
index 19ac0189a3c49588a6fb6a15476710f882dde9b6..8f1a4d7f498ebfbc25fd2508bb6a8b2e7f02f8db 100644 (file)
@@ -56,15 +56,15 @@ big-endian off
 
 [
     ! 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
-    temp0 profile-count-offset [+] 1 tag-fixnum ADD
+    safe-reg profile-count-offset [+] 1 tag-fixnum ADD
     ! Load word->code
-    temp0 temp0 word-code-offset [+] MOV
+    safe-reg safe-reg word-code-offset [+] MOV
     ! Compute word entry point
-    temp0 compiled-header-size ADD
+    safe-reg compiled-header-size ADD
     ! Jump to entry point
-    temp0 JMP
+    safe-reg JMP
 ] jit-profiling jit-define
 
 [
index a85d93450644147577b8242be85d41cc729e54a3..5c31cdaeb481b664ca6359db8db32939178e0bba 100644 (file)
@@ -1,6 +1,6 @@
 USING: accessors tools.profiler tools.test kernel memory math
 threads alien alien.c-types tools.profiler.private sequences
-compiler.test compiler.units words ;
+compiler.test compiler.units words arrays ;
 IN: tools.profiler.tests
 
 [ t ] [
@@ -9,7 +9,7 @@ IN: tools.profiler.tests
     \ length counter>> =
 ] unit-test
 
-[ ] [ [ 10 [ gc ] times ] profile ] unit-test
+[ ] [ [ 3 [ gc ] times ] profile ] unit-test
 
 [ ] [ [ 1000000 sleep ] profile ] unit-test 
 
@@ -72,3 +72,8 @@ IN: tools.profiler.tests
     ] profile
     counter>>
 ] 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
index c34affb9c33344c0dc0025faa85982498491a9ab..b009fe529fca0e4d1fd459da38fa54ac20a09c2c 100644 (file)
@@ -59,7 +59,7 @@ PRIVATE>
     [ nip ] [ number>string ] if* ;
 
 : group-id ( string -- id/f )
-    group-struct [ gr_gid>> ] [ f ] if* ;
+    group-struct dup [ gr_gid>> ] when ;
 
 <PRIVATE
 
index c7867db2bf2ac565ad0852fb77f030861374ae6f..e676f6fef646ff840c91023a93ba302750e3e14f 100644 (file)
@@ -62,7 +62,7 @@ HELP: user-name
 HELP: user-id
 { $values
      { "string" string }
-     { "id" integer } }
+     { "id/f" "an integer or f" } }
 { $description "Returns the user id associated with the user-name." } ;
 
 HELP: with-effective-user
index cf3747b346a65600641bd1de8173a0f4f5256df5..f2059a1a8c51c7bb74b03abcb258b3d478b65169 100644 (file)
@@ -25,3 +25,5 @@ IN: unix.users.tests
 [ "9999999999999999999" ] [ 9999999999999999999 user-name ] unit-test
 
 [ f ] [ 89898989898989898989898989898 user-passwd ] unit-test
+
+[ f ] [ "thisusershouldnotexistabcdefg12345asdfasdfasdfasdfasdfasdfasdf" user-id ] unit-test
index adf7f5ce4f320f63911dd72ca5f8d4a718ab6fb2..5de176e2424cab7cad635cc40dec93470234a638 100644 (file)
@@ -61,8 +61,8 @@ M: string user-passwd ( string -- passwd/f )
     dup user-passwd
     [ nip user-name>> ] [ number>string ] if* ;
 
-: user-id ( string -- id )
-    user-passwd uid>> ;
+: user-id ( string -- id/f )
+    user-passwd dup [ uid>> ] when ;
 
 : real-user-id ( -- id )
     unix.ffi:getuid ; inline
index 2a7ae19eccf017aab2816cf41894d3f261f6f849..56cd4937ceb4bda6516ed077b15b73e8a30fb2cd 100644 (file)
@@ -72,7 +72,7 @@ STRUCT: DICONFIGUREDEVICESPARAMSW
     { dics           DICOLORSET        }
     { lpUnkDDSTarget IUnknown*         } ;
 TYPEDEF: DICONFIGUREDEVICESPARAMSW* LPDICONFIGUREDEVICESPARAMSW
-TYPEDEF: DICONFIGUREDEVICESPARAMSW* LPDICONFIGUREDEVICESPARAMSW
+TYPEDEF: DICONFIGUREDEVICESPARAMSW* LPCDICONFIGUREDEVICESPARAMSW
 
 STRUCT: DIDEVCAPS
     { dwSize DWORD }
index ea5daba68889d7e7dda02a0ff8dda211781456dd..9e322d9cde2bc2f89e6bb54541b9c284c0b48d8e 100644 (file)
@@ -36,12 +36,10 @@ TYPEDEF: int                 HFILE
 
 TYPEDEF: long                LONG
 TYPEDEF: long*               LPLONG
-TYPEDEF: long                LONG_PTR
-TYPEDEF: long*               PLONG_PTR
+TYPEDEF: intptr_t            LONG_PTR
 
 TYPEDEF: uint                ULONG
-TYPEDEF: void*               ULONG_PTR
-TYPEDEF: void*               PULONG_PTR
+TYPEDEF: uintptr_t           ULONG_PTR
 
 TYPEDEF: void                VOID
 TYPEDEF: void*               PVOID
@@ -55,9 +53,6 @@ TYPEDEF: intptr_t    UHALF_PTR
 TYPEDEF: intptr_t    INT_PTR
 TYPEDEF: intptr_t    UINT_PTR
 
-TYPEDEF: int         LONG_PTR
-TYPEDEF: ulong       ULONG_PTR
-
 TYPEDEF: int         INT32
 TYPEDEF: uint        UINT32
 TYPEDEF: uint        DWORD32
@@ -88,7 +83,6 @@ TYPEDEF: TCHAR       TBYTE
 
 TYPEDEF: WORD                ATOM
 TYPEDEF: BYTE                BOOLEAN
-TYPEDEF: DWORD               COLORREF
 TYPEDEF: ULONGLONG           DWORDLONG
 TYPEDEF: ULONG_PTR           DWORD_PTR
 TYPEDEF: PVOID               HANDLE
@@ -135,7 +129,6 @@ TYPEDEF: DWORD               LGRPID
 TYPEDEF: LONG_PTR            LPARAM
 TYPEDEF: BOOL*               LPBOOL
 TYPEDEF: BYTE*               LPBYTE
-TYPEDEF: DWORD*              LPCOLORREF
 TYPEDEF: WCHAR*              LPCWSTR
 ! TYPEDEF: WCHAR*              LPWSTR
 
@@ -199,8 +192,6 @@ TYPEDEF: WCHAR*              PWSTR
 TYPEDEF: HANDLE              SC_HANDLE
 TYPEDEF: LPVOID              SC_LOCK
 TYPEDEF: HANDLE              SERVICE_STATUS_HANDLE
-TYPEDEF: ULONG_PTR           SIZE_T
-TYPEDEF: LONG_PTR            SSIZE_T
 TYPEDEF: LONGLONG            USN
 TYPEDEF: UINT_PTR            WPARAM
 
@@ -335,7 +326,6 @@ TYPEDEF: RECT* LPRECT
 TYPEDEF: PIXELFORMATDESCRIPTOR PFD
 TYPEDEF: PFD* LPPFD
 TYPEDEF: HANDLE HGLRC
-TYPEDEF: HANDLE HRGN
 
 TYPEDEF: void* PWNDCLASS
 TYPEDEF: void* PWNDCLASSEX
index ad21270378ac24735b48e4150ad7c26dc04113a6..c74351c1911301846969058ea466505df2433ff3 100755 (executable)
@@ -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((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_fclose(file)) ok = false;
+       safe_fclose(file);
 
        if(!ok)
                std::cout << "save-image failed: " << strerror(errno) << std::endl;
index 880675b212be78798a7e497f590275cd8ea37b09..ae27b5a3d86298585095c40a07e06b3f8b838f72 100755 (executable)
--- a/vm/io.cpp
+++ b/vm/io.cpp
@@ -31,7 +31,38 @@ void factor_vm::io_error()
        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;
 
@@ -42,7 +73,17 @@ size_t safe_fread(void *ptr, size_t size, size_t nitems, FILE *stream)
        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;
 
@@ -53,15 +94,55 @@ size_t safe_fwrite(void *ptr, size_t size, size_t nitems, FILE *stream)
        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 {
-               ret = fclose(stream);
-       } while(ret != 0 && errno == EINTR);
+               if(FSEEK(stream,offset,whence) == -1)
+                       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()
@@ -72,13 +153,8 @@ void factor_vm::primitive_fopen()
        path.untag_check(this);
 
        FILE *file;
-       do {
-               file = fopen((char *)(path.untagged() + 1),
-                                  (char *)(mode.untagged() + 1));
-               if(file == NULL)
-                       io_error();
-       } while(errno == EINTR);
-
+       file = safe_fopen((char *)(path.untagged() + 1),
+                                               (char *)(mode.untagged() + 1));
        ctx->push(allot_alien(file));
 }
 
@@ -91,24 +167,11 @@ void factor_vm::primitive_fgetc()
 {
        FILE *file = pop_file_handle();
 
-       do {
-               int c = fgetc(file);
-               if(c == EOF)
-               {
-                       if(feof(file))
-                       {
-                               ctx->push(false_object);
-                               break;
-                       }
-                       else
-                               io_error();
-               }
-               else
-               {
-                       ctx->push(tag_fixnum(c));
-                       break;
-               }
-       } while(errno == EINTR);
+       int c = safe_fgetc(file);
+       if(c == EOF && feof(file))
+               ctx->push(false_object);
+       else
+               ctx->push(tag_fixnum(c));
 }
 
 void factor_vm::primitive_fread()
@@ -156,13 +219,7 @@ void factor_vm::primitive_fputc()
 {
        FILE *file = pop_file_handle();
        fixnum ch = to_fixnum(ctx->pop());
-
-       do {
-               if(fputc(ch,file) == EOF)
-                       io_error();
-               else
-                       break;
-       } while(errno == EINTR);
+       safe_fputc(ch, file);
 }
 
 void factor_vm::primitive_fwrite()
@@ -183,16 +240,7 @@ void factor_vm::primitive_fwrite()
 void factor_vm::primitive_ftell()
 {
        FILE *file = pop_file_handle();
-       off_t offset;
-
-       do {
-               if((offset = FTELL(file)) == -1)
-                       io_error();
-               else
-                       break;
-       } while(errno == EINTR);
-
-       ctx->push(from_signed_8(offset));
+       ctx->push(from_signed_8(safe_ftell(file)));
 }
 
 void factor_vm::primitive_fseek()
@@ -200,41 +248,19 @@ void factor_vm::primitive_fseek()
        int whence = to_fixnum(ctx->pop());
        FILE *file = pop_file_handle();
        off_t offset = to_signed_8(ctx->pop());
-
-       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);
+       safe_fseek(file,offset,whence);
 }
 
 void factor_vm::primitive_fflush()
 {
        FILE *file = pop_file_handle();
-       do {
-               if(fflush(file) == EOF)
-                       io_error();
-               else
-                       break;
-       } while(errno == EINTR);
+       safe_fflush(file);
 }
 
 void factor_vm::primitive_fclose()
 {
        FILE *file = pop_file_handle();
-       if(safe_fclose(file) == EOF)
-               io_error();
+       safe_fclose(file);
 }
 
 /* This function is used by FFI I/O. Accessing the errno global directly is
index c96c95863d312481045c9f1426c32a70c9c3b7b6..80010fc993061b2baa0ccd0b99db2cd6f179c5a4 100755 (executable)
--- a/vm/io.hpp
+++ b/vm/io.hpp
@@ -1,10 +1,6 @@
 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 */
 
 VM_C_API int err_no();
index 0ccf5020786d6b6925490c7ccfdf3d6c5febcb57..5d9b3204d3babebdc807c9decaf6263c78d539c8 100755 (executable)
--- a/vm/vm.hpp
+++ b/vm/vm.hpp
@@ -492,6 +492,15 @@ struct factor_vm
        //io
        void init_c_io();
        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();
        FILE *pop_file_handle();
        void primitive_fgetc();