Unbreak sparc build.
[sbcl.git] / src / runtime / search.c
blobc736aa0bf9d546ae0a68fff154663d41e6dc4a9b
1 /*
2 * This software is part of the SBCL system. See the README file for
3 * more information.
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.
12 #include <string.h>
14 #include "sbcl.h"
15 #include "runtime.h"
16 #include "os.h"
17 #include "search.h"
18 #include "thread.h"
19 #include "genesis/primitive-objects.h"
21 boolean search_for_type(int type, lispobj **start, int *count)
23 lispobj obj;
25 while ((*count == -1 || (*count > 0)) &&
26 is_valid_lisp_addr((os_vm_address_t)*start)) {
27 obj = **start;
28 if (*count != -1)
29 *count -= 2;
31 if (widetag_of(obj) == type)
32 return 1;
34 (*start) += 2;
36 return 0;
39 static int strcmp_ucs4_ascii(uint32_t* a, char* b)
41 int i = 0;
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])
47 if (b[i] == 0)
48 return 0;
49 else
50 ++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))
74 #endif
76 return 1;
78 (*start) += 2;
80 return 0;