Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/yaz
authorDennis Schafroth <dennis@indexdata.com>
Mon, 10 May 2010 08:15:38 +0000 (10:15 +0200)
committerDennis Schafroth <dennis@indexdata.com>
Mon, 10 May 2010 08:15:38 +0000 (10:15 +0200)
12 files changed:
IDMETA
NEWS
configure.ac
debian/changelog
doc/zoom.xml
include/yaz/Makefile.am
include/yaz/shptr.h [new file with mode: 0644]
src/record_conv.c
src/zoom-c.c
src/zoom-p.h
test/Makefile.am
test/test_shared_ptr.c [new file with mode: 0644]

diff --git a/IDMETA b/IDMETA
index b281787..9ed38ff 100644 (file)
--- a/IDMETA
+++ b/IDMETA
@@ -1,2 +1,2 @@
 DEBIAN_DIST="squeeze etch lenny"
-UBUNTU_DIST="karmic jaunty intrepid hardy"
+UBUNTU_DIST="lucid karmic jaunty intrepid hardy"
diff --git a/NEWS b/NEWS
index 834323e..701e717 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+--- 4.0.7 2010/05/04
+
+record-conv: fix problem with at least one XSL conversion -
+due to probably incorrect usage of XML XSL documents.
+
 --- 4.0.6 2010/04/29
 
 Fix yaz-config for static mode and the use of SSL (gnutls).
index 4e3926f..ca20fbc 100644 (file)
@@ -1,7 +1,7 @@
 dnl This file is part of the YAZ toolkit.
 dnl Copyright (C) 1995-2010 Index Data
 AC_PREREQ([2.60])
-AC_INIT([yaz],[4.0.6],[yaz-help@indexdata.dk])
+AC_INIT([yaz],[4.0.7],[yaz-help@indexdata.dk])
 AC_CONFIG_SRCDIR([configure.ac])
 AC_CONFIG_AUX_DIR([config])
 AM_INIT_AUTOMAKE([1.9])
index a345610..d3a95b4 100644 (file)
@@ -1,3 +1,9 @@
+yaz (4.0.7-1indexdata) unstable; urgency=low
+
+  * Upstream.
+
+ -- Adam Dickmeiss <adam@indexdata.dk>  Tue, 04 May 2010 14:11:08 +0200
+
 yaz (4.0.6-1indexdata) unstable; urgency=low
 
   * Upstream.
index 55db631..10a3e19 100644 (file)
@@ -192,7 +192,15 @@ ZOOM_query_cql2rpn(ZOOM_query s, const char *str, ZOOM_connection conn)
         It's automatically set internally when connecting to a target.
        </entry><entry>none</entry></row>
       <row><entry>
-        proxy</entry><entry>Proxy host
+        proxy</entry><entry>Proxy host. If set, the logical host
+       is encoded in the otherInfo area of the Z39.50 Init PDU
+       with OID 1.2.840.10003.10.1000.81.1.
+       </entry><entry>none</entry></row>
+      <row><entry>
+        clientIP</entry><entry>Client IP. If set, is
+       encoded in the otherInfo area of a Z39.50 PDU with OID
+       1.2.840.10003.10.1000.81.3. Holds the original IP addreses
+       of a client. Is used of ZOOM is used in a gateway of some sort.
        </entry><entry>none</entry></row>
       <row><entry>
         async</entry><entry>If true (1) the connection operates in 
@@ -965,7 +973,7 @@ ZOOM_query_cql2rpn(ZOOM_query s, const char *str, ZOOM_connection conn)
       <row><entry>
         number</entry><entry>Number of Scan Terms requested in next scan.
         After scan it holds the actual number of terms returned.
-       </entry><entry>10</entry></row>
+       </entry><entry>20</entry></row>
       <row><entry>
         position</entry><entry>Preferred Position of term in response
         in next scan; actual position after completion of scan.
index 0016aa5..72e5896 100644 (file)
@@ -20,7 +20,7 @@ pkginclude_HEADERS= backend.h ccl.h ccl_xml.h cql.h rpn2cql.h comstack.h \
  z-univ.h z-oclcui.h zes-expi.h zes-exps.h zes-order.h zes-pquery.h \
  zes-psched.h zes-admin.h zes-pset.h zes-update.h zes-update0.h \
  zoom.h z-charneg.h charneg.h soap.h srw.h zgdu.h matchstr.h json.h \
