16 Unsafe Operations
(require racket/unsafe/ops) |
All functions and forms provided by racket/base and racket check their arguments to ensure that the arguments conform to contracts and other constraints. For example, vector-ref checks its arguments to ensure that the first argument is a vector, that the second argument is an exact integer, and that the second argument is between 0 and one less than the vector’s length, inclusive.
Functions provided by racket/unsafe/ops are unsafe. They have certain constraints, but the constraints are not checked, which allows the system to generate and execute faster code. If arguments violate an unsafe function’s constraints, the function’s behavior and result is unpredictable, and the entire system can crash or become corrupted.
All of the exported bindings of racket/unsafe/ops are protected in the sense of protect-out, so access to unsafe operations can be prevented by adjusting the code inspector (see Code Inspectors).
16.1 Unsafe Numeric Operations
procedure
(unsafe-fx+ a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fx- a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fx* a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxquotient a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxremainder a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxmodulo a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxabs a) → fixnum?
a : fixnum?
procedure
(unsafe-fxand a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxior a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxxor a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxnot a) → fixnum?
a : fixnum?
procedure
(unsafe-fxlshift a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxrshift a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fx= a b) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx< a b) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx> a b) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx<= a b) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fx>= a b) → boolean?
a : fixnum? b : fixnum?
procedure
(unsafe-fxmin a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fxmax a b) → fixnum?
a : fixnum? b : fixnum?
procedure
(unsafe-fl+ a b) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-fl- a b) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-fl* a b) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-fl/ a b) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-flabs a) → flonum?
a : flonum?
procedure
(unsafe-fl= a b) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl< a b) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl> a b) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl<= a b) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-fl>= a b) → boolean?
a : flonum? b : flonum?
procedure
(unsafe-flmin a b) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-flmax a b) → flonum?
a : flonum? b : flonum?
procedure
(unsafe-flround a) → flonum?
a : flonum?
procedure
(unsafe-flfloor a) → flonum?
a : flonum?
procedure
(unsafe-flceiling a) → flonum?
a : flonum?
procedure
(unsafe-fltruncate a) → flonum?
a : flonum?
procedure
(unsafe-flsin a) → flonum?
a : flonum?
procedure
(unsafe-flcos a) → flonum?
a : flonum?
procedure
(unsafe-fltan a) → flonum?
a : flonum?
procedure
(unsafe-flasin a) → flonum?
a : flonum?
procedure
(unsafe-flacos a) → flonum?
a : flonum?
procedure
(unsafe-flatan a) → flonum?
a : flonum?
procedure
(unsafe-fllog a) → flonum?
a : flonum?
procedure
(unsafe-flexp a) → flonum?
a : flonum?
procedure
(unsafe-flsqrt a) → flonum?
a : flonum?
procedure
(unsafe-flexpt a b) → flonum?
a : flonum? b : flonum?
procedure
→ (and/c complex? inexact? (not/c real?)) a : flonum? b : flonum?
procedure
(unsafe-flreal-part a) → flonum?
a : (and/c complex? inexact? (not/c real?))
procedure
(unsafe-flimag-part a) → flonum?
a : (and/c complex? inexact? (not/c real?))
procedure
(unsafe-fx->fl a) → flonum?
a : fixnum?
procedure
(unsafe-fl->fx a) → fixnum?
a : flonum?
16.2 Unsafe Data Extraction
procedure
(unsafe-car p) → any/c
p : pair?
procedure
(unsafe-cdr p) → any/c
p : pair?
procedure
(unsafe-mcar p) → any/c
p : mpair?
procedure
(unsafe-mcdr p) → any/c
p : mpair?
procedure
(unsafe-set-mcar! p v) → void?
p : mpair? v : any/c
procedure
(unsafe-set-mcdr! p v) → void?
p : mpair? v : any/c
procedure
(unsafe-list-ref lst pos) → any/c
lst : pair? pos : (and/c exact-nonnegative-integer? fixnum?)
procedure
(unsafe-list-tail lst pos) → any/c
lst : any/c pos : (and/c exact-nonnegative-integer? fixnum?)
procedure
(unsafe-unbox b) → fixnum?
b : box?
procedure
(unsafe-set-box! b k) → void?
b : box? k : fixnum?
procedure
(unsafe-unbox* v) → any/c
v : (and/c box? (not/c impersonator?))
procedure
(unsafe-set-box*! v val) → void?
v : (and/c box? (not/c impersonator?)) val : any/c
procedure
(unsafe-box*-cas! loc old new) → boolean?
loc : box? old : any/c new : any/c
procedure
(unsafe-vector-length v) → fixnum?
v : vector?
procedure
(unsafe-vector-ref v k) → any/c
v : vector? k : fixnum?
procedure
(unsafe-vector-set! v k val) → void?
v : vector? k : fixnum? val : any/c
procedure
(unsafe-vector*-length v) → fixnum?
v : (and/c vector? (not/c impersonator?))
procedure
(unsafe-vector*-ref v k) → any/c
v : (and/c vector? (not/c impersonator?)) k : fixnum?
procedure
(unsafe-vector*-set! v k val) → void?
v : (and/c vector? (not/c impersonator?)) k : fixnum? val : any/c
A vector’s size can never be larger than a fixnum, so even vector-length always returns a fixnum.
procedure
(unsafe-string-length str) → fixnum?
str : string?
procedure
(unsafe-string-ref str k)
→ (and/c char? (lambda (ch) (<= 0 (char->integer ch) 255))) str : string? k : fixnum?
procedure
(unsafe-string-set! str k ch) → void?
str : (and/c string? (not/c immutable?)) k : fixnum? ch : char?
procedure
(unsafe-bytes-length bstr) → fixnum?
bstr : bytes?
procedure
(unsafe-bytes-ref bstr k) → byte?
bstr : bytes? k : fixnum?
procedure
(unsafe-bytes-set! bstr k b) → void?
bstr : (and/c bytes? (not/c immutable?)) k : fixnum? b : byte?
procedure
v : flvector?
procedure
(unsafe-flvector-ref v k) → any/c
v : flvector? k : fixnum?
procedure
(unsafe-flvector-set! v k x) → void?
v : flvector? k : fixnum? x : flonum?
procedure
(unsafe-f64vector-ref vec k) → flonum?
vec : f64vector? k : fixnum?
procedure
(unsafe-f64vector-set! vec k n) → void?
vec : f64vector? k : fixnum? n : flonum?
procedure
(unsafe-s16vector-ref vec k) → (integer-in -32768 32767)
vec : s16vector? k : fixnum?
procedure
(unsafe-s16vector-set! vec k n) → void?
vec : s16vector? k : fixnum? n : (integer-in -32768 32767)
procedure
(unsafe-u16vector-ref vec k) → (integer-in 0 65535)
vec : u16vector? k : fixnum?
procedure
(unsafe-u16vector-set! vec k n) → void?
vec : u16vector? k : fixnum? n : (integer-in 0 65535)
procedure
(unsafe-struct-ref v k) → any/c
v : any/c k : fixnum?
procedure
(unsafe-struct-set! v k val) → void?
v : any/c k : fixnum? val : any/c
procedure
(unsafe-struct*-ref v k) → any/c
v : (not/c impersonator?) k : fixnum?
procedure
(unsafe-struct*-set! v k val) → void?
v : (not/c impersonator?) k : fixnum? val : any/c