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/lib/cpp/src/protocol/TBinaryProtocol.cc b/lib/cpp/src/protocol/TBinaryProtocol.cc
index 3cd11ba..f2fbe87 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.cc
+++ b/lib/cpp/src/protocol/TBinaryProtocol.cc
@@ -48,11 +48,11 @@
 uint32_t TBinaryProtocol::writeMapBegin(shared_ptr<TTransport> out,
                                         const TType keyType,
                                         const TType valType,
-                                        const int32_t size) const {
+                                        const uint32_t size) const {
   return
     writeByte(out, (uint8_t)keyType) +
     writeByte(out, (uint8_t)valType) +
-    writeI32(out, (int32_t)size);
+    writeU32(out, (uint32_t)size);
 }
 
 uint32_t TBinaryProtocol::writeMapEnd(shared_ptr<TTransport> out) const {
@@ -61,10 +61,10 @@
 
 uint32_t TBinaryProtocol::writeListBegin(shared_ptr<TTransport> out,
                                          const TType elemType,
-                                         const int32_t size) const {
+                                         const uint32_t size) const {
   return
     writeByte(out, (uint8_t) elemType) +
-    writeI32(out, (int32_t)size);
+    writeU32(out, (int32_t)size);
 }
 
 uint32_t TBinaryProtocol::writeListEnd(shared_ptr<TTransport> out) const {
@@ -73,10 +73,10 @@
 
 uint32_t TBinaryProtocol::writeSetBegin(shared_ptr<TTransport> out,
                                         const TType elemType,
-                                        const int32_t size) const {
+                                        const uint32_t size) const {
   return
     writeByte(out, (uint8_t)elemType) +
-    writeI32(out, (int32_t)size);
+    writeU32(out, (int32_t)size);
 }
 
 uint32_t TBinaryProtocol::writeSetEnd(shared_ptr<TTransport> out) const {
@@ -200,14 +200,14 @@
 uint32_t TBinaryProtocol::readMapBegin(shared_ptr<TTransport> in,
                                        TType& keyType,
                                        TType& valType,
-                                       int32_t& size) const {
+                                       uint32_t& size) const {
   uint8_t k, v;
   uint32_t result = 0;
   result += readByte(in, k);
   keyType = (TType)k;
   result += readByte(in, v);
   valType = (TType)v;
-  result += readI32(in, size);
+  result += readU32(in, size);
   return result;
 }
 
@@ -217,12 +217,12 @@
 
 uint32_t TBinaryProtocol::readListBegin(shared_ptr<TTransport> in,
                                         TType& elemType,
-                                        int32_t& size) const {
+                                        uint32_t& size) const {
   uint8_t e;
   uint32_t result = 0;
   result += readByte(in, e);
   elemType = (TType)e;
-  result += readI32(in, size);
+  result += readU32(in, size);
   return result;
 }
 
@@ -232,12 +232,12 @@
 
 uint32_t TBinaryProtocol::readSetBegin(shared_ptr<TTransport> in,
                                        TType& elemType,
-                                       int32_t& size) const {
+                                       uint32_t& size) const {
   uint8_t e;
   uint32_t result = 0;
   result += readByte(in, e);
   elemType = (TType)e;
-  result += readI32(in, size);
+  result += readU32(in, size);
   return result;
 }
 
@@ -318,8 +318,8 @@
 uint32_t TBinaryProtocol::readString(shared_ptr<TTransport> in,
                                      string& str) const {
   uint32_t result;
-  int32_t size;
-  result = readI32(in, size);
+  uint32_t size;
+  result = readU32(in, size);
 
   // Use the heap here to prevent stack overflow for v. large strings
   uint8_t *b = new uint8_t[size];
diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h
index 480182d..7780f16 100644
--- a/lib/cpp/src/protocol/TBinaryProtocol.h
+++ b/lib/cpp/src/protocol/TBinaryProtocol.h
@@ -49,19 +49,19 @@
   uint32_t writeMapBegin(shared_ptr<TTransport> out,
 			  const TType keyType,
 			  const TType valType,
-			  const int32_t size) const;
+			  const uint32_t size) const;
 
   uint32_t writeMapEnd(shared_ptr<TTransport> out) const;
 
   uint32_t writeListBegin(shared_ptr<TTransport> out,
 			   const TType elemType,
-			   const int32_t size) const;
+			   const uint32_t size) const;
 
   uint32_t writeListEnd(shared_ptr<TTransport> out) const;
 
   uint32_t writeSetBegin(shared_ptr<TTransport> out,
 			  const TType elemType,
-			  const int32_t size) const;
+			  const uint32_t size) const;
 
   uint32_t writeSetEnd(shared_ptr<TTransport> out) const;
 
@@ -119,19 +119,19 @@
   uint32_t readMapBegin(shared_ptr<TTransport> in,
 			 TType& keyType,
 			 TType& valType,
-			 int32_t& size) const;
+			 uint32_t& size) const;
 
   uint32_t readMapEnd(shared_ptr<TTransport> in) const;
 
   uint32_t readListBegin(shared_ptr<TTransport> in,
 			  TType& elemType,
-			  int32_t& size) const;
+			  uint32_t& size) const;
   
   uint32_t readListEnd(shared_ptr<TTransport> in) const;
 
   uint32_t readSetBegin(shared_ptr<TTransport> in,
 			 TType& elemType,
-			 int32_t& size) const;
+			 uint32_t& size) const;
 
   uint32_t readSetEnd(shared_ptr<TTransport> in) const;
 
diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h
index 7dbb4a0..38c5347 100644
--- a/lib/cpp/src/protocol/TProtocol.h
+++ b/lib/cpp/src/protocol/TProtocol.h
@@ -103,19 +103,19 @@
   virtual uint32_t writeMapBegin(shared_ptr<TTransport> out,
 				 const TType keyType,
 				 const TType valType,
-				 const int32_t size) const = 0;
+				 const uint32_t size) const = 0;
 
   virtual uint32_t writeMapEnd(shared_ptr<TTransport> out) const = 0;
   
   virtual uint32_t writeListBegin(shared_ptr<TTransport> out,
 				  const TType elemType,
-				  const int32_t size) const = 0;
+				  const uint32_t size) const = 0;
 
   virtual uint32_t writeListEnd(shared_ptr<TTransport> out) const = 0;
 
   virtual uint32_t writeSetBegin(shared_ptr<TTransport> out,
 				 const TType elemType,
-				 const int32_t size) const = 0;
+				 const uint32_t size) const = 0;
 
   virtual uint32_t writeSetEnd(shared_ptr<TTransport> out) const = 0;
 
@@ -172,19 +172,19 @@
   virtual uint32_t readMapBegin(shared_ptr<TTransport> in,
 				TType& keyType,
 				TType& valType,
-				int32_t& size) const = 0;
+				uint32_t& size) const = 0;
 
   virtual uint32_t readMapEnd(shared_ptr<TTransport> in) const = 0;
 
   virtual uint32_t readListBegin(shared_ptr<TTransport> in,
 				 TType& elemType,
-				 int32_t& size) const = 0;
+				 uint32_t& size) const = 0;
 
   virtual uint32_t readListEnd(shared_ptr<TTransport> in) const = 0;
 
   virtual uint32_t readSetBegin(shared_ptr<TTransport> in,
 				TType& elemType,
-				int32_t& size) const = 0;
+				uint32_t& size) const = 0;
 
   virtual uint32_t readSetEnd(shared_ptr<TTransport> in) const = 0;
 
@@ -273,7 +273,7 @@
         uint32_t result = 0;
         TType keyType;
         TType valType;
