Skip to content

Commit

Permalink
Porting changes from snappy/0.11.0
Browse files Browse the repository at this point in the history
- Add "skip_async" property to java generator
  - This skips generation of asynchronous interfaces for those who are not using them.

- Add "struct_separate_files" property to C++ generator
  - This generates of classes in separate files, one class per file, instead of everything
    in a single file (similar to what other generators like java do by default).
  - For clean separation of classes and allows override of specific classes by hand-written code.
  - This patch also changes the constants generation to use static consts for primitive types
    (int, bool, long, short, byte, double)

- Add couple of options to skip C++ generator features
  - "no-recursion-limit" option to skip checks for maximum recursion limit while writing objects
  - "no-concurrent-client" option to skip concurrent client code generation

- Adding public getters for TSocket timeout settings
- Removing unnecessary TBase with virtual TBase
- Changing to C++11 noexcept from empty throw()
- Allow for localhost-only bind for client sockets (C++)
- Fixing build on older compilers (gcc < 4.5).
- Fixing maven repo URLs to use https
- Fix java plugin's gradle install task
  • Loading branch information
Sumedh Wale authored and sumwale committed Jan 19, 2020
1 parent 384647d commit c4ba549
Show file tree
Hide file tree
Showing 16 changed files with 417 additions and 133 deletions.
436 changes: 366 additions & 70 deletions compiler/cpp/src/thrift/generate/t_cpp_generator.cc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/cpp/src/thrift/generate/t_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class t_generator {
virtual std::string autogen_comment() {
return std::string("/**\n") + " * " + autogen_summary() + "\n" + " *\n"
+ " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
+ " * @generated\n" + " */\n";
+ " * @generated\n" + " */\n\n";
}

virtual std::string autogen_summary() {
Expand Down
21 changes: 17 additions & 4 deletions compiler/cpp/src/thrift/generate/t_java_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class t_java_generator : public t_oop_generator {
suppress_generated_annotations_ = false;
rethrow_unhandled_exceptions_ = false;
unsafe_binaries_ = false;
skip_async_ = false;
for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
if( iter->first.compare("beans") == 0) {
bean_style_ = true;
Expand Down Expand Up @@ -106,6 +107,8 @@ class t_java_generator : public t_oop_generator {
}
} else if( iter->first.compare("unsafe_binaries") == 0) {
unsafe_binaries_ = true;
} else if( iter->first.compare("skip_async") == 0) {
skip_async_ = true;
} else {
throw "unknown option java:" + iter->first;
}
Expand Down Expand Up @@ -415,6 +418,7 @@ class t_java_generator : public t_oop_generator {
bool suppress_generated_annotations_;
bool rethrow_unhandled_exceptions_;
bool unsafe_binaries_;
bool skip_async_;

};

Expand Down Expand Up @@ -2855,11 +2859,17 @@ void t_java_generator::generate_service(t_service* tservice) {

// Generate the three main parts of the service
generate_service_interface(tservice);
generate_service_async_interface(tservice);
if (!skip_async_) {
generate_service_async_interface(tservice);
}
generate_service_client(tservice);
generate_service_async_client(tservice);
if (!skip_async_) {
generate_service_async_client(tservice);
}
generate_service_server(tservice);
generate_service_async_server(tservice);
if (!skip_async_) {
generate_service_async_server(tservice);
}
generate_service_helpers(tservice);

indent_down();
Expand Down Expand Up @@ -5451,4 +5461,7 @@ THRIFT_REGISTER_GENERATOR(
" generated_annotations=[undated|suppress]:\n"
" undated: suppress the date at @Generated annotations\n"
" suppress: suppress @Generated annotations entirely\n"
" unsafe_binaries: Do not copy ByteBuffers in constructors, getters, and setters.\n")
" unsafe_binaries: Do not copy ByteBuffers in constructors, getters, and setters.\n"
" skip_async:\n"
" Skip generating the Asynchronous interfaces, client and server.\n"
)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "0.11.0"
}
}
}
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ AS_IF([test "x$PY_PREFIX" = x], [PY_PREFIX="/usr"])

