You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by mo...@apache.org on 2011/06/18 08:04:01 UTC
svn commit: r1137131 - in /thrift/trunk: lib/erl/src/thrift_protocol.erl
test/erl/Makefile test/erl/src/Thrift1151.thrift
test/erl/src/test_thrift_1151.erl
Author: molinaro
Date: Sat Jun 18 06:04:01 2011
New Revision: 1137131
URL: http://svn.apache.org/viewvc?rev=1137131&view=rev
Log:
THRIFT-1151 - catch some serialization errors
Added:
thrift/trunk/test/erl/src/Thrift1151.thrift
thrift/trunk/test/erl/src/test_thrift_1151.erl
Modified:
thrift/trunk/lib/erl/src/thrift_protocol.erl
thrift/trunk/test/erl/Makefile
Modified: thrift/trunk/lib/erl/src/thrift_protocol.erl
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/erl/src/thrift_protocol.erl?rev=1137131&r1=1137130&r2=1137131&view=diff
==============================================================================
--- thrift/trunk/lib/erl/src/thrift_protocol.erl (original)
+++ thrift/trunk/lib/erl/src/thrift_protocol.erl Sat Jun 18 06:04:01 2011
@@ -329,6 +329,12 @@ write(Proto, {{struct, {Module, Structur
element(1, Data) =:= StructureName ->
write(Proto, {Module:struct_info(StructureName), Data});
+write(_, {{struct, {Module, StructureName}}, Data})
+ when is_atom(Module),
+ is_atom(StructureName) ->
+ error(struct_unmatched, {{provided, element(1, Data)},
+ {expected, StructureName}});
+
write(Proto0, {{list, Type}, Data})
when is_list(Data) ->
{Proto1, ok} = write(Proto0,
Modified: thrift/trunk/test/erl/Makefile
URL: http://svn.apache.org/viewvc/thrift/trunk/test/erl/Makefile?rev=1137131&r1=1137130&r2=1137131&view=diff
==============================================================================
--- thrift/trunk/test/erl/Makefile (original)
+++ thrift/trunk/test/erl/Makefile Sat Jun 18 06:04:01 2011
@@ -29,7 +29,7 @@ SRCDIR=src
ALL_INCLUDEDIR=$(GEN_INCLUDEDIR) $(INCLUDEDIR) ../../lib/erl/include
INCLUDEFLAGS=$(patsubst %,-I%, ${ALL_INCLUDEDIR})
-MODULES = stress_server test_server test_client test_disklog test_membuffer
+MODULES = stress_server test_server test_client test_disklog test_membuffer test_thrift_1151
INCLUDES =
TARGETS = $(patsubst %,${TARGETDIR}/%.beam,${MODULES})
@@ -39,12 +39,14 @@ all: ${GEN_TARGETDIR}/ ${TARGETS}
TEST_RPCFILE = ../ThriftTest.thrift
STRESS_RPCFILE = ../StressTest.thrift
+THRIFT_1151_FILE = src/Thrift1151.thrift
THRIFT = ../../compiler/cpp/thrift
${GENDIR}/: ${RPCFILE}
rm -rf ${GENDIR}
${THRIFT} --gen erl ${TEST_RPCFILE}
${THRIFT} --gen erl ${STRESS_RPCFILE}
+ ${THRIFT} --gen erl ${THRIFT_1151_FILE}
mkdir -p ${GEN_INCLUDEDIR}
mkdir -p ${GEN_SRCDIR}
mkdir -p ${GEN_TARGETDIR}
Added: thrift/trunk/test/erl/src/Thrift1151.thrift
URL: http://svn.apache.org/viewvc/thrift/trunk/test/erl/src/Thrift1151.thrift?rev=1137131&view=auto
==============================================================================
--- thrift/trunk/test/erl/src/Thrift1151.thrift (added)
+++ thrift/trunk/test/erl/src/Thrift1151.thrift Sat Jun 18 06:04:01 2011
@@ -0,0 +1,3 @@
+struct StructA { 1: i16 x; }
+struct StructB { 1: i32 x; }
+struct StructC { 1: StructA x; }
Added: thrift/trunk/test/erl/src/test_thrift_1151.erl
URL: http://svn.apache.org/viewvc/thrift/trunk/test/erl/src/test_thrift_1151.erl?rev=1137131&view=auto
==============================================================================
--- thrift/trunk/test/erl/src/test_thrift_1151.erl (added)
+++ thrift/trunk/test/erl/src/test_thrift_1151.erl Sat Jun 18 06:04:01 2011
@@ -0,0 +1,19 @@
+-module(test_thrift_1151).
+
+-include("thrift1151_types.hrl").
+
+-export([t/0, t1/0]).
+
+t() ->
+ S1 = #structC{x=#structB{x=1}},
+ {ok, Transport} = thrift_memory_buffer:new(),
+ {ok, Protocol} = thrift_binary_protocol:new(Transport),
+ thrift_protocol:write(Protocol,
+ {{struct, element(2, thrift1151_types:struct_info('structC'))}, S1}).
+
+t1() ->
+ S2 = #structC{x=#structA{x="1"}},
+ {ok, Transport} = thrift_memory_buffer:new(),
+ {ok, Protocol} = thrift_binary_protocol:new(Transport),
+ thrift_protocol:write(Protocol,
+ {{struct, element(2, thrift1151_types:struct_info('structC'))}, S2}).