Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit fad8d6b1096769abc6eb4c0f2f926de4d3f5ab56 1 parent 0c124bb
Bryan Duxbury authored
View
14 compiler/cpp/src/generate/t_ocaml_generator.cc
@@ -323,22 +323,22 @@ void t_ocaml_generator::generate_enum(t_enum* tenum) {
indent_down();
indent(f_types_) << "let to_i = function" << endl;
- indent(f_types_i_) << "val to_i : t -> int" << endl;
+ indent(f_types_i_) << "val to_i : t -> Int32.t" << endl;
indent_up();
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
int value = (*c_iter)->get_value();
string name = capitalize((*c_iter)->get_name());
- indent(f_types_) << "| " << name << " -> " << value << endl;
+ indent(f_types_) << "| " << name << " -> " << value << "l" << endl;
}
indent_down();
indent(f_types_) << "let of_i = function" << endl;
- indent(f_types_i_) << "val of_i : int -> t" << endl;
+ indent(f_types_i_) << "val of_i : Int32.t -> t" << endl;
indent_up();
for(c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
int value = (*c_iter)->get_value();
string name = capitalize((*c_iter)->get_name());
- indent(f_types_) << "| " << value << " -> " << name << endl;
+ indent(f_types_) << "| " << value << "l -> " << name << endl;
}
indent(f_types_) << "| _ -> raise Thrift_error" << endl;
indent_down();
@@ -379,9 +379,11 @@ string t_ocaml_generator::render_const_value(t_type* type, t_const_value* value)
break;
case t_base_type::TYPE_BYTE:
case t_base_type::TYPE_I16:
- case t_base_type::TYPE_I32:
out << value->get_integer();
break;
+ case t_base_type::TYPE_I32:
+ out << value->get_integer() << "l";
+ break;
case t_base_type::TYPE_I64:
out << value->get_integer() << "L";
break;
@@ -1851,7 +1853,7 @@ string t_ocaml_generator::render_ocaml_type(t_type* type) {
case t_base_type::TYPE_I16:
return "int";
case t_base_type::TYPE_I32:
- return "int";
+ return "Int32.t";
case t_base_type::TYPE_I64:
return "Int64.t";
case t_base_type::TYPE_DOUBLE:
View
44 lib/ocaml/src/TBinaryProtocol.ml
@@ -22,6 +22,7 @@ open Thrift
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 @@ let comp_int b n =
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 @@ let comp_int64 b n =
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 @@ object (self)
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 @@ object (self)
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 @@ object (self)
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 @@ object (self)
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 @@ object (self)
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
View
18 lib/ocaml/src/TSimpleServer.ml
@@ -26,13 +26,15 @@ object
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
View
48 lib/ocaml/src/Thrift.ml
@@ -177,7 +177,7 @@ struct
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 @@ struct
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 @@ struct
| 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 @@ struct
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
Please sign in to comment.
Something went wrong with that request. Please try again.