Uber configure.ac/Makefile.am and configure.ac/Makefile.am for lib/php and compiler
Modified TProtocol.h et al to take collection size as unsigned int. This removes need to cast STL's default size_t to signed int and is more correct, since collection sizes cannot be < 0 by definition
Moved compiler/Makefile to compiler/cpp.mk so it doesn't get trashed by automake
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664766 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/src/cpp_generator.py b/compiler/src/cpp_generator.py
index ba3380e..97a5f36 100644
--- a/compiler/src/cpp_generator.py
+++ b/compiler/src/cpp_generator.py
@@ -871,15 +871,22 @@
${keyType} key;
${valueType} elem;
uint32_t xfer = 0;
+ """+CPP_PROTOCOL_TTYPE+""" keyType;
+ """+CPP_PROTOCOL_TTYPE+""" valueType;
- xfer += iprot->readU32(itrans, count);
+ xfer += iprot->readMapBegin(itrans, keyType, valueType, count);
+ /* XXX
+ Should we assert that read key and value type are correct? */
+
for(uint32_t ix = 0; ix < count; ix++) {
${keyReaderCall};
${valueReaderCall};
value.insert(std::make_pair(key, elem));
}
+ xfer += iprot->readMapEnd(itrans);
+
return xfer;
}
""")
@@ -889,12 +896,14 @@
uint32_t xfer = 0;
- xfer += oprot->writeU32(otrans, value.size());
+ xfer += oprot->writeMapBegin(otrans, ${keyWireType}, ${valueWireType}, value.size());
for(${declaration}::const_iterator ix = value.begin(); ix != value.end(); ++ix) {
${keyWriterCall};
${valueWriterCall};
}
+
+ xfer += oprot->writeMapEnd(otrans);
return xfer;
}
""")
@@ -905,6 +914,12 @@
uint32_t count;
${valueType} elem;
uint32_t xfer = 0;
+ """+CPP_PROTOCOL_TTYPE+""" valueType;
+
+ xfer += iprot->read${protocolSuffix}Begin(itrans, valueType, count);
+
+ /* XXX
+ Should we assert that read value type is correct? */
xfer+= iprot->readU32(itrans, count);
@@ -912,6 +927,8 @@
${valueReaderCall};
value.${insert}(elem);
}
+
+ xfer += iprot->read${protocolSuffix}End(itrans);
return xfer;
}
""")
@@ -921,11 +938,14 @@
uint32_t xfer = 0;
- xfer+= oprot->writeU32(otrans, value.size());
+ xfer+= oprot->write${protocolSuffix}Begin(otrans, ${valueWireType}, value.size());
for(${declaration}::const_iterator ix = value.begin(); ix != value.end(); ++ix) {
${valueWriterCall};
}
+
+ xfer+= oprot->write${protocolSuffix}End(otrans);
+
return xfer;
}
""")
@@ -949,11 +969,14 @@
else:
if isinstance(collection, ListType):
+ protocolSuffix="List"
insert="push_back"
else:
+ protocolSuffix="Set"
insert="insert"
return CPP_READ_LIST_DEFINITION.substitute(suffix=suffix, declaration=toCTypeDeclaration(collection),
+ protocolSuffix=protocolSuffix,
valueReaderCall=valueReaderCall,
valueType=toCTypeDeclaration(collection.valueType),
insert=insert)
@@ -966,22 +989,36 @@
if isinstance(collection, MapType):
keyWriterCall = toWriterCall("ix->first", collection.keyType)
+ keyWireType = toWireType(collection.keyType)
valueWriterCall = toWriterCall("ix->second", collection.valueType)
else:
valueWriterCall= toWriterCall("*ix", collection.valueType)
+ valueWireType = toWireType(collection.valueType)
+
if isinstance(collection, MapType):
return CPP_WRITE_MAP_DEFINITION.substitute(suffix=suffix, declaration=toCTypeDeclaration(collection),
- keyType=toCTypeDeclaration(collection.keyType),
- keyWriterCall=keyWriterCall,
- valueType=toCTypeDeclaration(collection.valueType),
- valueWriterCall=valueWriterCall)
+ keyType=toCTypeDeclaration(collection.keyType),
+ keyWireType=keyWireType,
+ keyWriterCall=keyWriterCall,
+ valueType=toCTypeDeclaration(collection.valueType),
+ valueWireType=valueWireType,
+ valueWriterCall=valueWriterCall)
else:
+ if isinstance(collection, ListType):
+ protocolSuffix = "List"
+ elif isinstance(collection, SetType):
+ protocolSuffix = "Set"
+ else:
+ raise Exception, "Unknown collection type "+str(type(collection))+":"+str(collection)
+
return CPP_WRITE_LIST_DEFINITION.substitute(suffix=suffix, declaration=toCTypeDeclaration(collection),
- valueWriterCall=valueWriterCall,
- valueType=toCTypeDeclaration(collection.valueType))
+ protocolSuffix=protocolSuffix,
+ valueWireType=valueWireType,
+ valueWriterCall=valueWriterCall,
+ valueType=toCTypeDeclaration(collection.valueType))
CPP_READ_STRUCT_DEFINITION = Template("""
diff --git a/compiler/src/php_generator.py b/compiler/src/php_generator.py
index e68a4f7..71b1fd3 100644
--- a/compiler/src/php_generator.py
+++ b/compiler/src/php_generator.py
@@ -329,8 +329,6 @@
result+= self.toReadStructEnd()
- result+= self.indent()+"return "+value+";\n"
-
return result
def toReadCollection(self, value, collection):
@@ -631,12 +629,17 @@
result+= self.indent()+"}\n"
+ result+= self.reader.toReadMessageEnd()
+
+ if not isVoidType(function.returnType()):
+ result+= self.indent()+"return "+resultVar.name+"->success;\n"
+ else:
+ result+= self.indent()+"return;\n"
+
self.indent-= 1
self.oldScope()
- result+= self.reader.toReadMessageEnd()
-
result+= self.indent()+"}\n"
return result
diff --git a/compiler/src/thrift b/compiler/src/thrift
index 39bdb16..6c252d9 100644
--- a/compiler/src/thrift
+++ b/compiler/src/thrift
@@ -1,16 +1,20 @@
#!python
import sys
-from thrift import cpp_generator
from thrift import generator
+from thrift import cpp_generator
+from thrift import php_generator
from thrift import parser
-def thrift(source, cpp=False, perl=False, php=False, python=False, java=False, ruby=False, debug=False):
+def thrift(source, cpp=False, java=False, perl=False, php=False, python=False, ruby=False, debug=False):
generators = []
if cpp:
generators.append(cpp_generator.CPPGenerator())
+ if php:
+ generators.append(php_generator.PHPGenerator())
+
p = parser.Parser(debug=debug)
p.parse(source, False)
@@ -37,6 +41,9 @@
if "--cpp" in args:
cpp = True
args.remove("--cpp")
+ if "--php" in args:
+ php = True
+ args.remove("--php")
if "--debug" in args:
debug = True
args.remove("--debug")