Store a copy of parameter str in a hash tbl */
| 43 | |
| 44 | /* Store a copy of parameter str in a hash tbl */ |
| 45 | struct interned_string *intern_ptr(const char *str) |
| 46 | { |
| 47 | struct interned_string *s; |
| 48 | |
| 49 | pthread_once(&once, init_interned_strings); |
| 50 | Pthread_mutex_lock(&intern_lk); |
| 51 | s = hash_find_readonly(interned_strings, &str); |
| 52 | if (s == NULL) { |
| 53 | s = malloc(sizeof(struct interned_string)); |
| 54 | if (s == NULL) { |
| 55 | Pthread_mutex_unlock(&intern_lk); |
| 56 | return NULL; |
| 57 | } |
| 58 | s->str = strdup(str); |
| 59 | s->ix = node_ix++; |
| 60 | s->ptr = NULL; |
| 61 | s->clptr = NULL; |
| 62 | if (s->str == NULL) { |
| 63 | free(s); |
| 64 | Pthread_mutex_unlock(&intern_lk); |
| 65 | return NULL; |
| 66 | } |
| 67 | hash_add(interned_strings, s); |
| 68 | } |
| 69 | Pthread_mutex_unlock(&intern_lk); |
| 70 | return s; |
| 71 | } |
| 72 | |
| 73 | char *intern(const char *str) |
| 74 | { |
no test coverage detected