-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.data alien.parser
 assocs byte-arrays classes compiler.units functors kernel lexer


M: bad-byte-array-length summary
    drop "Byte array length doesn't divide type width" ;

: (underlying) ( n c-type -- array )
    heap-size * (byte-array) ; inline

    [ \ T heap-size calloc ] keep <direct-A> ; inline

: byte-array>A ( byte-array -- specialized-array )
    >c-ptr dup byte-array? [
        dup length \ T heap-size /mod 0 =
        [ <direct-A> ]
        [ drop \ T bad-byte-array-length ] if
    ] [ not-a-byte-array ] if ; inline

M: A clone [ underlying>> clone ] [ length>> ] bi <direct-A> ; inline

