Use PyLong_AsLongLong instead of PyInt_AsLong to guarantee 64-bit output.
authorSkye Wanderman-Milne <skyewm@google.com>
Tue, 3 Apr 2018 19:38:54 +0000 (12:38 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Tue, 3 Apr 2018 19:41:39 +0000 (12:41 -0700)
A C long is 32 bits on some platforms, which can cause the
PyInt_AsLong call in PyInt64ListToVector to
overflow. large_concat_op_test exposes this bug on such platforms.

PiperOrigin-RevId: 191484167

tensorflow/python/client/tf_session.i
tensorflow/python/kernel_tests/large_concat_op_test.py

index 68768f2..0c18d97 100644 (file)
@@ -72,7 +72,7 @@ void PyInt64ListToVector(PyObject* py_int_seq, std::vector<int64_t>* vec) {
   int size = PySequence_Fast_GET_SIZE(py_int_seq);
   for (int i = 0; i < size; ++i) {
     PyObject* item = PySequence_Fast_GET_ITEM(py_int_seq, i);
-    vec->push_back(PyInt_AsLong(item));
+    vec->push_back(PyLong_AsLongLong(item));
   }
 }
 
index 66afb6e..184d1dd 100644 (file)
@@ -19,10 +19,12 @@ from __future__ import print_function
 
 from tensorflow.python.framework import dtypes
 from tensorflow.python.framework import ops
+from tensorflow.python.framework import test_util
 from tensorflow.python.ops import array_ops
 from tensorflow.python.platform import test
 
 
+@test_util.with_c_api
 class LargeConcatOpTest(test.TestCase):
   """Tests that belong in concat_op_test.py, but run over large tensors."""