UNION: c-ptr byte-array alien displaced-alien ;
-: NULL ( -- null )
- #! C null value.
- 0 <alien> ;
-
M: alien hashcode ( obj -- n )
alien-address >fixnum ;
: init-fdsets ( -- read write except )
read-fdset get [ read-tasks get init-fdset ] keep
write-fdset get [ write-tasks get init-fdset ] keep
- NULL ;
+ f ;
: io-multiplex ( timeout -- )
>r FD_SETSIZE init-fdsets r> make-timeval select drop
: make-timeval ( ms -- timeval )
dup -1 = [
- drop NULL
+ drop f
] [
1000 /mod 1000 *
<timeval>
: win32-error-message ( id -- string )
4096 <buffer> dup >r >r >r
- FORMAT_MESSAGE_FROM_SYSTEM NULL r>
- LANG_NEUTRAL SUBLANG_DEFAULT MAKELANGID r> buffer-ptr <alien> 4096 NULL
+ FORMAT_MESSAGE_FROM_SYSTEM f r>
+ LANG_NEUTRAL SUBLANG_DEFAULT MAKELANGID r> buffer-ptr <alien> 4096 f
FormatMessage r> 2dup buffer-reset nip dup buffer-contents
swap buffer-free ;
GetLastError expected-error? [ drop f ] unless ;
: add-completion ( handle -- )
- completion-port get NULL 1 CreateIoCompletionPort drop ;
+ completion-port get f 1 CreateIoCompletionPort drop ;
: get-access ( -- file-mode )
"file-mode" get uncons
: win32-open-file ( file r w -- handle )
[
cons "file-mode" set
- get-access get-sharemode NULL get-create FILE_FLAG_OVERLAPPED NULL
+ get-access get-sharemode f get-create FILE_FLAG_OVERLAPPED f
CreateFile dup INVALID_HANDLE_VALUE = [ win32-throw-error ] when
dup add-completion
] with-scope ;
rot [ queue-error ] unless ;
: win32-init-stdio ( -- )
- INVALID_HANDLE_VALUE NULL NULL 1 CreateIoCompletionPort
+ INVALID_HANDLE_VALUE f f 1 CreateIoCompletionPort
completion-port set
<io-queue> io-queue set ;
] unless ;
: new-socket ( -- socket )
- AF_INET SOCK_STREAM 0 NULL NULL WSA_FLAG_OVERLAPPED WSASocket ;
+ AF_INET SOCK_STREAM 0 f f WSA_FLAG_OVERLAPPED WSASocket ;
: setup-sockaddr ( port -- sockaddr )
<sockaddr-in> swap
[
stream get alloc-io-callback init-overlapped
>r >r >r socket get r> r>
- buffer-ptr <alien> 0 32 32 NULL r> AcceptEx
+ buffer-ptr <alien> 0 32 32 f r> AcceptEx
[ handle-socket-error ] unless stop
] callcc1 pending-error drop
swap dup add-completion <win32-stream> <line-reader>
0 over set-overlapped-ext-internal-high
fileptr get dup 0 ? over set-overlapped-ext-offset
0 over set-overlapped-ext-offset-high
- NULL over set-overlapped-ext-event ;
+ f over set-overlapped-ext-event ;
: update-file-pointer ( whence -- )
file-size get [ fileptr [ + ] change ] [ drop ] ifte ;
update-timeout [
stream get alloc-io-callback init-overlapped >r
handle get out-buffer get [ buffer@ ] keep buffer-length
- NULL r> WriteFile [ handle-io-error ] unless stop
+ f r> WriteFile [ handle-io-error ] unless stop
] callcc1 pending-error
dup update-file-pointer
stream get alloc-io-callback init-overlapped >r
handle get in-buffer get [ buffer@ ] keep
buffer-capacity file-size get [ fileptr get - min ] when*
- NULL r>
+ f r>
ReadFile [ handle-io-error ] unless stop
] callcc1 pending-error
C: win32-stream ( handle -- stream )
swap [
- dup NULL GetFileSize dup -1 = not [
+ dup f GetFileSize dup -1 = not [
file-size set
] [ drop f file-size set ] ifte
handle set
drepl(F);
}
-INLINE void* alien_offset(CELL object)
+void* alien_offset(CELL object)
{
ALIEN *alien;
F_ARRAY *array;
case DISPLACED_ALIEN_TYPE:
d = untag_displaced_alien_fast(object);
return alien_offset(d->alien) + d->displacement;
+ case F_TYPE:
+ return NULL;
default:
type_error(ALIEN_TYPE,object);
return (void*)-1; /* can't happen */
void primitive_displaced_alien(void);
void primitive_alien_address(void);
+void* alien_offset(CELL object);
+
void fixup_alien(ALIEN* alien);
void fixup_displaced_alien(DISPLACED_ALIEN* d);
void collect_displaced_alien(DISPLACED_ALIEN* d);
}
/* FFI calls this */
-char *unbox_c_string(void)
+char* unbox_c_string(void)
{
CELL str = dpop();
- return (str ? to_c_string(untag_string(str)) : NULL);
+ if(type_of(str) == STRING_TYPE)
+ return to_c_string(untag_string(str));
+ else
+ return (char*)alien_offset(str);
}
/* FFI calls this */