- file_glob.h dirent.h thread_id.h gettimeofday.h
+ file_glob.h dirent.h thread_id.h gettimeofday.h shptr.h
 
 EXTRA_DIST = yaz-version.h.in
 
diff --git a/include/yaz/shptr.h b/include/yaz/shptr.h
new file mode 100644 (file)
index 0000000..b621b3d
--- /dev/null
@@ -0,0 +1,88 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data.
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of Index Data nor the names of its contributors
+ *       may be used to endorse or promote products derived from this
+ *       software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file shptr.h
+ * \brief Shared pointer macros
+ */
+
+#ifndef YAZ_SHARED_PTR_H
+#define YAZ_SHARED_PTR_H
+
+#include <yaz/xmalloc.h>
+#include <yaz/mutex.h>
+
+YAZ_BEGIN_CDECL
+
+#define YAZ_SHPTR_TYPE(type) \
+    struct type##_shptr \
+    {                          \
+    type ptr;                  \
+    int ref;                   \
+    YAZ_MUTEX mutex;           \
+    };  \
+    typedef struct type##_shptr *type##_shptr_t;
+
+#define YAZ_SHPTR_INIT(p,n) {                   \
+        p = xmalloc(sizeof(*p));                \
+        p->ptr = n;                             \
+        p->ref = 1;                             \
+        p->mutex = 0;  \
+        yaz_mutex_create(&p->mutex);            \
+    }
+
+#define YAZ_SHPTR_INC(p) {                      \
+        yaz_mutex_enter(p->mutex);              \
+        p->ref++;                               \
+        yaz_mutex_leave(p->mutex);              \
+    }
+
+#define YAZ_SHPTR_DEC(p, destroy)  {             \
+    yaz_mutex_enter(p->mutex);                   \
+    if (--p->ref == 0) {                         \
+        yaz_mutex_leave(p->mutex);               \
+        destroy(p->ptr);                         \
+        yaz_mutex_destroy(&p->mutex);            \
+        xfree(p);                                \
+        p = 0;                                   \
+    } else { \
+    yaz_mutex_leave(p->mutex); \
+    } \
+    }
+
+YAZ_END_CDECL
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+
index 695f088..9da5a44 100644 (file)
@@ -192,7 +192,9 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr)
                 wrbuf_printf(p->wr_error, " with path '%s'", p->path);
             return -1;
         }
-        xsp = xsltParseStylesheetDoc(xsp_doc);
+        /* need to copy this before passing it to the processor. It will
+           be encapsulated in the xsp and destroyed by xsltFreeStylesheet */
+        xsp = xsltParseStylesheetDoc(xmlCopyDoc(xsp_doc, 1));
         if (!xsp)
         {
             wrbuf_printf(p->wr_error, "Element: <xslt stylesheet=\"%s\"/>:"
@@ -207,14 +209,15 @@ static int conv_xslt(yaz_record_conv_t p, const xmlNode *ptr)
                          "EXSLT not supported"
 #endif
                          ")");
+            xmlFreeDoc(xsp_doc);
             return -1;
         }
         else
         {
             struct yaz_record_conv_rule *r = 
                 add_rule(p, YAZ_RECORD_CONV_RULE_XSLT);
-            r->u.xslt.xsp_doc = xmlCopyDoc(xsp_doc, 1);
-            xsltFreeStylesheet(xsp); /* will free xsp_doc */
+            r->u.xslt.xsp_doc = xsp_doc;
+            xsltFreeStylesheet(xsp);
         }
     }
     return 0;
