-unsigned int typedef_hash(const char *s) {
- unsigned int hash = 0;
- unsigned int size = strlen(s);
- unsigned int iter;
-
- for (iter = 0; iter < size; iter++) {
- hash += s[iter];
- hash += (hash << 10);
- hash ^= (hash >> 6);
- }
- hash += (hash << 3);
- hash ^= (hash >> 11);
- hash += (hash << 15);
-
- return hash % 1024;
+uint32_t typedef_hash(const char *s) {
+ return util_crc32(s, strlen(s), 1024);
if (find)
return error(file, ERROR_PARSE, "typedef for %s already exists or conflicts\n", to);
if (find)
return error(file, ERROR_PARSE, "typedef for %s already exists or conflicts\n", to);
/* check if the type exists first */
if (strncmp(from, "float", sizeof("float")) == 0 ||
strncmp(from, "vector", sizeof("vector")) == 0 ||
strncmp(from, "string", sizeof("string")) == 0 ||
strncmp(from, "entity", sizeof("entity")) == 0 ||
strncmp(from, "void", sizeof("void")) == 0) {
/* check if the type exists first */
if (strncmp(from, "float", sizeof("float")) == 0 ||
strncmp(from, "vector", sizeof("vector")) == 0 ||
strncmp(from, "string", sizeof("string")) == 0 ||
strncmp(from, "entity", sizeof("entity")) == 0 ||
strncmp(from, "void", sizeof("void")) == 0) {
-
- typedef_table[hash] = mem_a(sizeof(typedef_node));
- typedef_table[hash]->name = util_strdup(from);
+
+ typedef_table[hash] = mem_a(sizeof(typedef_node));
+ if (typedef_table[hash])
+ typedef_table[hash]->name = util_strdup(from);
+ else
+ return error(file, ERROR_PARSE, "ran out of resources for typedef %s\n", to);
- typedef_table[hash] = mem_a(sizeof(typedef_node));
- typedef_table[hash]->name = util_strdup(find->name);
+ typedef_table[hash] = mem_a(sizeof(typedef_node));
+ if (typedef_table[hash])
+ typedef_table[hash]->name = util_strdup(find->name);
+ else
+ return error(file, ERROR_PARSE, "ran out of resources for typedef %s\n", to);