diff --git a/basis/alien/arrays/arrays.factor b/basis/alien/arrays/arrays.factor index c823b614d9..8253d9458c 100644 --- a/basis/alien/arrays/arrays.factor +++ b/basis/alien/arrays/arrays.factor @@ -28,7 +28,7 @@ M: array stack-size drop "void*" stack-size ; M: array c-type-boxer-quot drop f ; -M: array c-type-unboxer-quot drop f ; +M: array c-type-unboxer-quot drop [ >c-ptr ] ; M: value-type c-type-reg-class drop int-regs ; diff --git a/basis/alien/c-types/c-types.factor b/basis/alien/c-types/c-types.factor index d1354cb04e..ff9d4cefc4 100644 --- a/basis/alien/c-types/c-types.factor +++ b/basis/alien/c-types/c-types.factor @@ -201,13 +201,13 @@ M: byte-array byte-length length ; 1 swap malloc-array ; inline : malloc-byte-array ( byte-array -- alien ) - dup length [ nip malloc dup ] 2keep memcpy ; + dup byte-length [ nip malloc dup ] 2keep memcpy ; : memory>byte-array ( alien len -- byte-array ) [ nip (byte-array) dup ] 2keep memcpy ; : byte-array>memory ( byte-array base -- ) - swap dup length memcpy ; + swap dup byte-length memcpy ; : array-accessor ( type quot -- def ) [ @@ -263,7 +263,7 @@ M: long-long-type box-return ( type -- ) ] when ; : malloc-file-contents ( path -- alien len ) - binary file-contents dup malloc-byte-array swap length ; + binary file-contents [ malloc-byte-array ] [ length ] bi ; : if-void ( type true false -- ) pick "void" = [ drop nip call ] [ nip call ] if ; inline @@ -283,9 +283,10 @@ M: long-long-type box-return ( type -- ) c-ptr >>class [ alien-cell ] >>getter - [ set-alien-cell ] >>setter + [ [ >c-ptr ] 2dip set-alien-cell ] >>setter bootstrap-cell >>size bootstrap-cell >>align + [ >c-ptr ] >>unboxer-quot "box_alien" >>boxer "alien_offset" >>unboxer "void*" define-primitive-type diff --git a/core/alien/alien.factor b/core/alien/alien.factor index c97e36e889..93d1a8e306 100644 --- a/core/alien/alien.factor +++ b/core/alien/alien.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2004, 2008 Slava Pestov. +! Copyright (C) 2004, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs kernel math namespaces sequences system kernel.private byte-arrays arrays init ; @@ -18,6 +18,14 @@ PREDICATE: pinned-alien < alien underlying>> pinned-c-ptr? ; UNION: pinned-c-ptr pinned-alien POSTPONE: f ; +GENERIC: >c-ptr ( obj -- c-ptr ) + +M: c-ptr >c-ptr ; + +SLOT: underlying + +M: object >c-ptr underlying>> ; + GENERIC: expired? ( c-ptr -- ? ) flushable M: alien expired? expired>> ;