+/** macro clone_z_type copies a given ASN.1 type */
+#define clone_z_type(x) \
+Z_##x *yaz_clone_z_##x(Z_##x *q, NMEM nmem_out) \
+{ \
+ Z_##x *q1 = 0; \
+ ODR enc = odr_createmem(ODR_ENCODE); \
+ ODR dec = odr_createmem(ODR_DECODE); \
+ if (z_##x(enc, &q, 0, 0)) \
+ { \
+ int len; \
+ char *buf = odr_getbuf(enc, &len, 0); \
+ if (buf) \
+ { \
+ odr_setbuf(dec, buf, len, 0); \
+ z_##x(dec, &q1, 0, 0); \
+ nmem_transfer(nmem_out, dec->mem); \
+ } \
+ } \
+ odr_destroy(enc); \
+ odr_destroy(dec); \
+ return q1; \
+}
+
+clone_z_type(NamePlusRecord)
+clone_z_type(RPNQuery)
+clone_z_type(Query)
+clone_z_type(RecordComposition)
+