AC_ARG_VAR([JAVA_PREFIX], [Prefix for installing the Java lib jar.
Default = "/usr/local/lib"])
AS_IF([test "x$JAVA_PREFIX" != x], [JAVA_PREFIX="$JAVA_PREFIX/usr/local/lib"],
AS_IF([test "x$JAVA_PREFIX" != x], [JAVA_PREFIX="$JAVA_PREFIX"],
[test "x$PREFIX" != x], [JAVA_PREFIX="$PREFIX/usr/local/lib"],
[JAVA_PREFIX="/usr/local/lib"])

Expand Down
2 changes: 1 addition & 1 deletion contrib/fb303/java/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Maven Ant tasks Jar details
mvn.ant.task.version=2.1.3
mvn.repo=http://repo1.maven.org/maven2
mvn.repo=https://repo1.maven.org/maven2
mvn.ant.task.url=${mvn.repo}/org/apache/maven/maven-ant-tasks/${mvn.ant.task.version}
mvn.ant.task.jar=maven-ant-tasks-${mvn.ant.task.version}.jar
2 changes: 1 addition & 1 deletion lib/as3/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Maven Ant tasks Jar details
mvn.ant.task.version=2.1.3
mvn.repo=http://repo1.maven.org/maven2
mvn.repo=https://repo1.maven.org/maven2
mvn.ant.task.url=${mvn.repo}/org/apache/maven/maven-ant-tasks/${mvn.ant.task.version}
mvn.ant.task.jar=maven-ant-tasks-${mvn.ant.task.version}.jar
3 changes: 1 addition & 2 deletions lib/cpp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ include_thrift_HEADERS = \
src/thrift/TApplicationException.h \
src/thrift/TLogging.h \
src/thrift/TToString.h \
src/thrift/stdcxx.h \
src/thrift/TBase.h
src/thrift/stdcxx.h

include_concurrencydir = $(include_thriftdir)/concurrency
include_concurrency_HEADERS = \
Expand Down
38 changes: 0 additions & 38 deletions lib/cpp/src/thrift/TBase.h

This file was deleted.

4 changes: 2 additions & 2 deletions lib/cpp/src/thrift/transport/THeaderTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class THeaderTransport : public TVirtualTransport<THeaderTransport, TFramedTrans

/// Use default buffer sizes.
explicit THeaderTransport(const stdcxx::shared_ptr<TTransport>& transport)
: TVirtualTransport(transport),
: TVirtualTransport<THeaderTransport, TFramedTransport>(transport),
outTransport_(transport),
protoId(T_COMPACT_PROTOCOL),
clientType(THRIFT_HEADER_CLIENT_TYPE),
Expand All @@ -90,7 +90,7 @@ class THeaderTransport : public TVirtualTransport<THeaderTransport, TFramedTrans

THeaderTransport(const stdcxx::shared_ptr<TTransport> inTransport,
const stdcxx::shared_ptr<TTransport> outTransport)
: TVirtualTransport(inTransport),
: TVirtualTransport<THeaderTransport, TFramedTransport>(inTransport),
outTransport_(outTransport),
protoId(T_COMPACT_PROTOCOL),
clientType(THRIFT_HEADER_CLIENT_TYPE),
Expand Down
9 changes: 1 addition & 8 deletions lib/cpp/src/thrift/transport/TSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,11 @@ void TSocket::local_open() {
std::memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
hints.ai_flags = AI_PASSIVE;
sprintf(port, "%d", port_);

error = getaddrinfo(host_.c_str(), port, &hints, &res0);

#ifdef _WIN32
if (error == WSANO_DATA) {
hints.ai_flags &= ~AI_ADDRCONFIG;
error = getaddrinfo(host_.c_str(), port, &hints, &res0);
}
#endif

if (error) {
string errStr = "TSocket::open() getaddrinfo() " + getSocketInfo()
+ string(THRIFT_GAI_STRERROR(error));
Expand Down
21 changes: 21 additions & 0 deletions lib/cpp/src/thrift/transport/TSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,37 @@ class TSocket : public TVirtualTransport<TSocket> {
*/
void setConnTimeout(int ms);

/**
* Get the connect timeout in milliseconds.
*/
int getConnTimeout() {
return connTimeout_;
}

/**
* Set the receive timeout
*/
void setRecvTimeout(int ms);

/**
* Get the receive timeout in milliseconds.
*/
int getRecvTimeout() {
return recvTimeout_;
}

/**
* Set the send timeout
*/
void setSendTimeout(int ms);

/**
* Get the send timeout in milliseconds.
*/
int getSendTimeout() {
return sendTimeout_;
}

/**
* Set the max number of recv retries in case of an THRIFT_EAGAIN
* error
Expand Down
2 changes: 1 addition & 1 deletion lib/java/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ all-local:
--console=plain

install-exec-hook:
./gradlew $(GRADLE_OPTS) install \
./gradlew $(GRADLE_OPTS) installDist installJavadoc \
-Prelease=true \
-Pinstall.path=$(DESTDIR)$(JAVA_PREFIX) \
-Pinstall.javadoc.path=$(DESTDIR)$(docdir)/java \
Expand Down
2 changes: 1 addition & 1 deletion lib/java/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ testPort=9090
cloverEnabled=false

# Maven dependency download locations
mvn.repo=http://repo1.maven.org/maven2
mvn.repo=https://repo1.maven.org/maven2
apache.repo=https://repository.apache.org/content/repositories/releases

# Apache Maven publish
Expand Down
2 changes: 1 addition & 1 deletion lib/js/test/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Maven Ant tasks Jar details
mvn.ant.task.version=2.1.3
mvn.repo=http://repo1.maven.org/maven2
mvn.repo=https://repo1.maven.org/maven2
mvn.ant.task.url=${mvn.repo}/org/apache/maven/maven-ant-tasks/${mvn.ant.task.version}
mvn.ant.task.jar=maven-ant-tasks-${mvn.ant.task.version}.jar
2 changes: 1 addition & 1 deletion lib/json/test/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mvn.ant.task.version=2.1.3
json-schema-validator.version=2.2.6

# Maven dependency download locations
mvn.repo=http://repo1.maven.org/maven2
mvn.repo=https://repo1.maven.org/maven2
mvn.ant.task.url=${mvn.repo}/org/apache/maven/maven-ant-tasks/${mvn.ant.task.version}
mvn.ant.task.jar=maven-ant-tasks-${mvn.ant.task.version}.jar

0 comments on commit c4ba549

Please sign in to comment.