You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/03/02 15:45:06 UTC

[4/8] thrift git commit: THRIFT-3699 Fix integer limit symbol includes in Python C extension

THRIFT-3699 Fix integer limit symbol includes in Python C extension

This closes #915


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/f7a8d946
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/f7a8d946
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/f7a8d946

Branch: refs/heads/master
Commit: f7a8d946a0b22d0acce1325d2607c38597b36a58
Parents: 3dd4d8e
Author: Nobuaki Sukegawa <ns...@apache.org>
Authored: Tue Mar 1 01:41:47 2016 +0900
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Wed Mar 2 23:44:23 2016 +0900

----------------------------------------------------------------------
 lib/py/src/ext/module.cpp   | 28 ++++++++++------------------
 lib/py/src/ext/protocol.h   |  8 ++++++--
 lib/py/src/ext/protocol.tcc | 16 +++++++++++-----
 lib/py/src/ext/types.h      |  5 +++++
 4 files changed, 32 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/f7a8d946/lib/py/src/ext/module.cpp
----------------------------------------------------------------------
diff --git a/lib/py/src/ext/module.cpp b/lib/py/src/ext/module.cpp
index 5ffc155..34ec7f6 100644
--- a/lib/py/src/ext/module.cpp
+++ b/lib/py/src/ext/module.cpp
@@ -21,8 +21,8 @@
 #include "types.h"
 #include "binary.h"
 #include "compact.h"
+#include <limits>
 #include <stdint.h>
-#include <sys/resource.h>
 
 // TODO(dreiss): defval appears to be unused.  Look into removing it.
 // TODO(dreiss): Make parse_spec_args recursive, and cache the output
@@ -87,11 +87,18 @@ static PyObject* decode_impl(PyObject* args) {
   }
 
   T protocol;
