Пример #1
0
/* Add a protocol to the hashtable.  */
void
__objc_protocols_add_protocol (const char *name, struct objc_protocol *object)
{
  objc_mutex_lock (__protocols_hashtable_lock);

  /* If we find a protocol with the same name already in the
     hashtable, we do not need to add the new one, because it will be
     identical to it.  This in the reasonable assumption that two
     protocols with the same name are identical, which is expected in
     any sane program.  If we are really paranoid, we would compare
     the protocols and abort if they are not identical.
     Unfortunately, this would slow down the startup of all
     Objective-C programs while trying to catch a problem that has
     never been seen in practice, so we don't do it.  */
  if (! objc_hash_is_key_in_hash (__protocols_hashtable, name))
    objc_hash_add (&__protocols_hashtable, name, object);

  objc_mutex_unlock (__protocols_hashtable_lock);
}
Пример #2
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;
}