]> granicus.if.org Git - libevent/commitdiff
Rename encode_int(64) to avoid polluting the global namespace.
authorNick Mathewson <nickm@torproject.org>
Mon, 20 Jul 2009 14:55:35 +0000 (14:55 +0000)
committerNick Mathewson <nickm@torproject.org>
Mon, 20 Jul 2009 14:55:35 +0000 (14:55 +0000)
They're now called evtag_encode_int(64).  The old names are available
as macros in event2/tag_compat.h.

Also, add unit tests for encode/decode_int64.

svn:r1365

ChangeLog
event.h
event_tagging.c
include/Makefile.am
include/event2/tag.h
include/event2/tag_compat.h [new file with mode: 0644]
test/regress.c

index 2ffe32d7f56161f86219b3f33e04828e516faa8d..83a3c5908941fd6f6e2a8cfca4f1718b654cb77d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,7 @@ Changes in 2.0.2-alpha:
  o Use AC_SEARCH_LIBS, not AC_CHECK_LIB to avoid needless library use.
  o Do not allow event_del(ev) to return while that event's callback is executing in another thread.  This fixes a nasty race condition.
  o event_get_supported_methods() now lists methods that have been disabled with the EVENT_NO* environment options.
+ o Rename encode_int[64] to evtag_encode_int[64] to avoid polluting the global namespace.  The old method names are still available as macros in event2/tag_compat.h.
 
 Changes in 2.0.1-alpha:
  o free minheap on event_base_free(); from Christopher Layne
diff --git a/event.h b/event.h
index b7d3b333d479eb3099780668ed1fa8b115e1f5ae..9139296c6f394ec8560ea2aab0d863aff493ecc9 100644 (file)
--- a/event.h
+++ b/event.h
@@ -194,6 +194,7 @@ typedef unsigned short u_short;
 #include <event2/bufferevent_struct.h>
 #include <event2/bufferevent_compat.h>
 #include <event2/tag.h>
+#include <event2/tag_compat.h>
 
 #ifdef __cplusplus
 }
index c18b93f252ae3720d43df0627320ed415a366d68..c5654d30c8024f9351f6c104ba4896cb0821f7bb 100644 (file)
@@ -68,6 +68,7 @@
 #include "util-internal.h"
 
 int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
+int evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf);
 int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t tag);
 int evtag_decode_tag(ev_uint32_t *ptag, struct evbuffer *evbuf);
 
@@ -123,7 +124,7 @@ encode_int64_internal(ev_uint8_t *data, ev_uint64_t number)
 }
 
 void
-encode_int(struct evbuffer *evbuf, ev_uint32_t number)
+evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number)
 {
        ev_uint8_t data[5];
        int len = encode_int_internal(data, number);
@@ -131,7 +132,7 @@ encode_int(struct evbuffer *evbuf, ev_uint32_t number)
 }
 
 void
-encode_int64(struct evbuffer *evbuf, ev_uint64_t number)
+evtag_encode_int64(struct evbuffer *evbuf, ev_uint64_t number)
 {
        ev_uint8_t data[9];
        int len = encode_int64_internal(data, number);
@@ -221,7 +222,7 @@ evtag_marshal(struct evbuffer *evbuf, ev_uint32_t tag,
     const void *data, ev_uint32_t len)
 {
        evtag_encode_tag(evbuf, tag);
-       encode_int(evbuf, len);
+       evtag_encode_int(evbuf, len);
        evbuffer_add(evbuf, (void *)data, len);
 }
 
@@ -230,7 +231,7 @@ evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag,
     struct evbuffer *data)
 {
        evtag_encode_tag(evbuf, tag);
-       encode_int(evbuf, evbuffer_get_length(data));
+       evtag_encode_int(evbuf, evbuffer_get_length(data));
        evbuffer_add_buffer(evbuf, data);
 }
 
@@ -242,7 +243,7 @@ evtag_marshal_int(struct evbuffer *evbuf, ev_uint32_t tag, ev_uint32_t integer)
        int len = encode_int_internal(data, integer);
 
        evtag_encode_tag(evbuf, tag);
-       encode_int(evbuf, len);
+       evtag_encode_int(evbuf, len);
        evbuffer_add(evbuf, data, len);
 }
 
@@ -254,7 +255,7 @@ evtag_marshal_int64(struct evbuffer *evbuf, ev_uint32_t tag,
        int len = encode_int64_internal(data, integer);
 
        evtag_encode_tag(evbuf, tag);
-       encode_int(evbuf, len);
+       evtag_encode_int(evbuf, len);
        evbuffer_add(evbuf, data, len);
 }
 
@@ -339,6 +340,16 @@ evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf)
        return (res == -1 ? -1 : 0);
 }
 