+#ifdef _MSC_VER
+  // workaround strange VC++ 2015 bug where #else path does not compile
+  int32_t default_limit = INT32_MAX;
+#else
+  int32_t default_limit = std::numeric_limits<int32_t>::max();
+#endif
   protocol.setStringLengthLimit(
-      as_long_then_delete(PyObject_GetAttr(oprot, INTERN_STRING(string_length_limit)), INT32_MAX));
+      as_long_then_delete(PyObject_GetAttr(oprot, INTERN_STRING(string_length_limit)),
+                          default_limit));
   protocol.setContainerLengthLimit(
       as_long_then_delete(PyObject_GetAttr(oprot, INTERN_STRING(container_length_limit)),
-                          INT32_MAX));
+                          default_limit));
   ScopedPyObject transport(PyObject_GetAttr(oprot, INTERN_STRING(trans)));
   if (!transport) {
     return NULL;
@@ -170,21 +177,6 @@ void initfastbinary() {
 
 #endif
 
-  const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB
-  struct rlimit rl;
-  int result;
-
-  result = getrlimit(RLIMIT_STACK, &rl);
-  if (result == 0) {
-    if (rl.rlim_cur < kStackSize) {
-      rl.rlim_cur = kStackSize;
-      result = setrlimit(RLIMIT_STACK, &rl);
-      if (result != 0) {
-        fprintf(stderr, "setrlimit returned result = %d\n", result);
-      }
-    }
-  }
-
 #define INIT_INTERN_STRING(value)                                                                  \
   do {                                                                                             \
     INTERN_STRING(value) = PyString_InternFromString(#value);                                      \

http://git-wip-us.apache.org/repos/asf/thrift/blob/f7a8d946/lib/py/src/ext/protocol.h
----------------------------------------------------------------------
diff --git a/lib/py/src/ext/protocol.h b/lib/py/src/ext/protocol.h
index bf3a6b8..126dbc3 100644
--- a/lib/py/src/ext/protocol.h
+++ b/lib/py/src/ext/protocol.h
@@ -21,6 +21,8 @@
 #define THRIFT_PY_PROTOCOL_H
 
 #include "ext/types.h"
+#include <limits>
+#include <stdint.h>
 
 namespace apache {
 namespace thrift {
@@ -30,14 +32,16 @@ template <typename Impl>
 class ProtocolBase {
 
 public:
-  ProtocolBase() : stringLimit_(INT32_MAX), containerLimit_(INT32_MAX), output_(NULL) {}
+  ProtocolBase()
+    : stringLimit_(std::numeric_limits<int32_t>::max()),
+      containerLimit_(std::numeric_limits<int32_t>::max()),
+      output_(NULL) {}
   inline virtual ~ProtocolBase();
 
   bool prepareDecodeBufferFromTransport(PyObject* trans);
 
   PyObject* readStruct(PyObject* output, PyObject* klass, PyObject* spec_seq);
 
-
   bool prepareEncodeBuffer();
 
   bool encodeValue(PyObject* value, TType type, PyObject* typeargs);

http://git-wip-us.apache.org/repos/asf/thrift/blob/f7a8d946/lib/py/src/ext/protocol.tcc
----------------------------------------------------------------------
diff --git a/lib/py/src/ext/protocol.tcc b/lib/py/src/ext/protocol.tcc
index 9c25841..2f0d083 100644
--- a/lib/py/src/ext/protocol.tcc
+++ b/lib/py/src/ext/protocol.tcc
@@ -20,6 +20,8 @@
 #ifndef THRIFT_PY_PROTOCOL_TCC
 #define THRIFT_PY_PROTOCOL_TCC
 
+#include <iterator>
+
 #define CHECK_RANGE(v, min, max) (((v) <= (max)) && ((v) >= (min)))
 #define INIT_OUTBUF_SIZE 128
 
@@ -210,7 +212,7 @@ inline bool check_ssize_t_32(Py_ssize_t len) {
   if (INT_CONV_ERROR_OCCURRED(len)) {
     return false;
   }
-  if (!CHECK_RANGE(len, 0, INT32_MAX)) {
+  if (!CHECK_RANGE(len, 0, std::numeric_limits<int32_t>::max())) {
     PyErr_SetString(PyExc_OverflowError, "size out of range: exceeded INT32_MAX");
     return false;
   }
@@ -358,7 +360,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type
   case T_I08: {
     int8_t val;
 
-    if (!parse_pyint(value, &val, INT8_MIN, INT8_MAX)) {
+    if (!parse_pyint(value, &val, std::numeric_limits<int8_t>::min(),
+                     std::numeric_limits<int8_t>::max())) {
       return false;
     }
 
@@ -368,7 +371,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type
   case T_I16: {
     int16_t val;
 
-    if (!parse_pyint(value, &val, INT16_MIN, INT16_MAX)) {
+    if (!parse_pyint(value, &val, std::numeric_limits<int16_t>::min(),
+                     std::numeric_limits<int16_t>::max())) {
       return false;
     }
 
@@ -378,7 +382,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type
   case T_I32: {
     int32_t val;
 
-    if (!parse_pyint(value, &val, INT32_MIN, INT32_MAX)) {
+    if (!parse_pyint(value, &val, std::numeric_limits<int32_t>::min(),
+                     std::numeric_limits<int32_t>::max())) {
       return false;
     }
 
@@ -392,7 +397,8 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type
       return false;
     }
 
-    if (!CHECK_RANGE(nval, INT64_MIN, INT64_MAX)) {
+    if (!CHECK_RANGE(nval, std::numeric_limits<int64_t>::min(),
+                     std::numeric_limits<int64_t>::max())) {
       PyErr_SetString(PyExc_OverflowError, "int out of range");
       return false;
     }

http://git-wip-us.apache.org/repos/asf/thrift/blob/f7a8d946/lib/py/src/ext/types.h
----------------------------------------------------------------------
diff --git a/lib/py/src/ext/types.h b/lib/py/src/ext/types.h
index fd0a197..2fc9d9c 100644
--- a/lib/py/src/ext/types.h
+++ b/lib/py/src/ext/types.h
@@ -22,6 +22,11 @@
 
 #include <Python.h>
 
+#ifdef _MSC_VER
+#define __STDC_LIMIT_MACROS
+#endif
+#include <stdint.h>
+
 #if PY_MAJOR_VERSION >= 3
 
 #include <vector>