static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *ptr_map)
{
	HashTable *pparams;
	sdlParamPtr tmp, pparam;
	sdlTypePtr ptype;
	encodePtr penc;
	zend_string *key;

	pparams = malloc(sizeof(HashTable));
	zend_hash_init(pparams, zend_hash_num_elements(params), NULL, delete_parameter_persistent, 1);

	ZEND_HASH_FOREACH_STR_KEY_PTR(params, key, tmp) {
		pparam = malloc(sizeof(sdlParam));
		memset(pparam, 0, sizeof(sdlParam));
		*pparam = *tmp;

		if (pparam->paramName) {
			pparam->paramName = strdup(pparam->paramName);
		}

		if (pparam->encode && pparam->encode->details.sdl_type) {
			if ((penc = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->encode, sizeof(encodePtr))) == NULL) {
				assert(0);
			}
			pparam->encode = penc;
		}
		if (pparam->element) {
			if ((ptype = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->element, sizeof(sdlTypePtr))) == NULL) {
				assert(0);
			}
			pparam->element = ptype;
		}

		if (key) {
			/* We have to duplicate key emalloc->malloc */
			zend_hash_str_add_ptr(pparams, ZSTR_VAL(key), ZSTR_LEN(key), pparam);
		} else {
			zend_hash_next_index_insert_ptr(pparams, pparam);
		}
	} ZEND_HASH_FOREACH_END();

	return pparams;
}
static HashTable* make_persistent_sdl_parameters(HashTable *params, HashTable *ptr_map)
{
	HashTable *pparams;
	sdlParamPtr tmp, pparam;
	sdlTypePtr ptype;
	encodePtr penc;
	zend_string *key;

	pparams = malloc(sizeof(HashTable));
	zend_hash_init(pparams, zend_hash_num_elements(params), NULL, delete_parameter_persistent, 1);

	ZEND_HASH_FOREACH_STR_KEY_PTR(params, key, tmp) {
		pparam = malloc(sizeof(sdlParam));
		memset(pparam, 0, sizeof(sdlParam));
		*pparam = *tmp;

		if (pparam->paramName) {
			pparam->paramName = strdup(pparam->paramName);
		}

		if (pparam->encode && pparam->encode->details.sdl_type) {
			if ((penc = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->encode, sizeof(encodePtr))) == NULL) {
				assert(0);
			}
			pparam->encode = penc;
		}
		if (pparam->element) {
			if ((ptype = zend_hash_str_find_ptr(ptr_map, (char*)&pparam->element, sizeof(sdlTypePtr))) == NULL) {
				assert(0);
			}
			pparam->element = ptype;
		}

		if (key) {
			 
			zend_hash_str_add_ptr(pparams, ZSTR_VAL(key), ZSTR_LEN(key), pparam);
		} else {
			zend_hash_next_index_insert_ptr(pparams, pparam);
		}
	} ZEND_HASH_FOREACH_END();

	return pparams;
}