A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.racket-lang.org/reference/unsafe.html below:

17 Unsafe Operations

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).

17.1 Unsafe Numeric Operations🔗

Changed in version 7.0.0.13 of package base: Allow zero or more arguments for unsafe-fx+ and unsafe-fx* and allow one or more arguments for unsafe-fx-.

Changed in version 7.0.0.13 of package base: Allow zero or more arguments for unsafe-fxand, unsafe-fxior, and unsafe-fxxor.
Changed in version 8.8.0.5: Added unsafe-fxrshift/logical.

Added in version 8.5.0.6 of package base.

Added in version 7.9.0.6 of package base.
Changed in version 8.15.0.12: Changed unsafe-fx-/wraparound to accept a single argument.

Changed in version 7.0.0.13 of package base: Allow one or more argument, instead of allowing just two.

Changed in version 7.0.0.13 of package base: Allow zero or more arguments for unsafe-fl+ and unsafe-fl* and one or more arguments for unsafe-fl- and unsafe-fl/.

Changed in version 7.0.0.13 of package base: Allow one or more argument, instead of allowing just two.

Added in version 7.8.0.7 of package base.

Added in version 7.8.0.7 of package base.

For

flonums

: Unchecked (potentially) versions of

flsin

,

flcos

,

fltan

,

flasin

,

flacos

,

flatan

,

fllog

,

flexp

,

flsqrt

, and

flexpt

. Currently, some of these bindings are simply aliases for the corresponding safe bindings.

Changed in version 7.7.0.8 of package base: Changed unsafe-fl->fx to truncate.

17.2 Unsafe Character Operations🔗

Added in version 7.0.0.14 of package base.

17.3 Unsafe Compound-Data Operations🔗

Unsafe variant of

cons

that produces a pair that claims to be a list—

without checking whether

rest

is a list.

As their oxymoronic names should suggest, there is no generally correct way to use these functions. They may be useful nevertheless, as a last resort, in settings where pairs are used in a constrained way and when making correct assumptions about Racket’s implementation (including limits on the compiler’s optimizations).

Some pitfalls of using unsafe-set-immutable-car! and unsafe-set-immutable-cdr!:

Added in version 7.9.0.18 of package base.

A vector’s size can never be larger than a fixnum, so even vector-length always returns a fixnum.

Changed in version 6.11.0.2 of package base: Added unsafe-vector*-cas!.
Changed in version 8.11.1.9: Added unsafe-vector-copy, unsafe-vector*-copy, unsafe-vector-set/copy, unsafe-vector*-set/copy, unsafe-vector-append, and unsafe-vector*-append.

Added in version 7.7.0.6 of package base.

Added in version 7.7.0.6 of package base.

Changed in version 7.5.0.15 of package base: Added unsafe-bytes-copy!.

Added in version 7.7.0.6 of package base.

Added in version 8.5.0.7 of package base.

Changed in version 6.11.0.2 of package base: Added unsafe-struct*-cas!.

Similar to

struct-info

, but without an inspector check, returning only the first result, and without support for

impersonators

.

Added in version 8.8.0.3 of package base.

Each unsafe ...-first and ...-next procedure may return, instead of a number index, an internal representation of a view into the hash structure, enabling faster iteration. The result of these ...-first and ...-next functions should be given as pos to the corresponding unsafe accessor functions.

If the pos provided to an accessor function for a mutable hash was formerly a valid hash index but is no longer a valid hash index for hash, and if bad-index-v is not provided, then the exn:fail:contract exception is raised. No behavior is specified for a pos that was never a valid hash index for hash. Note that bad-index-v argument is technically not useful for the unsafe-immutable-hash-iterate- functions, since an index cannot become invalid for an immutable hash.

Added in version 6.4.0.6 of package base.
Changed in version 7.0.0.10: Added the optional bad-index-v argument.
Changed in version 8.0.0.10: Added ephemeron variants.

Added in version 7.2.0.10 of package base.

17.4 Unsafe Extflonum Operations🔗

Unchecked (potentially) versions of

extflsin

,

extflcos

,

extfltan

,

extflasin

,

extflacos

,

extflatan

,

extfllog

,

extflexp

,

extflsqrt

, and

extflexpt

. Currently, some of these bindings are simply aliases for the corresponding safe bindings.

