1#lang scribble/doc 2@(require "utils.rkt") 3 4@bc-title[#:tag "im:values+types"]{Values and Types} 5 6A Racket value is represented by a pointer-sized value. The low bit is 7a mark bit: a 1 in the low bit indicates an immediate integer, a 0 8indicates a (word-aligned) pointer. 9 10A pointer Racket value references a structure that begins with a 11@cppi{Scheme_Object} sub-structure, which in turn starts with a tag 12that has the C type @cppi{Scheme_Type}. The rest of the structure, 13following the @cppi{Scheme_Object} header, is type-dependent. 14Racket's C interface gives Racket values the type 15@cpp{Scheme_Object*}. (The ``object'' here does not refer to objects 16in the sense of the @racketmodname[racket/class] library.) 17 18Examples of @cpp{Scheme_Type} values include @cpp{scheme_pair_type} 19and @cpp{scheme_symbol_type}. Some of these are implemented as 20instances of @cppi{Scheme_Simple_Object}, which is defined in 21@filepath{scheme.h}, but extension or embedding code should never access 22this structure directly. Instead, the code should use macros, such as 23@cpp{SCHEME_CAR}, that provide access to the data of common Racket 24types. 25 26For most Racket types, a constructor is provided for creating values 27of the type. For example, @cpp{scheme_make_pair} takes two 28@cpp{Scheme_Object*} values and returns the @racket[cons] of the 29values. 30 31The macro @cppdef{SCHEME_TYPE} takes a @cpp{Scheme_Object *} and returns 32the type of the object. This macro performs the tag-bit check, and 33returns @cppi{scheme_integer_type} when the value is an immediate 34integer; otherwise, @cpp{SCHEME_TYPE} follows the pointer to get the 35type tag. Macros are provided to test for common Racket types; for 36example, @cpp{SCHEME_PAIRP} returns @cpp{1} if the value is a cons 37cell, @cpp{0} otherwise. 38 39In addition to providing constructors, Racket defines six global 40constant Racket values: @cppi{scheme_true}, @cppi{scheme_false}, 41@cppi{scheme_null}, @cppi{scheme_eof}, @cppi{scheme_void}, and 42@cppi{scheme_undefined}. Each of these has a type tag, but each is 43normally recognized via its constant address. 44 45@index['("types" "creating")]{An} extension or embedding application 46can create new a primitive data type by calling 47@cppi{scheme_make_type}, which returns a fresh @cpp{Scheme_Type} 48value. To create a collectable instance of this type, allocate memory 49for the instance with @cpp{scheme_malloc_atomic}. From Racket's 50perspective, the main constraint on the data format of such an 51instance is that the first @cpp{sizeof(Scheme_Object)} bytes must 52correspond to a @cpp{Scheme_Object} record; furthermore, the first 53@cpp{sizeof(Scheme_Type)} bytes must contain the value returned by 54@cpp{scheme_make_type}. Extensions with modest needs can use 55@cppi{scheme_make_cptr}, instead of creating an entirely new type. 56 57Racket values should never be allocated on the stack, and they should 58never contain pointers to values on the stack. Besides the problem of 59restricting the value's lifetime to that of the stack frame, 60allocating values on the stack creates problems for continuations and 61threads, both of which copy into and out of the stack. 62 63@; ---------------------------------------------------------------------- 64 65@section[#:tag "im:stdtypes"]{Standard Types} 66 67The following are the @cpp{Scheme_Type} values for the standard 68types: 69 70@itemize[ 71 72 @item{@cppdef{scheme_bool_type} --- the constants 73 @cpp{scheme_true} and @cpp{scheme_false} are the only values of this 74 type; use @cpp{SCHEME_FALSEP} to recognize @cpp{scheme_false} and use 75 @cpp{SCHEME_TRUEP} to recognize anything except @cpp{scheme_false}; 76 test for this type with @cppdef{SCHEME_BOOLP}} 77 78 @item{@cppdef{scheme_char_type} --- @cppdef{SCHEME_CHAR_VAL} 79 extracts the character (of type @cppi{mzchar}); test for this type 80 with @cppdef{SCHEME_CHARP}} 81 82 @item{@cppdef{scheme_integer_type} --- fixnum integers, which are 83 identified via the tag bit rather than following a pointer to this 84 @cpp{Scheme_Type} value; @cppdef{SCHEME_INT_VAL} extracts the integer 85 to an @cpp{intptr_t}; test for this type with @cppdef{SCHEME_INTP}} 86 87 @item{@cppdef{scheme_double_type} --- flonum inexact numbers; 88 @cppdef{SCHEME_FLOAT_VAL} or @cppdef{SCHEME_DBL_VAL} extracts the 89 floating-point value; test for this type with @cppdef{SCHEME_DBLP}} 90 91 @item{@cppdef{scheme_float_type} --- single-precision flonum 92 inexact numbers, when specifically enabled when compiling Racket; 93 @cppi{SCHEME_FLOAT_VAL} or @cppdef{SCHEME_FLT_VAL} extracts the 94 floating-point value; test for this type with @cppdef{SCHEME_FLTP}} 95 96 @item{@cppdef{scheme_bignum_type} --- test for this type with 97 @cppdef{SCHEME_BIGNUMP}} 98 99 @item{@cppdef{scheme_rational_type} --- test for this type with 100 @cppdef{SCHEME_RATIONALP}} 101 102 @item{@cppdef{scheme_complex_type} --- test for this type 103 with @cppdef{SCHEME_COMPLEXP}} 104 105 @item{@cppdef{scheme_char_string_type} --- @index['("strings" 106 "conversion to C")]{@cppdef{SCHEME_CHAR_STR_VAL}} extracts the string 107 as a @cpp{mzchar*}; the string is always nul-terminated, but may also 108 contain embedded nul characters, and the Racket string is modified if 109 this string is modified; @cppdef{SCHEME_CHAR_STRLEN_VAL} extracts the 110 string length (in characters, not counting the nul terminator); test 111 for this type with @cppdef{SCHEME_CHAR_STRINGP}} 112 113 @item{@cppdef{scheme_byte_string_type} --- 114 @cppdef{SCHEME_BYTE_STR_VAL} extracts the string as a @cpp{char*}; the 115 string is always nul-terminated, but may also contain embedded nul 116 characters, and the Racket string is modified if this string is 117 modified; @cppdef{SCHEME_BYTE_STRLEN_VAL} extracts the string length 118 (in bytes, not counting the nul terminator); test for this type with 119 @cppdef{SCHEME_BYTE_STRINGP}} 120 121 @item{@cppdef{scheme_path_type} --- 122 @index['("strings" "conversion to C")] @cppdef{SCHEME_PATH_VAL} 123 extracts the path as a @cpp{char*}; the string is always 124 nul-terminated; @cppdef{SCHEME_PATH_LEN} extracts the path length (in 125 bytes, not counting the nul terminator); test for this type with 126 @cppdef{SCHEME_PATHP}} 127 128 @item{@cppdef{scheme_symbol_type} --- @cppdef{SCHEME_SYM_VAL} 129 extracts the symbol's string as a @cpp{char*} UTF-8 encoding (do not 130 modify this string); @cppdef{SCHEME_SYM_LEN} extracts the number of 131 bytes in the symbol name (not counting the nul terminator); test for 132 this type with @cppdef{SCHEME_SYMBOLP}; 3m: see @secref["im:3m"] for 133 a caution about @cppi{SCHEME_SYM_VAL}} 134 135 @item{@cppdef{scheme_keyword_type} --- @cppdef{SCHEME_KEYWORD_VAL} 136 extracts the keyword's string (without the leading hash colon) as a 137 @cpp{char*} UTF-8 encoding (do not modify this string); 138 @cppdef{SCHEME_KEYWORD_LEN} extracts the number of bytes in the keyword 139 name (not counting the nul terminator); test for this type with 140 @cppdef{SCHEME_KEYWORDP}; 3m: see @secref["im:3m"] for a caution 141 about @cppi{SCHEME_KEYWORD_VAL}} 142 143 @item{@cppdef{scheme_box_type} --- @cppdef{SCHEME_BOX_VAL} 144 extracts/sets the boxed value; test for this type with 145 @cppdef{SCHEME_BOXP}} 146 147 @item{@cppdef{scheme_pair_type} --- @cppdef{SCHEME_CAR} extracts/sets 148 the @racket[car] and @cppdef{SCHEME_CDR} extracts/sets the 149 @racket[cdr]; test for this type with @cppdef{SCHEME_PAIRP}} 150 151 @item{@cppdef{scheme_mutable_pair_type} --- @cppdef{SCHEME_MCAR} extracts/sets 152 the @racket[mcar] and @cppdef{SCHEME_MCDR} extracts/sets the 153 @racket[mcdr]; test for this type with @cppdef{SCHEME_MPAIRP}} 154 155 @item{@cppdef{scheme_vector_type} --- @cppdef{SCHEME_VEC_SIZE} 156 extracts the length and @cppdef{SCHEME_VEC_ELS} extracts the array of 157 Racket values (the Racket vector is modified when this array is 158 modified); test for this type with @cppdef{SCHEME_VECTORP}; 3m: see 159 @secref["im:3m"] for a caution about @cppi{SCHEME_VEC_ELS}} 160 161 @item{@cppdef{scheme_flvector_type} --- @cppdef{SCHEME_FLVEC_SIZE} 162 extracts the length and @cppdef{SCHEME_FLVEC_ELS} extracts the array of 163 @cpp{double}s; test for this type with @cppdef{SCHEME_FLVECTORP}; 3m: see 164 @secref["im:3m"] for a caution about @cppi{SCHEME_FLVEC_ELS}} 165 166 @item{@cppdef{scheme_fxvector_type} --- uses the same representation 167 as @cpp{scheme_vector_type}, so use @cpp{SCHEME_VEC_SIZE} 168 for the length and @cpp{SCHEME_VEC_ELS} for the array of 169 Racket fixnum values; test for this type with @cppdef{SCHEME_FXVECTORP}; 3m: see 170 @secref["im:3m"] for a caution about @cppi{SCHEME_VEC_ELS}} 171 172 @item{@cppdef{scheme_structure_type} --- structure instances; test 173 for this type with @cppdef{SCHEME_STRUCTP}} 174 175 @item{@cppdef{scheme_struct_type_type} --- structure types; test for 176 this type with @cppdef{SCHEME_STRUCT_TYPEP}} 177 178 @item{@cppdef{scheme_struct_property_type} --- structure type 179 properties} 180 181 @item{@cppdef{scheme_input_port_type} --- @cppdef{SCHEME_INPORT_VAL} 182 extracts/sets the user data pointer; test for just this type with 183 @cppdef{SCHEME_INPORTP}, but use @cppdef{SCHEME_INPUT_PORTP} to recognize 184 all input ports (including structures with the 185 @racket[prop:input-port] property), and use @cppi{scheme_input_port_record} 186 to extract a @cppi{scheme_input_port_type} value from a general input port} 187 188 @item{@cppdef{scheme_output_port_type} --- @cppdef{SCHEME_OUTPORT_VAL} 189 extracts/sets the user data pointer; test for just this type with 190 @cppdef{SCHEME_OUTPORTP}, but use @cppdef{SCHEME_OUTPUT_PORTP} to 191 recognize all output ports (including structures with the 192 @racket[prop:output-port] property), and use @cppi{scheme_output_port_record} 193 to extract a @cppi{scheme_output_port_type} value from a general input port} 194 195 @item{@cppdef{scheme_thread_type} --- thread descriptors; test for 196 this type with @cppdef{SCHEME_THREADP}} 197 198 @item{@cppdef{scheme_sema_type} --- semaphores; test for this type 199 with @cppdef{SCHEME_SEMAP}} 200 201 @item{@cppdef{scheme_hash_table_type} --- test for this type with 202 @cppdef{SCHEME_HASHTP}} 203 204 @item{@cppdef{scheme_hash_tree_type} --- test for this type 205 with @cppdef{SCHEME_HASHTRP}} 206 207 @item{@cppdef{scheme_bucket_table_type} --- test for this type with 208 @cppdef{SCHEME_BUCKTP}} 209 210 @item{@cppdef{scheme_weak_box_type} --- test for this type with 211 @cppdef{SCHEME_WEAKP}; @cppdef{SCHEME_WEAK_PTR} extracts the contained 212 object, or @cpp{NULL} after the content is collected; do not set the 213 content of a weak box} 214 215 @item{@cppdef{scheme_namespace_type} --- namespaces; test for this 216 type with @cppdef{SCHEME_NAMESPACEP}} 217 218 @item{@cppdef{scheme_cpointer_type} --- @|void-const| pointer with a 219 type-describing @cpp{Scheme_Object}; @cppdef{SCHEME_CPTR_VAL} extracts 220 the pointer and @cppdef{SCHEME_CPTR_TYPE} extracts the type tag object; 221 test for this type with @cppdef{SCHEME_CPTRP}. The tag is used when 222 printing such objects when it's a symbol, a byte string, a string, or 223 a pair holding one of these in its car.} 224 225] 226 227The following are the procedure types: 228 229@itemize[ 230 231 @item{@cppdef{scheme_prim_type} --- a primitive procedure, 232 possibly with data elements} 233 234 @item{@cppdef{scheme_closed_prim_type} --- an old-style primitive 235 procedure with a data pointer} 236 237 @item{@cppdef{scheme_compiled_closure_type} --- a Racket 238 procedure} 239 240 @item{@cppdef{scheme_cont_type} --- a continuation} 241 242 @item{@cppdef{scheme_escaping_cont_type} --- an escape continuation} 243 244 @item{@cppdef{scheme_case_closure_type} --- a @racket[case-lambda] 245 procedure} 246 247 @item{@cppdef{scheme_native_closure_type} --- a procedure with 248 native code generated by the just-in-time compiler} 249 250] 251 252The predicate @cppdef{SCHEME_PROCP} returns 1 for all procedure types 253 and 0 for anything else. 254 255The following are additional number predicates: 256 257@itemize[ 258 259 @item{@cppdef{SCHEME_NUMBERP} --- all numerical types} 260 261 @item{@cppdef{SCHEME_REALP} --- all non-complex numerical types} 262 263 @item{@cppdef{SCHEME_EXACT_INTEGERP} --- fixnums and bignums} 264 265 @item{@cppdef{SCHEME_EXACT_REALP} --- fixnums, bignums, and rationals} 266 267 @item{@cppdef{SCHEME_FLOATP} --- both single-precision (when enabled) 268 and double-precision flonums} 269 270] 271 272@; ---------------------------------------------------------------------- 273 274@section{Global Constants} 275 276There are six global constants: 277 278@itemize[ 279 280 @item{@cppdef{scheme_null} --- test for this value with 281 @cppdef{SCHEME_NULLP}} 282 283 @item{@cppdef{scheme_eof} --- test for this value with 284 @cppdef{SCHEME_EOFP}} 285 286 @item{@cppdef{scheme_true}} 287 288 @item{@cppdef{scheme_false} --- test for this value with 289 @cppdef{SCHEME_FALSEP}; test @italic{against} it with 290 @cppdef{SCHEME_TRUEP}} 291 292 @item{@cppdef{scheme_void} --- test for this value with 293 @cppdef{SCHEME_VOIDP}} 294 295 @item{@cppdef{scheme_undefined}} 296 297] 298 299In some embedding contexts, the function forms 300@cppi{scheme_make_null}, etc., must be used, instead. 301 302@; ---------------------------------------------------------------------- 303 304@section[#:tag "im:strings"]{Strings} 305 306As noted in @secref["im:unicode"], a Racket character is a Unicode 307 code point represented by a @cpp{mzchar} value, and character strings 308 are @cpp{mzchar} arrays. Racket also supplies byte strings, which 309 are @cpp{char} arrays. 310 311For a character string @var{s}, @cpp{@cpp{SCHEME_CHAR_STR_VAL}(@var{s})} 312 produces a pointer to @cpp{mzchar}s, not @cpp{char}s. Convert a 313 character string to its UTF-8 encoding as byte string with 314 @cpp{scheme_char_string_to_byte_string}. For a byte string 315 @var{bs}, @cpp{@cpp{SCHEME_BYTE_STR_VAL}(@var{bs})} produces a pointer 316 to @cpp{char}s. The function 317 @cpp{scheme_byte_string_to_char_string} decodes a byte string as 318 UTF-8 and produces a character string. The functions 319 @cpp{scheme_char_string_to_byte_string_locale} and 320 @cpp{scheme_byte_string_to_char_string_locale} are similar, but 321 they use the current locale's encoding instead of UTF-8. 322 323For more fine-grained control over UTF-8 encoding, use the 324 @cpp{scheme_utf8_decode} and @cpp{scheme_utf8_encode} functions, which 325 are described in @secref["im:encodings"]. 326 327@; ---------------------------------------------------------------------- 328 329@section{Value Functions} 330 331@function[(Scheme_Object* scheme_make_null)]{ 332 333Returns @cppi{scheme_null}. 334} 335 336@function[(Scheme_Object* scheme_make_eof)]{ 337 338Returns @cppi{scheme_eof}. 339} 340 341@function[(Scheme_Object* scheme_make_true)]{ 342 343Returns @cppi{scheme_true}. 344} 345 346@function[(Scheme_Object* scheme_make_false)]{ 347 348Returns @cppi{scheme_false}. 349} 350 351@function[(Scheme_Object* scheme_make_void)]{ 352 353Returns @cppi{scheme_void}. 354} 355 356@function[(Scheme_Object* scheme_make_char 357 [mzchar ch])]{ 358 359Returns the character value. The @var{ch} value must be a legal 360Unicode code point (and not a surrogate, for example). The first 256 361characters are represented by constant Racket values, and others are 362allocated.} 363 364@function[(Scheme_Object* scheme_make_char_or_null 365 [mzchar ch])]{ 366 367Like @cpp{scheme_make_char}, but the result is @cpp{NULL} if @var{ch} 368is not a legal Unicode code point.} 369 370@function[(Scheme_Object* scheme_make_character 371 [mzchar ch])]{ 372 373Returns the character value. This is a macro that directly accesses 374 the array of constant characters when @var{ch} is less than 256.} 375 376@function[(Scheme_Object* scheme_make_ascii_character 377 [mzchar ch])]{ 378 379Returns the character value, assuming that @var{ch} is less than 256. (This is a macro.)} 380 381@function[(Scheme_Object* scheme_make_integer 382 [intptr_t i])]{ 383 384Returns the integer value; @var{i} must fit in a fixnum. (This is a macro.)} 385 386@function[(Scheme_Object* scheme_make_integer_value 387 [intptr_t i])]{ 388 389Returns the integer value. If @var{i} does not fit in a fixnum, 390 a bignum is returned.} 391 392@function[(Scheme_Object* scheme_make_integer_value_from_unsigned 393 [uintptr_t i])]{ 394 395Like @cpp{scheme_make_integer_value}, but for unsigned integers.} 396 397@function[(Scheme_Object* scheme_make_integer_value_from_long_long 398 [mzlonglong i])]{ 399 400Like @cpp{scheme_make_integer_value}, but for @cpp{mzlonglong} 401 values (see @secref["im:intsize"]).} 402 403@function[(Scheme_Object* scheme_make_integer_value_from_unsigned_long_long 404 [umzlonglong i])]{ 405 406Like @cpp{scheme_make_integer_value_from_long_long}, but for unsigned integers.} 407 408@function[(Scheme_Object* scheme_make_integer_value_from_long_halves 409 [uintptr_t hi] 410 [uintptr_t lo])]{ 411 412Creates an integer given the high and low @cpp{intptr_t}s of a signed 413 integer. Note that on 64-bit platforms where @cpp{long long} is the 414 same as @cpp{intptr_t}, the resulting integer has 128 bits. (See also 415 @secref["im:intsize"].)} 416 417@function[(Scheme_Object* scheme_make_integer_value_from_unsigned_long_halves 418 [uintptr_t hi] 419 [uintptr_t lo])]{ 420 421Creates an integer given the high and low @cpp{intptr_t}s of an unsigned 422 integer. Note that on 64-bit platforms where @cpp{long long} is the 423 same as @cpp{intptr_t}, the resulting integer has 128 bits.} 424 425@function[(int scheme_get_int_val 426 [Scheme_Object* o] 427 [intptr_t* i])]{ 428 429Extracts the integer value. Unlike the @cppi{SCHEME_INT_VAL} macro, 430 this procedure will extract an integer that fits in a @cpp{intptr_t} from 431 a Racket bignum. If @var{o} fits in a @cpp{intptr_t}, the extracted 432 integer is placed in @var{*i} and 1 is returned; otherwise, 0 is 433 returned and @var{*i} is unmodified.} 434 435@function[(int scheme_get_unsigned_int_val 436 [Scheme_Object* o] 437 [uintptr_t* i])]{ 438 439Like @cpp{scheme_get_int_val}, but for unsigned integers.} 440 441@function[(int scheme_get_long_long_val 442 [Scheme_Object* o] 443 [mzlonglong* i])]{ 444 445Like @cpp{scheme_get_int_val}, but for @cpp{mzlonglong} values (see 446 @secref["im:intsize"]).} 447 448@function[(int scheme_get_unsigned_long_long_val 449 [Scheme_Object* o] 450 [umzlonglong* i])]{ 451 452Like @cpp{scheme_get_int_val}, but for unsigned @cpp{mzlonglong} values (see 453 @secref["im:intsize"]).} 454 455@function[(Scheme_Object* scheme_make_double 456 [double d])]{ 457 458Creates a new floating-point value.} 459 460@function[(Scheme_Object* scheme_make_float 461 [float d])]{ 462 463Creates a new single-precision floating-point value. The procedure is 464available only when Racket is compiled with single-precision 465numbers enabled.} 466 467@function[(double scheme_real_to_double 468 [Scheme_Object* o])]{ 469 470Converts a Racket real number to a double-precision floating-point 471value.} 472 473@function[(Scheme_Object* scheme_make_pair 474 [Scheme_Object* carv] 475 [Scheme_Object* cdrv])]{ 476 477Makes a @racket[cons] pair.} 478 479@function[(Scheme_Object* scheme_make_byte_string 480 [char* bytes])]{ 481 482Makes a Racket byte string from a nul-terminated C string. The 483@var{bytes} string is copied.} 484 485@function[(Scheme_Object* scheme_make_byte_string_without_copying 486 [char* bytes])]{ 487 488Like @cpp{scheme_make_byte_string}, but the string is not copied.} 489 490@function[(Scheme_Object* scheme_make_sized_byte_string 491 [char* bytes] 492 [intptr_t len] 493 [int copy])]{ 494 495Makes a byte string value with size @var{len}. A copy of @var{bytes} 496 is made if @var{copy} is not 0. The string @var{bytes} should 497 contain @var{len} bytes; @var{bytes} can contain the nul byte at any 498 position, and need not be nul-terminated if @var{copy} is 499 non-zero. However, if @var{len} is negative, then the nul-terminated 500 length of @var{bytes} is used for the length, and if @var{copy} is 501 zero, then @var{bytes} must be nul-terminated.} 502 503@function[(Scheme_Object* scheme_make_sized_offset_byte_string 504 [char* bytes] 505 [intptr_t d] 506 [intptr_t len] 507 [int copy])]{ 508 509Like @cpp{scheme_make_sized_byte_string}, except the @var{len} 510 characters start from position @var{d} in @var{bytes}. If @var{d} is 511 non-zero, then @var{copy} must be non-zero.} 512 513@function[(Scheme_Object* scheme_alloc_byte_string 514 [intptr_t size] 515 [char fill])]{ 516 517Allocates a new Racket byte string.} 518 519@function[(Scheme_Object* scheme_append_byte_string 520 [Scheme_Object* a] 521 [Scheme_Object* b])]{ 522 523Creates a new byte string by appending the two given byte strings.} 524 525@function[(Scheme_Object* scheme_make_locale_string 526 [char* bytes])]{ 527 528Makes a Racket string from a nul-terminated byte string that is a 529 locale-specific encoding of a character string; a new string is 530 allocated during decoding. The ``locale in the name of this function 531 thus refers to @var{bytes}, and not the resulting string (which is 532 internally stored as UCS-4).} 533 534@function[(Scheme_Object* scheme_make_utf8_string 535 [char* bytes])]{ 536 537Makes a Racket string from a nul-terminated byte string that is a 538 UTF-8 encoding. A new string is allocated during decoding. The 539 ``utf8'' in the name of this function thus refers to @var{bytes}, and 540 not the resulting string (which is internally stored as UCS-4).} 541 542@function[(Scheme_Object* scheme_make_sized_utf8_string 543 [char* bytes] 544 [intptr_t len])]{ 545 546Makes a string value, based on @var{len} UTF-8-encoding bytes (so the 547 resulting string is @var{len} characters or less). The string 548 @var{bytes} should contain at least @var{len} bytes; @var{bytes} can 549 contain the nul byte at any position, and need not be 550 null-terminated. However, if @var{len} is negative, then the 551 nul-terminated length of @var{bytes} is used for the length.} 552 553@function[(Scheme_Object* scheme_make_sized_offset_utf8_string 554 [char* bytes] 555 [intptr_t d] 556 [intptr_t len])]{ 557 558Like @cpp{scheme_make_sized_char_string}, except the @var{len} characters 559 start from position @var{d} in @var{bytes}.} 560 561 562@function[(Scheme_Object* scheme_make_char_string 563 [mzchar* chars])]{ 564 565Makes a Racket string from a nul-terminated UCS-4 string. The 566 @var{chars} string is copied.} 567 568@function[(Scheme_Object* scheme_make_char_string_without_copying 569 [mzchar* chars])]{ 570 571Like @cpp{scheme_make_char_string}, but the string is not copied.} 572 573@function[(Scheme_Object* scheme_make_sized_char_string 574 [mzchar* chars] 575 [intptr_t len] 576 [int copy])]{ 577 578Makes a string value with size @var{len}. A copy of @var{chars} is 579 made if @var{copy} is not 0. The string @var{chars} should 580 contain @var{len} characters; @var{chars} can contain the nul 581 character at any position, and need not be nul-terminated 582 if @var{copy} is non-zero. However, if @var{len} is negative, then 583 the nul-terminated length of @var{chars} is used for the length, and 584 if @var{copy} is zero, then the @var{chars} must be nul-terminated.} 585 586@function[(Scheme_Object* scheme_make_sized_offset_char_string 587 [mzchar* chars] 588 [intptr_t d] 589 [intptr_t len] 590 [int copy])]{ 591 592Like @cpp{scheme_make_sized_char_string}, except the @var{len} 593 characters start from position @var{d} in @var{chars}. If @var{d} is 594 non-zero, then @var{copy} must be non-zero.} 595 596@function[(Scheme_Object* scheme_alloc_char_string 597 [intptr_t size] 598 [mzchar fill])]{ 599 600Allocates a new Racket string.} 601 602@function[(Scheme_Object* scheme_append_char_string 603 [Scheme_Object* a] 604 [Scheme_Object* b])]{ 605 606Creates a new string by appending the two given strings.} 607 608@function[(Scheme_Object* scheme_char_string_to_byte_string 609 [Scheme_Object* s])]{ 610 611Converts a Racket character string into a Racket byte string via UTF-8.} 612 613@function[(Scheme_Object* scheme_byte_string_to_char_string 614 [Scheme_Object* s])]{ 615 616Converts a Racket byte string into a Racket character string via UTF-8.} 617 618@function[(Scheme_Object* scheme_char_string_to_byte_string_locale 619 [Scheme_Object* s])]{ 620 621Converts a Racket character string into a Racket byte string via the locale's encoding.} 622 623@function[(Scheme_Object* scheme_byte_string_to_char_string_locale 624 [Scheme_Object* s])]{ 625 626Converts a Racket byte string into a Racket character string via the locale's encoding.} 627 628@function[(Scheme_Object* scheme_intern_symbol 629 [char* name])]{ 630 631Finds (or creates) the symbol matching the given nul-terminated, ASCII 632 string (not UTF-8). The case of @var{name} is (non-destructively) normalized 633 before interning if @cppi{scheme_case_sensitive} is 0.} 634 635@function[(Scheme_Object* scheme_intern_exact_symbol 636 [char* name] 637 [int len])]{ 638 639Creates or finds a symbol given the symbol's length in UTF-8-encoding 640 bytes. The case of @var{name} is not normalized.} 641 642@function[(Scheme_Object* scheme_intern_exact_char_symbol 643 [mzchar* name] 644 [int len])]{ 645 646Like @cpp{scheme_intern_exact_symbol}, but given a character array 647 instead of a UTF-8-encoding byte array.} 648 649@function[(Scheme_Object* scheme_make_symbol 650 [char* name])]{ 651 652Creates an uninterned symbol from a nul-terminated, UTF-8-encoding 653 string. The case is not normalized.} 654 655@function[(Scheme_Object* scheme_make_exact_symbol 656 [char* name] 657 [int len])]{ 658 659Creates an uninterned symbol given the symbol's length in 660 UTF-8-encoded bytes.} 661 662@function[(Scheme_Object* scheme_intern_exact_keyword 663 [char* name] 664 [int len])]{ 665 666Creates or finds a keyword given the keywords length in UTF-8-encoding 667 bytes. The case of @var{name} is not normalized, and it should 668 not include the leading hash and colon of the keyword's printed form.} 669 670@function[(Scheme_Object* scheme_intern_exact_char_keyword 671 [mzchar* name] 672 [int len])]{ 673 674Like @cpp{scheme_intern_exact_keyword}, but given a character array 675 instead of a UTF-8-encoding byte array.} 676 677@function[(Scheme_Object* scheme_make_vector 678 [intptr_t size] 679 [Scheme_Object* fill])]{ 680 681Allocates a new vector.} 682 683@function[(Scheme_Double_Vector* scheme_alloc_flvector 684 [intptr_t size])]{ 685 686Allocates an uninitialized flvector. 687The result type is effectively an alias for @cpp{Scheme_Object*}.} 688 689@function[(Scheme_Vector* scheme_alloc_fxvector 690 [intptr_t size])]{ 691 692Allocates an uninitialized fxvector. 693The result type is effectively an alias for @cpp{Scheme_Object*}.} 694 695@function[(Scheme_Object* scheme_box 696 [Scheme_Object* v])]{ 697 698Creates a new box containing the value @var{v}.} 699 700@function[(Scheme_Object* scheme_make_weak_box 701 [Scheme_Object* v])]{ 702 703Creates a new weak box containing the value @var{v}.} 704 705@function[(Scheme_Type scheme_make_type 706 [char* name])]{ 707 708Creates a new type (not a Racket value). The type tag is valid across 709all @|tech-place|s.} 710 711@function[(Scheme_Object* scheme_make_cptr 712 [void* ptr] 713 [const-Scheme_Object* typetag])]{ 714 715Creates a C-pointer object that encapsulates @var{ptr} and uses 716 @var{typetag} to identify the type of the pointer. The 717 @cppi{SCHEME_CPTRP} macro recognizes objects created by 718 @cpp{scheme_make_cptr}. The @cppi{SCHEME_CPTR_VAL} macro extracts 719 the original @var{ptr} from the Racket object, and 720 @cppi{SCHEME_CPTR_TYPE} extracts the type tag. 721 The @cppi{SCHEME_CPTR_OFFSETVAL} macro returns @cpp{0} 722 for the result Racket object. 723 724 The @var{ptr} can refer to either memory managed by the garbage 725 collector or by some other memory manager. Beware, however, of 726 retaining a @var{ptr} that refers to memory released by another 727 memory manager, since the enclosing memory range might later become 728 managed by the garbage collector (in which case @var{ptr} might 729 become an invalid pointer that can crash the garbage collector).} 730 731@function[(Scheme_Object* scheme_make_external_cptr 732 [void* ptr] 733 [const-Scheme_Object* typetag])]{ 734 735Like @cpp{scheme_make_cptr}, but @var{ptr} is never treated as 736referencing memory managed by the garbage collector.} 737 738@function[(Scheme_Object* scheme_make_offset_cptr 739 [void* ptr] 740 [intptr_t offset] 741 [const-Scheme_Object* typetag])]{ 742 743Creates a C-pointer object that encapsulates both @var{ptr} and @var{offset}. 744 The @cppi{SCHEME_CPTR_OFFSETVAL} macro returns @var{offset} 745 for the result Racket object (and the macro be used to change the offset, 746 since it also works on objects with no offset). 747 748 The @var{ptr} can refer to either memory managed by the garbage 749 collector or by some other memory manager; see also 750 @cpp{scheme_make_cptr}.} 751 752@function[(Scheme_Object* scheme_make_offset_external_cptr 753 [void* ptr] 754 [intptr_t offset] 755 [const-Scheme_Object* typetag])]{ 756 757 Like @cpp{scheme_make_offset_cptr}, but @var{ptr} is never treated as 758referencing memory managed by the garbage collector.} 759 760 761@function[(void scheme_set_type_printer 762 [Scheme_Type type] 763 [Scheme_Type_Printer printer])]{ 764 765Installs a printer to be used for printing (or writing or displaying) 766 values that have the type tag @var{type}. 767 768The type of @var{printer} is defined as follows: 769 770@verbatim[#:indent 2]{ 771 typedef void (*Scheme_Type_Printer)(Scheme_Object *v, int dis, 772 Scheme_Print_Params *pp); 773} 774 775Such a printer must print a representation of the value using 776 @cppi{scheme_print_bytes} and @cppi{scheme_print_string}. The 777 first argument to the printer, @var{v}, is the value to be printed. 778 The second argument indicates whether @var{v} is printed via 779 @racket[write] or @racket[display]. The last argument is to be passed 780 on to @cppi{scheme_print_bytes} or @cppi{scheme_print_string} to 781 identify the printing context.} 782 783@function[(void scheme_print_bytes 784 [Scheme_Print_Params* pp] 785 [const-char* str] 786 [int offset] 787 [int len])]{ 788 789Writes the content of @var{str} --- starting from @var{offset} and 790 running @var{len} bytes --- into a printing context determined by 791 @var{pp}. This function is for use by a printer that is installed 792 with @cpp{scheme_set_type_printer}.} 793 794@function[(void scheme_print_string 795 [Scheme_Print_Params* pp] 796 [const-mzchar* str] 797 [int offset] 798 [int len])]{ 799 800Writes the content of @var{str} --- starting from @var{offset} and 801 running @var{len} characters --- into a printing context determined 802 by @var{pp}. This function is for use by a printer that is installed 803 with @cpp{scheme_set_type_printer}.} 804 805@function[(void scheme_set_type_equality 806 [Scheme_Type type] 807 [Scheme_Equal_Proc equalp] 808 [Scheme_Primary_Hash_Proc hash1] 809 [Scheme_Secondary_Hash_Proc hash2])]{ 810 811Installs an equality predicate and associated hash functions for 812values that have the type tag @var{type}. The @var{equalp} predicate 813is only applied to values that both have tag @var{type}. 814 815The type of @var{equalp}, @var{hash1}, and @var{hash2} are defined as 816follows: 817 818@verbatim[#:indent 2]{ 819 typedef int (*Scheme_Equal_Proc)(Scheme_Object* obj1, 820 Scheme_Object* obj2, 821 void* cycle_data); 822 typedef intptr_t (*Scheme_Primary_Hash_Proc)(Scheme_Object* obj, 823 intptr_t base, 824 void* cycle_data); 825 typedef intptr_t (*Scheme_Secondary_Hash_Proc)(Scheme_Object* obj, 826 void* cycle_data); 827} 828 829The two hash functions are use to generate primary and secondary keys 830for double hashing in an @racket[equal?]-based hash table. The result 831of the primary-key function should depend on both @var{obj} and 832@var{base}. 833 834The @var{cycle_data} argument in each case allows checking and hashing 835on cyclic values. It is intended for use in recursive checking or 836hashing via @cpp{scheme_recur_equal}, 837@cpp{scheme_recur_equal_hash_key}, and 838@cpp{scheme_recur_equal_hash_key}. That is, do not call plain 839@cpp{scheme_equal}, @cpp{scheme_equal_hash_key}, or 840@cpp{scheme_equal_hash_key} for recursive checking or hashing on 841sub-elements of the given value(s).} 842 843 844