THRIFT-125. OCaml libraries don't compile with 32-bit ocaml
Patch: Iain Proctor and John Bilings
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1058270 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/ocaml/src/TBinaryProtocol.ml b/lib/ocaml/src/TBinaryProtocol.ml
index a06cc9a..6d7500e 100644
--- a/lib/ocaml/src/TBinaryProtocol.ml
+++ b/lib/ocaml/src/TBinaryProtocol.ml
@@ -22,6 +22,7 @@
module P = Protocol
let get_byte i b = 255 land (i lsr (8*b))
+let get_byte32 i b = 255 land (Int32.to_int (Int32.shift_right i (8*b)))
let get_byte64 i b = 255 land (Int64.to_int (Int64.shift_right i (8*b)))
@@ -35,7 +36,7 @@
for i=0 to (n-1) do
s:= Int32.logor !s (Int32.shift_left (Int32.of_int (int_of_char b.[i])) (8*(n-1-i)))
done;
- Int32.to_int (Int32.shift_right (Int32.shift_left !s sb) sb)
+ Int32.shift_right (Int32.shift_left !s sb) sb
let comp_int64 b n =
let s = ref 0L in
@@ -44,8 +45,8 @@
done;
!s
-let version_mask = 0xffff0000
-let version_1 = 0x80010000
+let version_mask = 0xffff0000l
+let version_1 = 0x80010000l
class t trans =
object (self)
@@ -63,7 +64,7 @@
ibyte.[0] <- char_of_int (gb 1);
trans#write ibyte 0 2
method writeI32 i =
- let gb = get_byte i in
+ let gb = get_byte32 i in
for i=0 to 3 do
ibyte.[3-i] <- char_of_int (gb i)
done;
@@ -78,13 +79,13 @@
self#writeI64 (Int64.bits_of_float d)
method writeString s=
let n = String.length s in
- self#writeI32(n);
+ self#writeI32 (Int32.of_int n);
trans#write s 0 n
method writeBinary a = self#writeString a
method writeMessageBegin (n,t,s) =
- self#writeI32 (version_1 lor (P.message_type_to_i t));
+ self#writeI32 (Int32.logor version_1 (Int32.of_int (P.message_type_to_i t)));
self#writeString n;
- self#writeI32 s
+ self#writeI32 (Int32.of_int s)
method writeMessageEnd = ()
method writeStructBegin s = ()
method writeStructEnd = ()
@@ -93,26 +94,26 @@
self#writeI16 i
method writeFieldEnd = ()
method writeFieldStop =
- self#writeByte (tv (Protocol.T_STOP))
+ self#writeByte (tv (P.T_STOP))
method writeMapBegin (k,v,s) =
self#writeByte (tv k);
self#writeByte (tv v);
- self#writeI32 s
+ self#writeI32 (Int32.of_int s)
method writeMapEnd = ()
method writeListBegin (t,s) =
self#writeByte (tv t);
- self#writeI32 s
+ self#writeI32 (Int32.of_int s)
method writeListEnd = ()
method writeSetBegin (t,s) =
self#writeByte (tv t);
- self#writeI32 s
+ self#writeI32 (Int32.of_int s)
method writeSetEnd = ()
method readByte =
ignore (trans#readAll ibyte 0 1);
- (comp_int ibyte 1)
+ Int32.to_int (comp_int ibyte 1)
method readI16 =
ignore (trans#readAll ibyte 0 2);
- comp_int ibyte 2
+ Int32.to_int (comp_int ibyte 2)
method readI32 =
ignore (trans#readAll ibyte 0 4);
comp_int ibyte 4
@@ -124,20 +125,19 @@
method readBool =
self#readByte = 1
method readString =
- let sz = self#readI32 in
+ let sz = Int32.to_int (self#readI32) in
let buf = String.create sz in
ignore (trans#readAll buf 0 sz);
buf
method readBinary = self#readString
method readMessageBegin =
let ver = self#readI32 in
- if (ver land version_mask != version_1) then
- (print_int ver;
- raise (P.E (P.BAD_VERSION, "Missing version identifier")))
+ if Int32.compare (Int32.logand ver version_mask) version_1 != 0 then
+ raise (P.E (P.BAD_VERSION, "Missing version identifier"))
else
let s = self#readString in
- let mt = P.message_type_of_i (ver land 0xFF) in
- (s,mt, self#readI32)
+ let mt = P.message_type_of_i (Int32.to_int (Int32.logand ver 0xFFl)) in
+ (s,mt, Int32.to_int self#readI32)
method readMessageEnd = ()
method readStructBegin =
""
@@ -152,15 +152,15 @@
method readMapBegin =
let kt = vt (self#readByte) in
let vt = vt (self#readByte) in
- (kt,vt, self#readI32)
+ (kt,vt, Int32.to_int self#readI32)
method readMapEnd = ()
method readListBegin =
let t = vt (self#readByte) in
- (t,self#readI32)
+ (t, Int32.to_int self#readI32)
method readListEnd = ()
method readSetBegin =
let t = vt (self#readByte) in
- (t, self#readI32);
+ (t, Int32.to_int self#readI32);
method readSetEnd = ()
end
diff --git a/lib/ocaml/src/TSimpleServer.ml b/lib/ocaml/src/TSimpleServer.ml
index d19d8c5..2927c08 100644
--- a/lib/ocaml/src/TSimpleServer.ml
+++ b/lib/ocaml/src/TSimpleServer.ml
@@ -26,13 +26,15 @@
method serve =
try
st#listen;
- let c = st#accept in
- let trans = tf#getTransport c in
- let inp = ipf#getProtocol trans in
- let op = opf#getProtocol trans in
- try
- while (pf#process inp op) do () done;
- trans#close
- with e -> trans#close; raise e
+ while true do
+ let c = st#accept in
+ let trans = tf#getTransport c in
+ let inp = ipf#getProtocol trans in
+ let op = opf#getProtocol trans in
+ try
+ while (pf#process inp op) do () done;
+ trans#close
+ with e -> trans#close; raise e
+ done
with _ -> ()
end
diff --git a/lib/ocaml/src/Thrift.ml b/lib/ocaml/src/Thrift.ml
index 8dc9afa..fdf2649 100644
--- a/lib/ocaml/src/Thrift.ml
+++ b/lib/ocaml/src/Thrift.ml
@@ -177,7 +177,7 @@
method virtual writeBool : bool -> unit
method virtual writeByte : int -> unit
method virtual writeI16 : int -> unit
- method virtual writeI32 : int -> unit
+ method virtual writeI32 : Int32.t -> unit
method virtual writeI64 : Int64.t -> unit
method virtual writeDouble : float -> unit
method virtual writeString : string -> unit
@@ -198,7 +198,7 @@
method virtual readBool : bool
method virtual readByte : int
method virtual readI16 : int
- method virtual readI32: int
+ method virtual readI32: Int32.t
method virtual readI64 : Int64.t
method virtual readDouble : float
method virtual readString : string
@@ -294,20 +294,20 @@
| MISSING_RESULT
let typ_of_i = function
- 0 -> UNKNOWN
- | 1 -> UNKNOWN_METHOD
- | 2 -> INVALID_MESSAGE_TYPE
- | 3 -> WRONG_METHOD_NAME
- | 4 -> BAD_SEQUENCE_ID
- | 5 -> MISSING_RESULT
+ 0l -> UNKNOWN
+ | 1l -> UNKNOWN_METHOD
+ | 2l -> INVALID_MESSAGE_TYPE
+ | 3l -> WRONG_METHOD_NAME
+ | 4l -> BAD_SEQUENCE_ID
+ | 5l -> MISSING_RESULT
| _ -> raise Thrift_error;;
let typ_to_i = function
- | UNKNOWN -> 0
- | UNKNOWN_METHOD -> 1
- | INVALID_MESSAGE_TYPE -> 2
- | WRONG_METHOD_NAME -> 3
- | BAD_SEQUENCE_ID -> 4
- | MISSING_RESULT -> 5
+ | UNKNOWN -> 0l
+ | UNKNOWN_METHOD -> 1l
+ | INVALID_MESSAGE_TYPE -> 2l
+ | WRONG_METHOD_NAME -> 3l
+ | BAD_SEQUENCE_ID -> 4l
+ | MISSING_RESULT -> 5l
class t =
object (self)
@@ -337,23 +337,21 @@
let read (iprot : Protocol.t) =
let msg = ref "" in
- let typ = ref 0 in
+ let typ = ref 0l in
ignore iprot#readStructBegin;
(try
while true do
let (name,ft,id) =iprot#readFieldBegin in
- if ft = Protocol.T_STOP then
- raise Break
+ if ft = Protocol.T_STOP
+ then raise Break
else ();
(match id with
- | 1 -> (if ft = Protocol.T_STRING then
- msg := (iprot#readString)
- else
- iprot#skip ft)
- | 2 -> (if ft = Protocol.T_I32 then
- typ := iprot#readI32
- else
- iprot#skip ft)
+ | 1 -> (if ft = Protocol.T_STRING
+ then msg := (iprot#readString)
+ else iprot#skip ft)
+ | 2 -> (if ft = Protocol.T_I32
+ then typ := iprot#readI32
+ else iprot#skip ft)
| _ -> iprot#skip ft);
iprot#readFieldEnd
done