File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -204,7 +204,11 @@ tensorflow::ImportNumpy();
204
204
// The wrapped function TF_GetOpList returns a TF_Buffer pointer. This typemap
205
205
// creates a Python string from the TF_Buffer and returns it.
206
206
%typemap(out) TF_Buffer TF_GetOpList {
207
+ %#if PY_MAJOR_VERSION < 3
207
208
$result = PyString_FromStringAndSize (
209
+ %#else
210
+ $result = PyUnicode_FromStringAndSize (
211
+ %#endif
208
212
reinterpret_cast <const char *>($1 .data ), $1 .length );
209
213
}
210
214
Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ limitations under the License.
24
24
#include " tensorflow/core/platform/mutex.h"
25
25
#include " tensorflow/core/platform/port.h"
26
26
27
+ // Return type of import_array() changed between Python 2 and 3
28
+ // NUMPY_IMPORT_ARRAY_RETVAL is NULL for Python 3
29
+ #if PY_MAJOR_VERSION >= 3
30
+ #define NUMPY_IMPORT_ARRAY_RETURN_TYPE int
31
+ #else
32
+ #define NUMPY_IMPORT_ARRAY_RETURN_TYPE void
33
+ #endif
34
+
27
35
namespace tensorflow {
28
36
namespace {
29
37
@@ -39,7 +47,7 @@ PyObject* GetPyTrampoline() {
39
47
}
40
48
41
49
// Module initialization (mainly import numpy) if needed.
42
- void InitIfNeeded () {
50
+ NUMPY_IMPORT_ARRAY_RETURN_TYPE InitIfNeeded () {
43
51
mutex_lock l (mu);
44
52
if (!initialized) {
45
53
PyGILState_STATE py_threadstate;
You can’t perform that action at this time.
0 commit comments