Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
proton-c-0.30.0
-
None
-
None
Description
Observation
Attempting to set a number between 2**31-1 and 2**62-1 as e.g. the message-id in Ruby 2.6.5 (and probably any other recent Ruby) results in the number mod 2**32.
Example (pry is a Ruby repl):
[1] pry(main)> m = Qpid::Proton::Message.new('body') => Message{body="body"} [2] pry(main)> m.id = 2**61 + 2**30 => 2305843010287435776 [3] pry(main)> m.id => 1073741824
Analysis
The SWIG bindings contain the following snippet (lines 115-123)
case T_FIXNUM: $1.type = PN_INT; $1.u.as_int = FIX2LONG($input); break; case T_BIGNUM: $1.type = PN_LONG; $1.u.as_long = NUM2LL($input); break;
Integer instances <= 2**62 - 1 will hit the T_FIXNUM case, as Ruby fixnums are 63 bits (1 bit is used to indicate they are fixnums to speed up arithmetic). Subsequently the number is converted into a 32 bit C long, discarding the 32 highest bits.
Further notes
The T_BIGNUM case takes care of correctly setting the value for numbers between 2**62 and 2**63-1, as those numbers can be converted into a 64 bit C long long
The T_BIGNUM case will fail for all larger numbers, with
RangeError: bignum too big to convert into `long long'
This is probably OK.
Note that the autoconversion of a pn_atom_t to an int or long is not useful for e.g. the message-id property, as it needs to be passed as a ulong (when numeric, disregarding the uuid, string, binary alternatives). Proton doesn't enforce this and naively setting message.id = 1 results in sending a message that is invalid with respect to the specification, as the type of the message-id will be an int.