+static int apply_set_converter(void *p TSRMLS_DC, int argc, va_list argv, zend_hash_key *key)
+{
+ zval *tmp, **zoid = p, **zcnv = va_arg(argv, zval **);
+ HashTable *converters = va_arg(argv, HashTable *);
+
+ tmp = *zoid;
+ convert_to_long_ex(&tmp);
+ Z_ADDREF_PP(zcnv);
+ zend_hash_index_update(converters, Z_LVAL_P(tmp), zcnv, sizeof(zval *), NULL);
+ if (tmp != *zoid) {
+ zval_ptr_dtor(&tmp);
+ }
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_pqconn_set_converter, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, converter, pq\\ConverterInterface, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(pqconn, setConverter) {
+ STATUS rv;
+ zend_error_handling zeh;
+ zval *zcnv;
+
+ zend_replace_error_handling(EH_THROW, exce(EX_INVALID_ARGUMENT), &zeh TSRMLS_CC);
+ rv = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zcnv, php_pqconv_class_entry);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (SUCCESS == rv) {
+ php_pqconn_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (!obj->intern) {
+ throw_exce(EX_UNINITIALIZED TSRMLS_CC, "pq\\Connection not initialized");
+ } else {
+ zval *tmp, *zoids = NULL;
+
+ zend_call_method_with_0_params(&zcnv, NULL, NULL, "converttypes", &zoids);
+ tmp = zoids;
+ convert_to_array_ex(&zoids);
+ zend_hash_apply_with_arguments(Z_ARRVAL_P(zoids) TSRMLS_CC, apply_set_converter, 2, &zcnv, &obj->intern->converters);
+ if (tmp != zoids) {
+ zval_ptr_dtor(&tmp);
+ }
+ zval_ptr_dtor(&zoids);
+ }
+ }
+}
+