Changed in version 7.7.0.8 of package base: Changed unsafe-fl->fx to truncate.

17.5 Unsafe Impersonators and Chaperones🔗

If proc is itself an impersonator that is derived from impersonate-procedure* or chaperone-procedure*, beware that replacement-proc will not be able to call it correctly. Specifically, the impersonator produced by unsafe-impersonate-procedure will not get passed to a wrapper procedure that was supplied to impersonate-procedure* or chaperone-procedure* to generate proc.

Finally, unlike impersonate-procedure, unsafe-impersonate-procedure does not specially handle impersonator-prop:application-mark as a prop.

The unsafety of unsafe-impersonate-procedure is limited to the above differences from impersonate-procedure. The contracts on the arguments of unsafe-impersonate-procedure are checked when the arguments are supplied.

is equivalent to

Similarly, with the same assumptions about

f

, the following two procedures

wrap-f1

and

wrap-f2

are almost equivalent; they differ only in the error message produced when their arguments are functions that return multiple values (and that they update different global variables). The version using

unsafe-impersonate-procedure

will signal an error in the

let

expression about multiple return values, whereas the one using

impersonate-procedure

signals an error from

impersonate-procedure

about multiple return values.

Added in version 6.4.0.4 of package base.

Like

unsafe-impersonate-procedure

, but creates a

chaperone

. Since

wrapper-proc

will be called in lieu of

proc

,

wrapper-proc

is assumed to return a chaperone of the value that

proc

would return.

Added in version 6.4.0.4 of package base.

Like

impersonate-vector

, but instead of going through interposition procedures, all accesses to the impersonator are dispatched to

replacement-vec

.

The result of unsafe-impersonate-vector is an impersonator of vec.

Added in version 6.9.0.2 of package base.

Added in version 6.9.0.2 of package base.

17.6 Unsafe Assertions🔗

The compiler may take advantage of its liberty to pick convenient or efficient behavior in place of a call to unsafe-assert-unreachable. For example, the expression

may be compiled to code equivalent to

(lambda (x) (unsafe-car x))

because choosing to make (unsafe-assert-unreachable) behave the same as (unsafe-car x) makes both branches of the if the same, and then pair? test can be eliminated.

Added in version 8.0.0.11 of package base.

17.7 Unsafe Undefined🔗

The constant unsafe-undefined is used internally as a placeholder value. For example, it is used by letrec as a value for a variable that has not yet been assigned a value. Unlike the undefined value exported by racket/undefined, however, the unsafe-undefined value should not leak as the result of a safe expression, and it should not be passed as an optional argument to a procedure (because it may count as “no value provided”). Expression results that potentially produce unsafe-undefined can be guarded by check-not-unsafe-undefined, so that an exception can be raised instead of producing an undefined value.

The unsafe-undefined value is always eq? to itself.

Added in version 6.0.1.2 of package base.
Changed in version 6.90.0.29: Procedures with optional arguments sometimes use the unsafe-undefined value internally to mean “no argument supplied.”

The unsafe “undefined” constant.

See above for important constraints on the use of unsafe-undefined.

The same as

check-not-unsafe-undefined

, except that the error message (if any) is along the lines of “

sym

: undefined; assignment before initialization.”

Chaperones

v

if it is a structure (as viewed through some

inspector

). Every access of a field in the structure is checked to prevent returning

unsafe-undefined

. Similarly, every assignment to a field in the structure is checked (unless the check disabled as described below) to prevent assignment of a field whose current value is

unsafe-undefined

.

When a field access would otherwise produce unsafe-undefined or when a field assignment would replace unsafe-undefined, the exn:fail:contract exception is raised.

The chaperone’s field-assignment check is disabled whenever (continuation-mark-set-first #f prop:chaperone-unsafe-undefined) returns unsafe-undefined. Thus, a field-initializing assignment—one that is intended to replace the unsafe-undefined value of a field—should be wrapped with (with-continuation-mark prop:chaperone-unsafe-undefined unsafe-undefined ....).

The property value should be a list of symbols used as field names, but the list should be in reverse order of the structure’s fields. When a field access or assignment would produce or replace unsafe-undefined, the exn:fail:contract:variable exception is raised if a field name is provided by the structure property’s value, otherwise the exn:fail:contract exception is raised.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4