@@ -532,7 +535,7 @@ static int yaz_record_conv_record_rule(yaz_record_conv_t p,
                     xmlChar *out_buf = 0;
                     int out_len;
 
-#if YAZ_HAVE_XSLTSAVERESULTTOSTRING
+#if HAVE_XSLTSAVERESULTTOSTRING
                     xsltSaveResultToString(&out_buf, &out_len, res, xsp);
 #else
                     xmlDocDumpFormatMemory (res, &out_buf, &out_len, 1);
index cc47d5a..4e2bea0 100644 (file)
 #include <yaz/copy_types.h>
 #include <yaz/snprintf.h>
 
+#include <yaz/shptr.h>
+
+#if SHPTR
+YAZ_SHPTR_TYPE(WRBUF)
+#endif
+
 static int log_api = 0;
 static int log_details = 0;
 
@@ -790,13 +796,18 @@ static zoom_ret do_write(ZOOM_connection c);
 ZOOM_API(void)
     ZOOM_connection_destroy(ZOOM_connection c)
 {
+#if ZOOM_RESULT_LISTS
     ZOOM_resultsets list;
+#else
+    ZOOM_resultset r;
+#endif
     if (!c)
         return;
     yaz_log(log_api, "%p ZOOM_connection_destroy", c);
     if (c->cs)
         cs_close(c->cs);
 
+#if ZOOM_RESULT_LISTS
     // Remove the connection's usage of resultsets
     list = c->resultsets;
     while (list) {
@@ -805,6 +816,10 @@ ZOOM_API(void)
         list = list->next;
         xfree(removed);
     }
+#else
+    for (r = c->resultsets; r; r = r->next)
+        r->connection = 0;
+#endif
 
     xfree(c->buf_in);
     xfree(c->addinfo);
@@ -870,6 +885,12 @@ ZOOM_resultset ZOOM_resultset_create(void)
     r->num_databaseNames = 0;
     r->mutex = 0;
     yaz_mutex_create(&r->mutex);
+#if SHPTR
+    {
+        WRBUF w = wrbuf_alloc();
+        YAZ_SHPTR_INIT(r->record_wrbuf, w);
+    }
+#endif
     return r;
 }
 
@@ -894,7 +915,9 @@ ZOOM_API(ZOOM_resultset)
     const char *cp;
     int start, count;
     const char *syntax, *elementSetName;
+#if ZOOM_RESULT_LISTS
     ZOOM_resultsets set;
+#endif
 
     yaz_log(log_api, "%p ZOOM_connection_search set %p query %p", c, r, q);
     r->r_sort_spec = q->sort_spec;
@@ -923,13 +946,17 @@ ZOOM_API(ZOOM_resultset)
     
     r->connection = c;
 
+#if ZOOM_RESULT_LISTS
     yaz_log(log_details, "%p ZOOM_connection_search: Adding new resultset (%p) to resultsets (%p) ", c, r, c->resultsets);
     set = xmalloc(sizeof(*set));
     ZOOM_resultset_addref(r);
     set->resultset = r;
     set->next = c->resultsets;
     c->resultsets = set;
-
+#else
+    r->next = c->resultsets;
+    c->resultsets = r;
+#endif
     if (c->host_port && c->proto == PROTO_HTTP)
     {
         if (!c->cs)
@@ -1027,8 +1054,15 @@ static void ZOOM_record_release(ZOOM_record rec)
 {
     if (!rec)
         return;
+
+#if SHPTR
+    if (rec->record_wrbuf)
+        YAZ_SHPTR_DEC(rec->record_wrbuf, wrbuf_destroy);
+#else
     if (rec->wrbuf)
         wrbuf_destroy(rec->wrbuf);
+#endif
+
 #if YAZ_HAVE_XML2
     if (rec->xml_mem)
         xmlFree(rec->xml_mem);
@@ -1069,14 +1103,36 @@ static void resultset_destroy(ZOOM_resultset r)
     if (r->refcount == 0)
     {
         yaz_mutex_leave(r->mutex);
+
         yaz_log(log_details, "%p ZOOM_connection resultset_destroy: Deleting resultset (%p) ", r->connection, r);
         ZOOM_resultset_cache_reset(r);
+#if ZOOM_RESULT_LISTS
+#else
+        if (r->connection)
+        {
+            /* remove ourselves from the resultsets in connection */
+            ZOOM_resultset *rp = &r->connection->resultsets;
+            while (1)
+            {
+                assert(*rp);   /* we must be in this list!! */
+                if (*rp == r)
+                {   /* OK, we're here - take us out of it */
+                    *rp = (*rp)->next;
+                    break;
+                }
+                rp = &(*rp)->next;
+            }
+        }
+#endif
         ZOOM_query_destroy(r->query);
         ZOOM_options_destroy(r->options);
         odr_destroy(r->odr);
         xfree(r->setname);
         xfree(r->schema);
         yaz_mutex_destroy(&r->mutex);
+#if SHPTR
+        YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy);
+#endif
         xfree(r);
     }
     else
@@ -1739,6 +1795,7 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c)
                result sets on the server. */
             for (ord = 1; ; ord++)
             {
+#if ZOOM_RESULT_LISTS
                 ZOOM_resultsets rsp;
                 sprintf(setname, "%d", ord);
                 for (rsp = c->resultsets; rsp; rsp = rsp->next)
@@ -1746,6 +1803,16 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c)
                         break;
                 if (!rsp)
                     break;
+#else
+                ZOOM_resultset rp;
+                sprintf(setname, "%d", ord);
+                for (rp = c->resultsets; rp; rp = rp->next)
+                    if (rp->setname && !strcmp(rp->setname, setname))
+                        break;
+                if (!rp)
+                    break;
+#endif
+
             }
             r->setname = xstrdup(setname);
             yaz_log(log_details, "%p ZOOM_connection_send_search: allocating "
@@ -1808,7 +1875,11 @@ ZOOM_API(ZOOM_record)
     nrec = (ZOOM_record) xmalloc(sizeof(*nrec));
     yaz_log(log_details, "ZOOM_record create");
     nrec->odr = odr_createmem(ODR_DECODE);
+#if SHPTR
+    nrec->record_wrbuf = 0;
+#else
     nrec->wrbuf = 0;
+#endif
 #if YAZ_HAVE_XML2
     nrec->xml_mem = 0;
     nrec->xml_size = 0;
@@ -1897,7 +1968,8 @@ static yaz_iconv_t iconv_create_charset(const char *record_charset)
     return cd;
 }
 
