Fix bug where int attributes >= 2**31 caused on exception on some platforms.

PiperOrigin-RevId: 343544621
Change-Id: I0881f6f77d6293a25b6804a1a8ebe4692222dd55
This commit is contained in:
Edward Loper 2020-11-20 12:36:42 -08:00 committed by TensorFlower Gardener
parent ce73ff7126
commit 35696cc325
2 changed files with 15 additions and 1 deletions

View File

@ -243,7 +243,7 @@ struct FastPathOpExecInfo {
#if PY_MAJOR_VERSION >= 3
PARSE_VALUE(ParseIntValue, int, PyLong_Check, PyLong_AsLong)
PARSE_VALUE(ParseInt64Value, int64_t, PyLong_Check, PyLong_AsLong)
PARSE_VALUE(ParseInt64Value, int64_t, PyLong_Check, PyLong_AsLongLong)
#else
PARSE_VALUE(ParseIntValue, int, PyInt_Check, PyInt_AsLong)
#endif

View File

@ -368,5 +368,19 @@ class Tests(test.TestCase):
self.assertNotRegex(full_exception_text, "_FallbackException")
def testIntAttrThatDoesNotFitIn32Bits(self):
# Tests bug where int attributes >= 2**31 raised an exception on platforms
# where sizeof(long) = 32 bits.
ctx = context.context()
ctx.ensure_initialized()
shape = constant_op.constant([10])
minval = constant_op.constant(0)
maxval = constant_op.constant(10)
seed = 2**50
pywrap_tfe.TFE_Py_FastPathExecute(ctx, "RandomUniformInt", None,
shape, minval, maxval,
"seed", seed)
if __name__ == "__main__":
test.main()