+int
+evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf)
+{
+       int res = decode_int64_internal(pnumber, evbuf, 0);
+       if (res != -1)
+               evbuffer_drain(evbuf, res);
+
+       return (res == -1 ? -1 : 0);
+}
+
 int
 evtag_peek(struct evbuffer *evbuf, ev_uint32_t *ptag)
 {
index 57f0c015700e2a47b6a7f49f157cdc526034af7d..529eff1f03f01becb3f126a94fce7665d472cd52 100644 (file)
@@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = foreign
 EXTRA_SRC = event2/buffer.h event2/buffer_compat.h \
        event2/thread.h event2/bufferevent.h event2/bufferevent_compat.h \
         event2/bufferevent_struct.h event2/event.h event2/event_compat.h \
-        event2/event_struct.h event2/tag.h event2/util.h \
+        event2/event_struct.h event2/tag.h event2/tag_compat.h event2/util.h \
        event2/http.h event2/http_struct.h event2/http_compat.h \
        event2/listener.h
 
@@ -14,7 +14,7 @@ nobase_include_HEADERS = \
        event2/thread.h event2/bufferevent.h \
        event2/bufferevent_compat.h \
         event2/bufferevent_struct.h event2/event.h event2/event_compat.h \
-        event2/event_struct.h event2/tag.h event2/util.h \
+        event2/event_struct.h event2/tag.h event2/tag_compat.h event2/util.h \
        event2/http.h event2/http_struct.h event2/http_compat.h \
        event2/rpc.h event2/rpc_struct.h event2/rpc_compat.h \
        event2/dns.h event2/dns_struct.h event2/dns_compat.h \
index 0f967e02f4f637ce27d225c9b12f7a6a4b4f38c4..ebed1a61ca3771d867cb47201c12655d2a78b6c2 100644 (file)
@@ -88,8 +88,8 @@ void evtag_marshal_buffer(struct evbuffer *evbuf, ev_uint32_t tag,
   @param evbuf evbuffer to store the encoded number
   @param number a 32-bit integer
  */
-void encode_int(struct evbuffer *evbuf, ev_uint32_t number);
-void encode_int64(struct evbuffer *evbuf, ev_uint64_t number);
+void evtag_encode_int(struct evbuffer *evbuf, ev_uint32_t number);
+void evtag_encode_int64(struct evbuffer *evbuf, ev_uint64_t number);
 
 void evtag_marshal_int(struct evbuffer *evbuf, ev_uint32_t tag,
     ev_uint32_t integer);
diff --git a/include/event2/tag_compat.h b/include/event2/tag_compat.h
new file mode 100644 (file)
index 0000000..4cb9f43
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
+ * Copyright (c) 2007-2009 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+#ifndef _EVENT2_TAG_COMPAT_H_
+#define _EVENT2_TAG_COMPAT_H_
+
+/** @file tag_compat.h
+
+    Obsolete/deprecated functions from tag.h; provided only for backwards
+    compatibility.
+ */
+
+#define encode_int(evbuf, number) evtag_encode_int((evbuf), (number))
+#define encode_int64(evbuf, number) evtag_encode_int64((evbuf), (number))
+
+#endif /* _EVENT2_TAG_H_ */
index 0d26eb011b7d9efe2796f7654ffe9e2f6db2b272..64903b3e7eed14f1d06e1847a0155ce5caeb11a7 100644 (file)
@@ -1270,6 +1270,7 @@ test_multiple_events_for_same_fd(void)
 }
 
 int evtag_decode_int(ev_uint32_t *pnumber, struct evbuffer *evbuf);
+int evtag_decode_int64(ev_uint64_t *pnumber, struct evbuffer *evbuf);
 int evtag_encode_tag(struct evbuffer *evbuf, ev_uint32_t number);
 int evtag_decode_tag(ev_uint32_t *pnumber, struct evbuffer *evbuf);
 
@@ -1326,23 +1327,30 @@ evtag_int_test(void)
                0xaf0, 0x1000, 0x1, 0xdeadbeef, 0x00, 0xbef000
        };
        ev_uint32_t integer;
+       ev_uint64_t big_int;
        int i;
 
        for (i = 0; i < TEST_MAX_INT; i++) {
                int oldlen, newlen;
                oldlen = EVBUFFER_LENGTH(tmp);
-               encode_int(tmp, integers[i]);
-               newlen = EVBUFFER_LENGTH(tmp);
-                TT_BLATHER(("encoded 0x%08x with %d bytes",
+               evtag_encode_int(tmp, integers[i]);
+                newlen = EVBUFFER_LENGTH(tmp);
+               TT_BLATHER(("encoded 0x%08x with %d bytes",
                         (unsigned)integers[i], newlen - oldlen));
+               big_int = integers[i];
+               big_int *= 1000000000; /* 1 billion */
+               evtag_encode_int64(tmp, big_int);
        }
 
        for (i = 0; i < TEST_MAX_INT; i++) {
-                tt_assert(evtag_decode_int(&integer, tmp) != -1);
+                tt_int_op(evtag_decode_int(&integer, tmp), !=, -1);
                 tt_uint_op(integer, ==, integers[i]);
+               tt_int_op(evtag_decode_int64(&big_int, tmp), !=, -1);
+               tt_assert((big_int / 1000000000) == integers[i]);
        }
 
         tt_uint_op(EVBUFFER_LENGTH(tmp), ==, 0);
+
 end:
        evbuffer_free(tmp);
 }