qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: PROTON-807: Fix incorrect decoding of small long values.
Date Wed, 28 Jan 2015 17:18:07 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master aee6cbffa -> 249685a8c


PROTON-807: Fix incorrect decoding of small long values.

codec/decoder.c: Was treating signed small long values as unsigned.
proton-j/src/main/resources/ccodec.py: Added missing byte operations, fix ulong decoeing.
tests/python/proton_tests/codec.py: Test all integer types, positive, negative and min/max.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/249685a8
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/249685a8
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/249685a8

Branch: refs/heads/master
Commit: 249685a8cb675ab6fc16b14828fac2da949c9510
Parents: aee6cbf
Author: Alan Conway <aconway@redhat.com>
Authored: Wed Jan 28 10:17:07 2015 -0500
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Jan 28 12:16:10 2015 -0500

----------------------------------------------------------------------
 proton-c/src/codec/decoder.c          |  8 ++++----
 proton-c/src/codec/encoder.c          |  1 +
 proton-j/src/main/resources/ccodec.py | 15 ++++++++++++++-
 tests/python/proton_tests/codec.py    | 27 +++++++++++++++++++++++----
 4 files changed, 42 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/249685a8/proton-c/src/codec/decoder.c
----------------------------------------------------------------------
diff --git a/proton-c/src/codec/decoder.c b/proton-c/src/codec/decoder.c
index 2bd4ecc..3d4a09a 100644
--- a/proton-c/src/codec/decoder.c
+++ b/proton-c/src/codec/decoder.c
@@ -137,9 +137,9 @@ static inline pn_type_t pn_code2type(uint8_t code)
     return PN_SHORT;
   case PNE_UINT0:
   case PNE_SMALLUINT:
-  case PNE_SMALLINT:
   case PNE_UINT:
     return PN_UINT;
+  case PNE_SMALLINT:
   case PNE_INT:
     return PN_INT;
   case PNE_UTF32:
@@ -147,6 +147,7 @@ static inline pn_type_t pn_code2type(uint8_t code)
   case PNE_FLOAT:
     return PN_FLOAT;
   case PNE_LONG:
+  case PNE_SMALLLONG:
     return PN_LONG;
   case PNE_MS64:
     return PN_TIMESTAMP;
@@ -162,7 +163,6 @@ static inline pn_type_t pn_code2type(uint8_t code)
     return PN_UUID;
   case PNE_ULONG0:
   case PNE_SMALLULONG:
-  case PNE_SMALLLONG:
   case PNE_ULONG:
     return PN_ULONG;
   case PNE_VBIN8:
