byte-length generic word for determining alien buffer sizes of byte-arrays and float-arrays

db4
Joe Groff 2008-01-31 20:22:19 -08:00
parent ae31bc65d2
commit 7666949e13
5 changed files with 12 additions and 2 deletions

View File

@ -34,6 +34,10 @@ HELP: <alien>
{ $description "Creates an alien object, wrapping a raw memory address." }
{ $notes "Alien objects are invalidated between image saves and loads." } ;
HELP: byte-length
{ $values { "seq" "A byte array or float array" } { "n" "a non-negative integer" } }
{ $contract "Outputs the size of the byte array or float array data in bytes as presented to the C library interface." } ;
HELP: c-ptr
{ $class-description "Class of objects consisting of aliens, byte arrays and " { $link f } ". These objects can convert to pointer C types, which are all aliases of " { $snippet "void*" } "." } ;

View File

@ -28,6 +28,8 @@ PREDICATE: alien pinned-alien
UNION: pinned-c-ptr
pinned-alien POSTPONE: f ;
GENERIC: byte-length ( seq -- n ) flushable
M: f expired? drop t ;
: <alien> ( address -- alien )

View File

@ -15,6 +15,9 @@ M: byte-array new drop <byte-array> ;
M: byte-array equal?
over byte-array? [ sequence= ] [ 2drop f ] if ;
M: byte-array byte-length
length ;
INSTANCE: byte-array sequence
INSTANCE: byte-array simple-c-ptr
INSTANCE: byte-array c-ptr

View File

@ -32,7 +32,7 @@ HELP: <float-array> ( n initial -- float-array )
HELP: >float-array
{ $values { "seq" "a sequence" } { "float-array" float-array } }
{ $description "Outputs a freshly-allocated float array whose elements have the same boolean values as a given sequence." }
{ $description "Outputs a freshly-allocated float array whose elements have the same floating-point values as a given sequence." }
{ $errors "Throws an error if the sequence contains elements other than real numbers." } ;
HELP: 1float-array

View File

@ -1,6 +1,6 @@
! Copyright (C) 2007, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel kernel.private alien sequences
USING: kernel kernel.private alien alien.c-types sequences
sequences.private math math.private ;
IN: float-arrays
@ -12,6 +12,7 @@ PRIVATE>
M: float-array clone (clone) ;
M: float-array length array-capacity ;
M: float-array byte-length array-capacity "float" heap-size * ;
M: float-array nth-unsafe
float-array@ alien-double ;