-static const char *return_marc_record(ZOOM_record rec, int marc_type,
+static const char *return_marc_record(ZOOM_record rec, WRBUF wrbuf,
+                                      int marc_type,
                                       int *len,
                                       const char *buf, int sz,
                                       const char *record_charset)
@@ -1909,14 +1981,11 @@ static const char *return_marc_record(ZOOM_record rec, int marc_type,
     if (cd)
         yaz_marc_iconv(mt, cd);
     yaz_marc_xml(mt, marc_type);
-    if (!rec->wrbuf)
-        rec->wrbuf = wrbuf_alloc();
-    wrbuf_rewind(rec->wrbuf);
-    if (yaz_marc_decode_wrbuf(mt, buf, sz, rec->wrbuf) > 0)
+    if (yaz_marc_decode_wrbuf(mt, buf, sz, wrbuf) > 0)
     {
         if (len)
-            *len = wrbuf_len(rec->wrbuf);
-        ret_string = wrbuf_cstr(rec->wrbuf);
+            *len = wrbuf_len(wrbuf);
+        ret_string = wrbuf_cstr(wrbuf);
     }
     yaz_marc_destroy(mt);
     if (cd)
@@ -1924,7 +1993,8 @@ static const char *return_marc_record(ZOOM_record rec, int marc_type,
     return ret_string;
 }
 
-static const char *return_opac_record(ZOOM_record rec, int marc_type,
+static const char *return_opac_record(ZOOM_record rec, WRBUF wrbuf,
+                                      int marc_type,
                                       int *len,
                                       Z_OPACRecord *opac_rec,
                                       const char *record_charset)
@@ -1936,21 +2006,18 @@ static const char *return_opac_record(ZOOM_record rec, int marc_type,
         yaz_marc_iconv(mt, cd);
     yaz_marc_xml(mt, marc_type);
 
-    if (!rec->wrbuf)
-        rec->wrbuf = wrbuf_alloc();
-    wrbuf_rewind(rec->wrbuf);
-
-    yaz_opac_decode_wrbuf(mt, opac_rec, rec->wrbuf);
+    yaz_opac_decode_wrbuf(mt, opac_rec, wrbuf);
     yaz_marc_destroy(mt);
 
     if (cd)
         yaz_iconv_close(cd);
     if (len)
-        *len = wrbuf_len(rec->wrbuf);
-    return wrbuf_cstr(rec->wrbuf);
+        *len = wrbuf_len(wrbuf);
+    return wrbuf_cstr(wrbuf);
 }
 
-static const char *return_string_record(ZOOM_record rec, int *len,
+static const char *return_string_record(ZOOM_record rec, WRBUF wrbuf,
+                                        int *len,
                                         const char *buf, int sz,
                                         const char *record_charset)
 {
@@ -1958,16 +2025,11 @@ static const char *return_string_record(ZOOM_record rec, int *len,
 
     if (cd)
     {
-        if (!rec->wrbuf)
-            rec->wrbuf = wrbuf_alloc();
-
-        wrbuf_rewind(rec->wrbuf);
+        wrbuf_iconv_write(wrbuf, cd, buf, sz);
+        wrbuf_iconv_reset(wrbuf, cd);
 
-        wrbuf_iconv_write(rec->wrbuf, cd, buf, sz);
-        wrbuf_iconv_reset(rec->wrbuf, cd);
-
-        buf = wrbuf_cstr(rec->wrbuf);
-        sz = wrbuf_len(rec->wrbuf);
+        buf = wrbuf_cstr(wrbuf);
+        sz = wrbuf_len(wrbuf);
         yaz_iconv_close(cd);
     }
     if (len)
@@ -1981,15 +2043,29 @@ static const char *return_record(ZOOM_record rec, int *len,
 {
     Z_External *r = (Z_External *) npr->u.databaseRecord;
     const Odr_oid *oid = r->direct_reference;
-    
+    WRBUF wrbuf;
+
+#if SHPTR
+    if (!rec->record_wrbuf)
+    {
+        WRBUF w = wrbuf_alloc();
+        YAZ_SHPTR_INIT(rec->record_wrbuf, w);
+    }
+    wrbuf = rec->record_wrbuf->ptr;
+#else
+    if (!rec->wrbuf)
+        rec->wrbuf = wrbuf_alloc();
+    wrbuf = rec->wrbuf;
+#endif
+    wrbuf_rewind(wrbuf);
     /* render bibliographic record .. */
     if (r->which == Z_External_OPAC)
     {
-        return return_opac_record(rec, marctype, len,
+        return return_opac_record(rec, wrbuf, marctype, len,
                                   r->u.opac, charset);
     }
     if (r->which == Z_External_sutrs)
-        return return_string_record(rec, len,
+        return return_string_record(rec, wrbuf, len,
                                     (char*) r->u.sutrs->buf,
                                     r->u.sutrs->len,
                                     charset);
@@ -1998,7 +2074,7 @@ static const char *return_record(ZOOM_record rec, int *len,
         if (yaz_oid_is_iso2709(oid))
         {
             const char *ret_buf = return_marc_record(
-                rec, marctype, len,
+                rec, wrbuf, marctype, len,
                 (const char *) r->u.octet_aligned->buf,
                 r->u.octet_aligned->len,
                 charset);
@@ -2008,20 +2084,17 @@ static const char *return_record(ZOOM_record rec, int *len,
             if (marctype != YAZ_MARC_ISO2709)
                 return 0;
         }
-        return return_string_record(rec, len,
+        return return_string_record(rec, wrbuf, len,
                                     (const char *) r->u.octet_aligned->buf,
                                     r->u.octet_aligned->len,
                                     charset);
     }
     else if (r->which == Z_External_grs1)
     {
-        if (!rec->wrbuf)
-            rec->wrbuf = wrbuf_alloc();
-        wrbuf_rewind(rec->wrbuf);
-        yaz_display_grs1(rec->wrbuf, r->u.grs1, 0);
-        return return_string_record(rec, len,
-                                    wrbuf_buf(rec->wrbuf),
-                                    wrbuf_len(rec->wrbuf),
+        yaz_display_grs1(wrbuf, r->u.grs1, 0);
+        return return_string_record(rec, wrbuf, len,
+                                    wrbuf_buf(wrbuf),
+                                    wrbuf_len(wrbuf),
                                     charset);
     }
     return 0;
@@ -2276,7 +2349,12 @@ static void record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr,
     {
         rc = (ZOOM_record_cache) odr_malloc(r->odr, sizeof(*rc));
         rc->rec.odr = 0;
+#if SHPTR
+        YAZ_SHPTR_INC(r->record_wrbuf);
+        rc->rec.record_wrbuf = r->record_wrbuf;
+#else
         rc->rec.wrbuf = 0;
+#endif
 #if YAZ_HAVE_XML2
         rc->rec.xml_mem = 0;
 #endif
@@ -2908,7 +2986,7 @@ static zoom_ret ZOOM_connection_send_scan(ZOOM_connection c)
     }
 
     *req->numberOfTermsRequested =
-        ZOOM_options_get_int(scan->options, "number", 10);
+        ZOOM_options_get_int(scan->options, "number", 20);
 
     req->preferredPositionInResponse =
         odr_intdup(c->odr_out,
index 3535221..844badf 100644 (file)
@@ -37,6 +37,9 @@
 #include <yaz/srw.h>
 #include <yaz/mutex.h>
 
+#define SHPTR 1
+#define ZOOM_RESULT_LISTS 0
+
 typedef struct ZOOM_Event_p *ZOOM_Event;
 
 struct ZOOM_query_p {
@@ -61,7 +64,9 @@ typedef struct ZOOM_task_p *ZOOM_task;
 #define STATE_CONNECTING 1
 #define STATE_ESTABLISHED 2
 
+#if ZOOM_RESULT_LISTS
 typedef struct ZOOM_resultsets_p *ZOOM_resultsets;
+#endif
 
 struct ZOOM_connection_p {
     enum oid_proto proto;
@@ -102,18 +107,23 @@ struct ZOOM_connection_p {
 
     ZOOM_task tasks;
     ZOOM_options options;
+#if ZOOM_RESULT_LISTS
     ZOOM_resultsets resultsets;
+#else
+    ZOOM_resultset resultsets;
+#endif
     ZOOM_Event m_queue_front;
     ZOOM_Event m_queue_back;
     zoom_sru_mode sru_mode;
     int no_redirects; /* 0 for no redirects. >0 for number of redirects */
 };
 
+#if ZOOM_RESULT_LISTS
 struct ZOOM_resultsets_p {
     ZOOM_resultset resultset;
     ZOOM_resultsets next;
 };
-
+#endif
 
 struct ZOOM_options_entry {
     char *name;
@@ -152,11 +162,23 @@ struct ZOOM_resultset_p {
     char **databaseNames;
     int num_databaseNames;
     YAZ_MUTEX mutex;
+#if SHPTR
+    struct WRBUF_shptr *record_wrbuf;
+#endif
+#if ZOOM_RESULT_LISTS
+#else
+    ZOOM_resultset next;
+#endif
 };
 
 struct ZOOM_record_p {
     ODR odr;
+#if SHPTR
+    struct WRBUF_shptr *record_wrbuf;
+#else
     WRBUF wrbuf;
+#endif
+
     Z_NamePlusRecord *npr;
     const char *schema;
 
index 762e372..da02fd6 100644 (file)
@@ -6,7 +6,7 @@ check_PROGRAMS = test_xmalloc test_iconv test_nmem test_matchstr test_wrbuf \
  test_soap1 test_soap2 test_odrstack test_log_thread test_xmlquery test_pquery \
  test_comstack test_filepath test_record_conv test_retrieval test_tpath \
  test_timing test_query_charset test_oid test_icu test_match_glob \
- test_rpn2cql test_json test_xml_include test_file_glob
+ test_rpn2cql test_json test_xml_include test_file_glob test_shared_ptr
 
 check_SCRIPTS = tstmarc.sh tstmarccol.sh tstcql2xcql.sh tstcql2pqf.sh tsticu.sh
 
@@ -80,3 +80,4 @@ test_rpn2cql_SOURCES = test_rpn2cql.c
 test_json_SOURCES = test_json.c
 test_xml_include_SOURCES = test_xml_include.c
 test_file_glob_SOURCES = test_file_glob.c
+test_shared_ptr_SOURCES = test_shared_ptr.c
diff --git a/test/test_shared_ptr.c b/test/test_shared_ptr.c
new file mode 100644 (file)
index 0000000..3502238
--- /dev/null
@@ -0,0 +1,60 @@
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2010 Index Data
+ * See the file LICENSE for details.
+ */
+
+/**
+ * \file test_shared_ptr.c
+ * \brief test shared pointer
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <yaz/shptr.h>
+#include <yaz/wrbuf.h>
+#include <yaz/test.h>
+
+YAZ_SHPTR_TYPE(WRBUF)
+
+static void test(void)
+{
+    WRBUF w = wrbuf_alloc();
+
+    WRBUF_shptr_t t = 0;
+    
+    YAZ_SHPTR_INIT(t, w);
+    YAZ_CHECK(t);
+
+    YAZ_SHPTR_INC(t);
+    YAZ_CHECK(t);
+
+    YAZ_SHPTR_DEC(t, wrbuf_destroy);
+    YAZ_CHECK(t);
+
+    YAZ_SHPTR_DEC(t, wrbuf_destroy);
+    YAZ_CHECK(!t);
+}
+
+int main (int argc, char **argv)
+{
+    YAZ_CHECK_INIT(argc, argv);
+    test();
+    YAZ_CHECK_TERM;
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+