-        int32_t i, size;
+        uint32_t i, size;
         result += readMapBegin(in, keyType, valType, size);
         for (i = 0; i < size; i++) {
           result += skip(in, keyType);
@@ -286,7 +286,7 @@
       {
         uint32_t result = 0;
         TType elemType;
-        int32_t i, size;
+        uint32_t i, size;
         result += readSetBegin(in, elemType, size);
         for (i = 0; i < size; i++) {
           result += skip(in, elemType);
@@ -298,7 +298,7 @@
       {
         uint32_t result = 0;
         TType elemType;
-        int32_t i, size;
+        uint32_t i, size;
         result += readListBegin(in, elemType, size);
         for (i = 0; i < size; i++) {
           result += skip(in, elemType);
diff --git a/lib/cpp/src/test/Makefile b/lib/cpp/src/test/Makefile
index 73206cd..9b15095 100644
--- a/lib/cpp/src/test/Makefile
+++ b/lib/cpp/src/test/Makefile
@@ -38,7 +38,7 @@
 debug: stress-test-debug
 
 stubs: StressTest.thrift
-	$(THRIFT) --cpp StressTest.thrift
+	$(THRIFT) --cpp --php StressTest.thrift
 
 stress-test-debug: stubs
 	g++ -o stress-test $(DCFL) main.cc cpp-gen/StressTest.cc
diff --git a/lib/cpp/src/test/StressTest.thrift b/lib/cpp/src/test/StressTest.thrift
index 89e2f9b..3d2f9d8 100644
--- a/lib/cpp/src/test/StressTest.thrift
+++ b/lib/cpp/src/test/StressTest.thrift
@@ -7,5 +7,9 @@
   u16 echoU16(u16 arg),
   u32 echoU32(u32 arg),
   u64 echoU64(u64 arg),
+  string echoString(string arg),
+  list<byte>  echoList(list<byte> arg),
+  set<byte>  echoSet(set<byte> arg),
+  map<byte, byte>  echoMap(map<byte, byte> arg),
 }
 
diff --git a/lib/cpp/src/test/main.cc b/lib/cpp/src/test/main.cc
index 51ac38a..69a6eb0 100644
--- a/lib/cpp/src/test/main.cc
+++ b/lib/cpp/src/test/main.cc
@@ -34,6 +34,10 @@
   uint16_t echoU16(uint16_t arg) {return arg;}
   uint32_t echoU32(uint32_t arg) {return arg;}
   uint64_t echoU64(uint64_t arg) {return arg;}
+  string echoString(string arg) {return arg;}
+  list<uint8_t> echoList(list<uint8_t> arg) {return arg;}
+  set<uint8_t> echoSet(set<uint8_t> arg) {return arg;}
+  map<uint8_t, uint8_t> echoMap(map<uint8_t, uint8_t> arg) {return arg;}
 };
 
 class ClientThread: public Runnable {
@@ -107,17 +111,20 @@
   size_t workerCount = 4;
   size_t clientCount = 10;
   size_t loopCount = 10000;
+  bool runServer = true;
 
-     ostringstream usage;
+  ostringstream usage;
 
   usage <<
-    argv[0] << " [--port=<port number>] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>]" << endl <<
-
-    "\t\tserver-type\t\ttype of server, \"simple\" or \"thread-pool\".  Default is " << serverType << endl <<
-
-    "\t\tprotocol-type\t\ttype of protocol, \"binary\", \"ascii\", or \"xml\".  Default is " << protocolType << endl <<
-
-    "\t\tworkers\t\tNumber of thread pools workers.  Only valid for thread-pool server type.  Default is " << workerCount << endl;
+    argv[0] << " [--port=<port number>] [--server] [--server-type=<server-type>] [--protocol-type=<protocol-type>] [--workers=<worker-count>] [--clients=<client-count>] [--loop=<loop-count>]" << endl <<
+    "\tclients        Number of client threads to create - 0 implies no clients, i.e. server only.  Default is " << clientCount << endl <<
+    "\thelp           Prints this help text." << endl <<
+    "\tloop           The number of remote thrift calls each client makes.  Default is " << loopCount << endl <<
+    "\tport           The port the server and clients should bind to for thrift network connections.  Default is " << port << endl <<
+    "\tserver         Run the Thrift server in this process.  Default is " << runServer << endl <<
+    "\tserver-type    Type of server, \"simple\" or \"thread-pool\".  Default is " << serverType << endl <<
+    "\tprotocol-type  Type of protocol, \"binary\", \"ascii\", or \"xml\".  Default is " << protocolType << endl <<
+    "\tworkers        Number of thread pools workers.  Only valid for thread-pool server type.  Default is " << workerCount << endl;
     
   map<string, string>  args;
   
@@ -143,10 +150,27 @@
 
   try {
 
+    if(!args["clients"].empty()) {
+      clientCount = atoi(args["clients"].c_str());
+    }
+
+    if(!args["help"].empty()) {
+      cerr << usage.str();
+      return 0;
+    }
+
+    if(!args["loop"].empty()) {
+      loopCount = atoi(args["loop"].c_str());
+    }
+
     if(!args["port"].empty()) {
       port = atoi(args["port"].c_str());
     }
 
+    if(!args["server"].empty()) {
+      runServer = args["server"] == "true";
+    }
+
     if(!args["server-type"].empty()) {
       serverType = args["server-type"];
       
@@ -164,138 +188,141 @@
       workerCount = atoi(args["workers"].c_str());
     }
 
-    if(!args["clients"].empty()) {
-      clientCount = atoi(args["clients"].c_str());
-    }
-
-    if(!args["loop"].empty()) {
-      loopCount = atoi(args["loop"].c_str());
-    }
   } catch(exception& e) {
     cerr << e.what() << endl;
     cerr << usage;
   }
 
-  // Dispatcher
-  shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol);
-
-  shared_ptr<Server> server(new Server(binaryProtocol));
-
-  // Options
-  shared_ptr<TServerOptions> serverOptions(new TServerOptions());
-
-  // Transport
-  shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
-
-  // ThreadFactory
-
   shared_ptr<PosixThreadFactory> threadFactory = shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
 
-  shared_ptr<Thread> serverThread;
+  if(runServer) {
 
-  if(serverType == "simple") {
+    // Dispatcher
+    shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol);
 
-    serverThread = threadFactory->newThread(shared_ptr<Runnable>(new TSimpleServer(server, serverOptions, serverSocket)));
+    shared_ptr<Server> server(new Server(binaryProtocol));
 
-  } else if(serverType == "thread-pool") {
+    // Options
+    shared_ptr<TServerOptions> serverOptions(new TServerOptions());
 
-    shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);
+    // Transport
+    shared_ptr<TServerSocket> serverSocket(new TServerSocket(port));
 
-    threadManager->threadFactory(threadFactory);
+    // ThreadFactory
 
-    threadManager->start();
+    shared_ptr<Thread> serverThread;
 
-    serverThread = threadFactory->newThread(shared_ptr<TServer>(new TThreadPoolServer(server,
-										      serverOptions,
-										      serverSocket,
-										      threadManager)));
+    if(serverType == "simple") {
+      
+      serverThread = threadFactory->newThread(shared_ptr<Runnable>(new TSimpleServer(server, serverOptions, serverSocket)));
+      
+    } else if(serverType == "thread-pool") {
+
+      shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(workerCount);
+
+      threadManager->threadFactory(threadFactory);
+
+      threadManager->start();
+
+      serverThread = threadFactory->newThread(shared_ptr<TServer>(new TThreadPoolServer(server,
+											serverOptions,
+											serverSocket,
+											threadManager)));
+    }
+
+    cerr << "Starting the server on port " << port << endl;
+
+    serverThread->start();
+    
+    // If we aren't running clients, just wait forever for external clients
+
+    if(clientCount == 0) {
+      serverThread->join();
+    }
   }
 
-  cerr << "Starting the server on port " << port << endl;
+  if(clientCount > 0) {
 
-  serverThread->start();
+    Monitor monitor;
 
-  Monitor monitor;
+    size_t threadCount = 0;
 
-  size_t threadCount = 0;
+    set<shared_ptr<Thread> > clientThreads;
 
-  set<shared_ptr<Thread> > clientThreads;
-
-  for(size_t ix = 0; ix < clientCount; ix++) {
+    for(size_t ix = 0; ix < clientCount; ix++) {
     
-    shared_ptr<TSocket> socket(new TSocket("127.0.01", port));
-    shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket, 2048));
-    shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol());
-    shared_ptr<ServiceClient> serviceClient(new ServiceClient(bufferedSocket, binaryProtocol));
+      shared_ptr<TSocket> socket(new TSocket("127.0.01", port));
+      shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket, 2048));
+      shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol());
+      shared_ptr<ServiceClient> serviceClient(new ServiceClient(bufferedSocket, binaryProtocol));
     
