Exemplo n.º 1
0
hashmap_t*
hashmap_allocate(size_t buckets, size_t bucketsize) {
	hashmap_t* map;

	if (buckets < HASHMAP_MINBUCKETS)
		buckets = HASHMAP_MINBUCKETS;
	if (bucketsize < HASHMAP_MINBUCKETSIZE)
		bucketsize = HASHMAP_MINBUCKETSIZE;

	map = memory_allocate(0, sizeof(hashmap_t) + sizeof(hashmap_node_t*) * buckets, 0,
	                      MEMORY_PERSISTENT);

	hashmap_initialize(map, buckets, bucketsize);

	return map;
}
Exemplo n.º 2
0
int
lua_compile(const uuid_t uuid, uint64_t platform, resource_source_t* source,
            const uint256_t source_hash, const char* type, size_t type_length) {
	int result = 0;
	uint64_t* subplatforms = 0;
	size_t iplat, psize;
	hashmap_fixed_t fixedmap;
	hashmap_t* map = (hashmap_t*)&fixedmap;
	hash_t resource_type_hash;

	resource_type_hash = hash(type, type_length);

	if (resource_type_hash != HASH_LUA)
		return -1;

	array_push(subplatforms, platform);

	hashmap_initialize(map, sizeof(fixedmap.bucket) / sizeof(fixedmap.bucket[0]), 8);
	resource_source_map_all(source, map, false);
	resource_source_map_reduce(source, map, &subplatforms, resource_source_platform_reduce);
	resource_source_map_clear(map);

	for (iplat = 1, psize = array_size(subplatforms); (iplat != psize) && (result == 0); ++iplat) {
		void* compiled_blob = 0;
		size_t compiled_size = 0;
		stream_t* stream;
		uint64_t subplatform = subplatforms[iplat];

		resource_change_t* sourcechange = resource_source_get(source, HASH_SOURCE, subplatform);
		if (sourcechange && (sourcechange->flags & RESOURCE_SOURCEFLAG_BLOB)) {
			compiled_size = sourcechange->value.blob.size;
			compiled_blob = memory_allocate(HASH_RESOURCE, compiled_size, 0, MEMORY_PERSISTENT);
			if (!resource_source_read_blob(uuid, HASH_SOURCE, subplatform, sourcechange->value.blob.checksum,
			                               compiled_blob, compiled_size)) {
				memory_deallocate(compiled_blob);
				compiled_blob = 0;
				compiled_size = 0;
			}
		}

		if (compiled_size <= 0)
			continue;

		stream = resource_local_create_static(uuid, subplatform);
		if (stream) {
			const uint32_t version = 1;
			resource_header_t header = {
				.type = resource_type_hash,
				.version = version,
				.source_hash = source_hash
			};
			resource_stream_write_header(stream, header);
			stream_deallocate(stream);

			if (compiled_size > 0) {
				stream = resource_local_create_dynamic(uuid, subplatform);
				if (stream) {
					stream_write_uint32(stream, version);
					stream_write_uint64(stream, compiled_size);
					stream_write(stream, compiled_blob, compiled_size);
					stream_deallocate(stream);
				}
				else {
					log_errorf(HASH_RESOURCE, ERROR_SYSTEM_CALL_FAIL,
					           STRING_CONST("Unable to create dynamic resource stream"));
					result = -1;
				}
			}
		}
		else {
			log_errorf(HASH_RESOURCE, ERROR_SYSTEM_CALL_FAIL,
			           STRING_CONST("Unable to create static resource stream"));
			result = -1;
		}

		memory_deallocate(compiled_blob);
	}