Esempio n. 1
0
void __objc_init_selector_tables (void)
{
  __objc_selector_array = sarray_new (SELECTOR_HASH_SIZE, 0);
  __objc_selector_names = sarray_new (SELECTOR_HASH_SIZE, 0);
  __objc_selector_hash
    = objc_hash_new (SELECTOR_HASH_SIZE,
		     (hash_func_type) objc_hash_string,
		     (compare_func_type) objc_compare_strings);
}  
Esempio n. 2
0
/* Called at startup by init.c.  */
void
__objc_protocols_init (void)
{
  __protocols_hashtable_lock = objc_mutex_allocate ();

  /* The keys in the table are strings, and the values are Protocol
     objects.  */
  __protocols_hashtable = objc_hash_new (64, (hash_func_type) objc_hash_string,
					 (compare_func_type) objc_compare_strings);
}
Esempio n. 3
0
int registerStruct(const char *fileName) {
	structInfoMap = objc_hash_new((unsigned int) 128, intHashFuncType, intCompareFuncType);
	int fileSize;
	char *base;
	char *cursor;
	FILE *fp = fopen(fileName, "r");
	if (fp == NULL) {
		printf("Can't open file: %s.", fileName);
		return -1;
	}

	fseek(fp, 0, SEEK_END);
	fileSize = ftell(fp);
	base = malloc(fileSize + 1);
	if (base == NULL) {
		printf("The file %s is too big", fileName);
		fclose(fp);
		exit(0);
	}
	fseek(fp, 0, SEEK_SET);
	fileSize = fread(base, 1, fileSize, fp);
	fclose(fp);

	base[fileSize] = -1;
	cursor = base;
	structFieldInfo *sfi;
	array *value;
	int sfiSize = sizeof(structFieldInfo);
	char *start;
	char c[1024];
	int *key;
	while (*cursor != -1) {
		value = (array*) malloc(sizeof(array));
		value->byteLength = 0;
		value->data = NULL;

		sfi = malloc(sfiSize);
		start = cursor;
		cursor = readNext(cursor);
		sfi->fieldName = malloc(cursor - start + 1);
		memcpy(sfi->fieldName, start, cursor - start);
		sfi->fieldName[cursor - start] = '\0';

		start = ++cursor;
		cursor = readNext(cursor);
		memcpy(c, start, cursor - start);
		c[cursor - start] = '\0';
		sfi->typeId = atoi(c);
		key = malloc(sizeof(int));
		*key = sfi->typeId;

		start = ++cursor;
		cursor = readNext(cursor);
		memcpy(c, start, cursor - start);
		c[cursor - start] = '\0';
		sfi->offset = atoi(c);

		++cursor;
		sfi->isPointe = *cursor & 1;
		++cursor;
		byteArrayPutData(value, sfi, sfiSize);
		++cursor;
		while (*cursor != -1 && *cursor != '\n') {
			sfi = malloc(sfiSize);
			start = cursor;
			cursor = readNext(cursor);
			sfi->fieldName = malloc(cursor - start + 1);
			memcpy(sfi->fieldName, start, cursor - start);
			sfi->fieldName[cursor - start] = '\0';

			start = ++cursor;
			cursor = readNext(cursor);
			memcpy(c, start, cursor - start);
			c[cursor - start] = '\0';
			sfi->typeId = GetTypeId(c);

			start = ++cursor;
			cursor = readNext(cursor);

			start = ++cursor;
			cursor = readNext(cursor);
			memcpy(c, start, cursor - start);
			c[cursor - start] = '\0';
			sfi->offset = atoi(c);

			++cursor;
			sfi->isPointe = *cursor & 1;
			++cursor;

			if (sfi->typeId == SERIALIZE_CHAR_N && sfi->isPointe) {
				sfi->typeId = SERIALIZE_STRING_N;
			}
			if (sfi->typeId == SERIALIZE_MAP_N) {
				sfi->isPointe = 1;
			}

			byteArrayPutData(value, sfi, sfiSize);
			++cursor;
		}
		objc_hash_add(&structInfoMap, key, value);
		++cursor;
	}
	free(base);
	return 0;
}