2 * This software is part of the SBCL system. See the README file for
5 * This software is derived from the CMU CL system, which was
6 * written at Carnegie Mellon University and released into the
7 * public domain. The software is in the public domain and is
8 * provided with absolutely no warranty. See the COPYING and CREDITS
9 * files for more information.
19 #include "genesis/primitive-objects.h"
21 boolean
search_for_type(int type
, lispobj
**start
, int *count
)
25 while ((*count
== -1 || (*count
> 0)) &&
26 is_valid_lisp_addr((os_vm_address_t
)*start
)) {
31 if (widetag_of(obj
) == type
)
39 static int strcmp_ucs4_ascii(uint32_t* a
, char* b
)
43 // Lisp terminates UCS4 strings with NULL bytes - probably to no avail
44 // since null-terminated UCS4 isn't a common convention for any foreign ABI -
45 // but length has been pre-checked, so hitting an ASCII null is a win.
46 while (a
[i
] == ((unsigned char*)b
)[i
])
51 return a
[i
] - b
[i
]; // same return convention as strcmp()
54 boolean
search_for_symbol(char *name
, lispobj
**start
, int *count
)
56 struct symbol
*symbol
;
57 struct vector
*symbol_name
;
58 int namelen
= strlen(name
);
60 while (search_for_type(SYMBOL_HEADER_WIDETAG
, start
, count
)) {
61 symbol
= (struct symbol
*)native_pointer((lispobj
)*start
);
62 if (lowtag_of(symbol
->name
) == OTHER_POINTER_LOWTAG
) {
63 symbol_name
= (struct vector
*)native_pointer(symbol
->name
);
64 if (is_valid_lisp_addr((os_vm_address_t
)symbol_name
) &&
65 /* FIXME: Broken with more than one type of string
66 (i.e. even broken given (VECTOR NIL) */
67 ((widetag_of(symbol_name
->header
) == SIMPLE_BASE_STRING_WIDETAG
68 && fixnum_value(symbol_name
->length
) == namelen
69 && !strcmp((char *)symbol_name
->data
, name
))
70 #ifdef LISP_FEATURE_SB_UNICODE
71 || (widetag_of(symbol_name
->header
) == SIMPLE_CHARACTER_STRING_WIDETAG
72 && fixnum_value(symbol_name
->length
) == namelen
73 && !strcmp_ucs4_ascii((uint32_t*)symbol_name
->data
, name
))