void _nc_table_delete_64(table_t *tin, uint64_t key) { table_private_t *t; table_node_t *n, *p; uint32_t b; if (tin == NULL) return; t = (table_private_t *)tin; (void)osx_assumes(t->type == KEY_INT); b = hash_nkey(t->bucket_count, key); p = NULL; for (n = t->bucket[b]; n != NULL; n = n->next) { if ((n->key.uint64 != (uint64_t)-1) && (key == n->key.uint64)) { if (p == NULL) t->bucket[b] = n->next; else p->next = n->next; free(n); return; } p = n; } }
void _nc_table_delete(table_t *tin, const char *key) { table_private_t *t; table_node_t *n, *p; uint32_t b; if (tin == NULL) return; if (key == NULL) return; t = (table_private_t *)tin; (void)osx_assumes((t->type == KEY_STR_MINE) || (t->type == KEY_STR_SHARED)); b = hash_key(t->bucket_count, key); p = NULL; for (n = t->bucket[b]; n != NULL; n = n->next) { if ((n->key.string != NULL) && (!strcmp(key, n->key.string))) { if (p == NULL) t->bucket[b] = n->next; else p->next = n->next; if (t->type == KEY_STR_MINE) free(n->key.string); free(n); return; } p = n; } }
static void _nc_table_insert_type(table_t *tin, int type, char *key, const char *ckey, void *datum) { table_private_t *t; table_node_t *n; uint32_t b; if (tin == NULL) return; if ((key == NULL) && (ckey == NULL)) return; if (datum == NULL) return; t = (table_private_t *)tin; if (t->type == KEY_UNKNOWN) t->type = type; else (void)osx_assumes(t->type == type); n = (table_node_t *)malloc(sizeof(table_node_t)); if (key != NULL) { b = hash_key(t->bucket_count, key); n->key.string = key; } else { b = hash_key(t->bucket_count, ckey); n->key.const_string = ckey; } n->datum = datum; n->next = t->bucket[b]; t->bucket[b] = n; }
void _nc_table_insert_64(table_t *tin, uint64_t key, void *datum) { table_private_t *t; table_node_t *n; uint32_t b; if (tin == NULL) return; if (datum == NULL) return; t = (table_private_t *)tin; if (t->type == KEY_UNKNOWN) t->type = KEY_INT; else (void)osx_assumes(t->type == KEY_INT); b = hash_nkey(t->bucket_count, key); n = (table_node_t *)malloc(sizeof(table_node_t)); n->key.uint64 = key; n->datum = datum; n->next = t->bucket[b]; t->bucket[b] = n; }
// When Blocks or Block_byrefs hold objects their destroy helper routines call this entry point // to help dispose of the contents // Used initially only for __attribute__((NSObject)) marked pointers. void _Block_object_dispose(const void *object, const int flags) { switch (osx_assumes(flags & BLOCK_ALL_COPY_DISPOSE_FLAGS)) { case BLOCK_FIELD_IS_BYREF | BLOCK_FIELD_IS_WEAK: case BLOCK_FIELD_IS_BYREF: // get rid of the __block data structure held in a Block _Block_byref_release(object); break; case BLOCK_FIELD_IS_BLOCK: _Block_destroy(object); break; case BLOCK_FIELD_IS_OBJECT: _Block_release_object(object); break; case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT: case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK: case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT | BLOCK_FIELD_IS_WEAK: case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK | BLOCK_FIELD_IS_WEAK: break; default: break; } }
// // When Blocks or Block_byrefs hold objects then their copy routine helpers use this entry point // to do the assignment. // void _Block_object_assign(void *destAddr, const void *object, const int flags) { switch (osx_assumes(flags & BLOCK_ALL_COPY_DISPOSE_FLAGS)) { case BLOCK_FIELD_IS_OBJECT: /******* id object = ...; [^{ object; } copy]; ********/ _Block_retain_object(object); _Block_assign((void *)object, destAddr); break; case BLOCK_FIELD_IS_BLOCK: /******* void (^object)(void) = ...; [^{ object; } copy]; ********/ _Block_assign(_Block_copy_internal(object, false), destAddr); break; case BLOCK_FIELD_IS_BYREF | BLOCK_FIELD_IS_WEAK: case BLOCK_FIELD_IS_BYREF: /******* // copy the onstack __block container to the heap __block ... x; __weak __block ... x; [^{ x; } copy]; ********/ _Block_byref_assign_copy(destAddr, object, flags); break; case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT: case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK: /******* // copy the actual field held in the __block container __block id object; __block void (^object)(void); [^{ object; } copy]; ********/ // under manual retain release __block object/block variables are dangling _Block_assign((void *)object, destAddr); break; case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_OBJECT | BLOCK_FIELD_IS_WEAK: case BLOCK_BYREF_CALLER | BLOCK_FIELD_IS_BLOCK | BLOCK_FIELD_IS_WEAK: /******* // copy the actual field held in the __block container __weak __block id object; __weak __block void (^object)(void); [^{ object; } copy]; ********/ _Block_assign_weak(object, destAddr); break; default: break; } }