summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Joubert <emile@rabbitmq.com>2011-10-19 12:58:12 +0100
committerEmile Joubert <emile@rabbitmq.com>2011-10-19 12:58:12 +0100
commit2fca18856246f66085d0bcab520209703a0e5e9b (patch)
treeb3b122e870762893c43299a6a3a792fa3414ccf1
parent5675e074ad96c56e8a178cecbbdca3ddf5817d8d (diff)
downloadrabbitmq-server-2fca18856246f66085d0bcab520209703a0e5e9b.tar.gz
Perform semantic equivalence test
-rw-r--r--src/rabbit_misc.erl26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl
index a9b15af8..1bfd1baf 100644
--- a/src/rabbit_misc.erl
+++ b/src/rabbit_misc.erl
@@ -236,18 +236,32 @@ protocol_error(#amqp_error{} = Error) ->
not_found(R) -> protocol_error(not_found, "no ~s", [rs(R)]).
+type_class(byte) -> int_class;
+type_class(short) -> int_class;
+type_class(signedint) -> int_class;
+type_class(long) -> int_class;
+type_class(decimal) -> int_class;
+type_class(float) -> float_class;
+type_class(double) -> float_class;
+type_class(Other) -> Other.
+
assert_args_equivalence(Orig, New, Name, Keys) ->
[assert_args_equivalence1(Orig, New, Name, Key) || Key <- Keys],
ok.
assert_args_equivalence1(Orig, New, Name, Key) ->
case {table_lookup(Orig, Key), table_lookup(New, Key)} of
- {Same, Same} -> ok;
- {Orig1, New1} -> protocol_error(
- precondition_failed,
- "inequivalent arg '~s' for ~s: "
- "received ~s but current is ~s",
- [Key, rs(Name), val(New1), val(Orig1)])
+ {Same, Same} ->
+ ok;
+ {{Type1, OrigVal1} = Orig1, {Type2, NewVal1} = New1} ->
+ case type_class(Type1) == type_class(Type2) andalso
+ OrigVal1 == NewVal1 of
+ true -> ok;
+ false -> protocol_error(precondition_failed, "inequivalent arg"
+ " '~s' for ~s: received ~s but current"
+ " is ~s",
+ [Key, rs(Name), val(New1), val(Orig1)])
+ end
end.
val(undefined) ->