@@ -246,7 +246,7 @@ int pn_decoder_decode_value(pn_decoder_t *decoder, pn_data_t *data, uint8_t
code
     break;
   case PNE_SMALLINT:
     if (!pn_decoder_remaining(decoder)) return PN_UNDERFLOW;
-    err = pn_data_put_int(data, pn_decoder_readf8(decoder));
+    err = pn_data_put_int(data, (int8_t)pn_decoder_readf8(decoder));
     break;
   case PNE_INT:
     if (pn_decoder_remaining(decoder) < 4) return PN_UNDERFLOW;
@@ -297,7 +297,7 @@ int pn_decoder_decode_value(pn_decoder_t *decoder, pn_data_t *data, uint8_t
code
     break;
   case PNE_SMALLLONG:
     if (!pn_decoder_remaining(decoder)) return PN_UNDERFLOW;
-    err = pn_data_put_long(data, pn_decoder_readf8(decoder));
+    err = pn_data_put_long(data, (int8_t)pn_decoder_readf8(decoder));
     break;
   case PNE_DECIMAL128:
     if (pn_decoder_remaining(decoder) < 16) return PN_UNDERFLOW;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/249685a8/proton-c/src/codec/encoder.c
----------------------------------------------------------------------
diff --git a/proton-c/src/codec/encoder.c b/proton-c/src/codec/encoder.c
index 4a32183..2496f09 100644
--- a/proton-c/src/codec/encoder.c
+++ b/proton-c/src/codec/encoder.c
@@ -296,6 +296,7 @@ static int pni_encoder_enter(void *ctx, pn_data_t *data, pni_node_t *node)
   case PNE_ULONG: return pn_encoder_writef64(encoder, atom->u.as_ulong);
   case PNE_SMALLULONG: return pn_encoder_writef8(encoder, atom->u.as_ulong);
   case PNE_LONG: return pn_encoder_writef64(encoder, atom->u.as_long);
+  case PNE_SMALLLONG: return pn_encoder_writef8(encoder, atom->u.as_long);
   case PNE_MS64: return pn_encoder_writef64(encoder, atom->u.as_timestamp);
   case PNE_FLOAT: c.f = atom->u.as_float; return pn_encoder_writef32(encoder, c.i);
   case PNE_DOUBLE: c.d = atom->u.as_double; return pn_encoder_writef64(encoder, c.l);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/249685a8/proton-j/src/main/resources/ccodec.py
----------------------------------------------------------------------
diff --git a/proton-j/src/main/resources/ccodec.py b/proton-j/src/main/resources/ccodec.py
index e3549be..02cecc9 100644
--- a/proton-j/src/main/resources/ccodec.py
+++ b/proton-j/src/main/resources/ccodec.py
@@ -61,6 +61,7 @@ def DATA_TYPES(jtype, ptype):
 
 DATA_TYPES(DataType.NULL, PN_NULL)
 DATA_TYPES(DataType.BOOL, PN_BOOL)
+DATA_TYPES(DataType.BYTE, PN_BYTE)
 DATA_TYPES(DataType.UBYTE, PN_UBYTE)
 DATA_TYPES(DataType.USHORT, PN_USHORT)
 DATA_TYPES(DataType.UINT, PN_UINT)
@@ -98,6 +99,13 @@ def pn_data_put_bool(data, b):
 def pn_data_get_bool(data):
   return data.getBoolean()
 
+def pn_data_get_byte(data):
+  return data.getByte()
+
+def pn_data_put_byte(data, u):
+  data.putByte(u)
+  return 0
+
 def pn_data_get_ubyte(data):
   return data.getUnsignedByte().longValue()
 
@@ -123,8 +131,13 @@ def pn_data_put_ulong(data, u):
   data.putUnsignedLong(UnsignedLong.valueOf(u))
   return 0
 
+BITS_64 = 2**64 - 1;
+
 def pn_data_get_ulong(data):
-  return data.getUnsignedLong().longValue()
+  value =  data.getUnsignedLong().longValue()
+  if value < 0:
+    return value & BITS_64;
+  return value
 
 def pn_data_get_short(data):
   return data.getShort()

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/249685a8/tests/python/proton_tests/codec.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/codec.py b/tests/python/proton_tests/codec.py
index 46d5d46..661a1a9 100644
--- a/tests/python/proton_tests/codec.py
+++ b/tests/python/proton_tests/codec.py
@@ -17,7 +17,7 @@
 # under the License.
 #
 
-import os, common
+import os, common, sys
 from proton import *
 try:
   from uuid import uuid4
@@ -182,7 +182,11 @@ class DataTest(Test):
     getter = getattr(self.data, "get_%s" % dtype)
 
     for v in values:
-      putter(v)
+      try:
+        putter(v)
+      except Exception, e:
+        etype, value, trace = sys.exc_info()
+        raise etype, "Testing %s: %s" % (v, value), trace
       gotten = getter()
       assert eq(gotten, v), (gotten, v)
 
@@ -209,8 +213,23 @@ class DataTest(Test):
       gotten = cgetter()
       assert eq(gotten, v), (gotten, v)
 
-  def testInt(self):
-    self._test("int", 1, 2, 3, -1, -2, -3)
+  def _test_int(self, dtype, bits, signed=True):
+    """Test a few basic integers and the min/max"""
+    values = [0, 1, 2, 3, 42]
+    if signed:
+      max = 2**(bits-1)-1
+      values += [-i for i in values] + [-2**(bits-1)]
+    else:
+      max = 2**(bits)-1
+    values.append(max)
+    self._test(dtype, *values)
+
+  def testByte(self): self._test_int("byte", 8)
+  def testUbyte(self): self._test_int("ubyte", 8, signed=False)
+  def testInt(self): self._test_int("int", 32)
+  def testUint(self): self._test_int("uint", 32, signed=False)
+  def testLong(self): self._test_int("long", 64)
+  def testUlong(self): self._test_int("ulong", 64, signed=False)
 
   def testString(self):
     self._test("string", "one", "two", "three", "this is a test", "")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message