-    clientThreads.insert(threadFactory->newThread(shared_ptr<ClientThread>(new ClientThread(bufferedSocket, serviceClient, monitor, threadCount, loopCount))));
-  }
+      clientThreads.insert(threadFactory->newThread(shared_ptr<ClientThread>(new ClientThread(bufferedSocket, serviceClient, monitor, threadCount, loopCount))));
+    }
   
-  for(std::set<shared_ptr<Thread> >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) {
-    (*thread)->start();
-  }
+    for(std::set<shared_ptr<Thread> >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) {
+      (*thread)->start();
+    }
 
-  cerr << endl;
-
-  long long time00;
-  long long time01;
+    long long time00;
+    long long time01;
   
-  {Synchronized s(monitor);
-    threadCount = clientCount;
+    {Synchronized s(monitor);
+      threadCount = clientCount;
     
-    cerr << "Launch "<< clientCount << " client threads" << endl;
+      cerr << "Launch "<< clientCount << " client threads" << endl;
     
-    time00 =  Util::currentTime();
+      time00 =  Util::currentTime();
     
-    monitor.notifyAll();
+      monitor.notifyAll();
+      
+      while(threadCount > 0) {
+	monitor.wait();
+      }
     
-    while(threadCount > 0) {
-      monitor.wait();
+      time01 =  Util::currentTime();
     }
-    
-    time01 =  Util::currentTime();
-  }
   
-  long long firstTime = 9223372036854775807LL;
-  long long lastTime = 0;
+    long long firstTime = 9223372036854775807LL;
+    long long lastTime = 0;
 
-  double averageTime = 0;
-  long long minTime = 9223372036854775807LL;
-  long long maxTime = 0;
+    double averageTime = 0;
+    long long minTime = 9223372036854775807LL;
+    long long maxTime = 0;
   
-  for(set<shared_ptr<Thread> >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) {
+    for(set<shared_ptr<Thread> >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) {
       
-    shared_ptr<ClientThread> client = dynamic_pointer_cast<ClientThread>((*ix)->runnable());
+      shared_ptr<ClientThread> client = dynamic_pointer_cast<ClientThread>((*ix)->runnable());
       
-    long long delta = client->_endTime - client->_startTime;
+      long long delta = client->_endTime - client->_startTime;
       
-    assert(delta > 0);
+      assert(delta > 0);
 
-    if(client->_startTime < firstTime) {
-      firstTime = client->_startTime;
-    }
+      if(client->_startTime < firstTime) {
+	firstTime = client->_startTime;
+      }
       
-    if(client->_endTime > lastTime) {
-      lastTime = client->_endTime;
-    }
+      if(client->_endTime > lastTime) {
+	lastTime = client->_endTime;
+      }
       
-    if(delta < minTime) {
-      minTime = delta;
-    }
+      if(delta < minTime) {
+	minTime = delta;
+      }
       
-    if(delta > maxTime) {
-      maxTime = delta;
-    }
+      if(delta > maxTime) {
+	maxTime = delta;
+      }
       
-    averageTime+= delta;
+      averageTime+= delta;
+    }
+    
+    averageTime /= clientCount;
+    
+    
+    cout <<  "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl;
+    
+    cerr << "done." << endl;
   }
-    
-  averageTime /= clientCount;
-    
-
-  cout <<  "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl;
-    
-  cerr << "done." << endl;
 
   return 0;
 }