summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setup.py4
-rw-r--r--torch/csrc/Generator.cpp4
-rw-r--r--torch/csrc/THP.h11
-rw-r--r--torch/csrc/autograd/functions/init.cpp2
-rw-r--r--torch/csrc/autograd/python_function.cpp2
-rw-r--r--torch/csrc/cuda/Module.cpp6
-rw-r--r--torch/csrc/utils/python_numbers.h9
-rw-r--r--torch/multiprocessing/queue.py5
8 files changed, 24 insertions, 19 deletions
diff --git a/setup.py b/setup.py
index 5fd510cbaf..b00db6b5d8 100644
--- a/setup.py
+++ b/setup.py
@@ -370,6 +370,10 @@ if IS_WINDOWS:
# structured exception handling (SEH)
# /DNOMINMAX removes builtin min/max functions
]
+ if sys.version_info[0] == 2:
+ # /bigobj increases number of sections in .obj file, which is needed to link
+ # against libaries in Python 2.7 under Windows
+ extra_compile_args.append('/bigobj')
else:
extra_compile_args = ['-std=c++11', '-Wno-write-strings',
# Python 2.6 requires -fno-strict-aliasing, see
diff --git a/torch/csrc/Generator.cpp b/torch/csrc/Generator.cpp
index 45086e231d..a33c820562 100644
--- a/torch/csrc/Generator.cpp
+++ b/torch/csrc/Generator.cpp
@@ -93,14 +93,14 @@ static PyObject * THPGenerator_manualSeed(THPGenerator *self, PyObject *seed)
static PyObject * THPGenerator_seed(THPGenerator *self)
{
HANDLE_TH_ERRORS
- return PyLong_FromUnsignedLong(self->cdata->seed());
+ return THPUtils_packUInt64(self->cdata->seed());
END_HANDLE_TH_ERRORS
}
static PyObject * THPGenerator_initialSeed(THPGenerator *self)
{
HANDLE_TH_ERRORS
- return PyLong_FromUnsignedLong(self->cdata->initialSeed());
+ return THPUtils_packUInt64(self->cdata->initialSeed());
END_HANDLE_TH_ERRORS
}
diff --git a/torch/csrc/THP.h b/torch/csrc/THP.h
index d89f1f3b11..d125c5537e 100644
--- a/torch/csrc/THP.h
+++ b/torch/csrc/THP.h
@@ -6,17 +6,6 @@
#include <TH/TH.h>
#include <THS/THS.h>
-// macros for Windows compatibility
-#ifdef _WIN32
-#undef PyLong_FromLong
-#undef PyLong_AsLong
-#undef PyLong_FromUnsignedLong
-
-#define PyLong_FromLong PyLong_FromLongLong
-#define PyLong_AsLong PyLong_AsLongLong
-#define PyLong_FromUnsignedLong PyLong_FromUnsignedLongLong
-#endif
-
#include "THP_export.h"
// Back-compatibility macros, Thanks to http://cx-oracle.sourceforge.net/
diff --git a/torch/csrc/autograd/functions/init.cpp b/torch/csrc/autograd/functions/init.cpp
index 0971785674..5572826db5 100644
--- a/torch/csrc/autograd/functions/init.cpp
+++ b/torch/csrc/autograd/functions/init.cpp
@@ -128,7 +128,7 @@ PyObject* getTensorAttr(PyObject* obj, void* _unused)
// specialization. So we write a little stub function which does have
// the right type.
static PyObject* PortablePyInt_FromLong(int64_t ival) {
- return PyInt_FromLong(ival);
+ return THPUtils_packInt64(ival);
}
static struct PyGetSetDef batch_norm_forward_properties[] = {
diff --git a/torch/csrc/autograd/python_function.cpp b/torch/csrc/autograd/python_function.cpp
index 4d47a211fb..65b792bcc0 100644
--- a/torch/csrc/autograd/python_function.cpp
+++ b/torch/csrc/autograd/python_function.cpp
@@ -1021,7 +1021,7 @@ PyObject *THPFunction_next_functions(THPFunction *self, void *_unused)
PyObject* fn = functionToPyObject(next_fns[i].first);
if (!fn) return NULL;
PyTuple_SET_ITEM(fn_tuple.get(), 0, fn);
- PyTuple_SET_ITEM(fn_tuple.get(), 1, PyInt_FromLong(next_fns[i].second));
+ PyTuple_SET_ITEM(fn_tuple.get(), 1, THPUtils_packInt64(next_fns[i].second));
PyTuple_SET_ITEM(result.get(), i, fn_tuple.release());
}
return result.release();
diff --git a/torch/csrc/cuda/Module.cpp b/torch/csrc/cuda/Module.cpp
index 9afa659529..98990224c6 100644
--- a/torch/csrc/cuda/Module.cpp
+++ b/torch/csrc/cuda/Module.cpp
@@ -236,21 +236,21 @@ PyObject * THCPModule_manualSeedAll(PyObject *_unused, PyObject *seed)
PyObject * THCPModule_seed(PyObject *_unused)
{
HANDLE_TH_ERRORS
- return PyLong_FromUnsignedLong(THCRandom_seed(state));
+ return THPUtils_packUInt64(THCRandom_seed(state));
END_HANDLE_TH_ERRORS
}
PyObject * THCPModule_seedAll(PyObject *_unused)
{
HANDLE_TH_ERRORS
- return PyLong_FromUnsignedLong(THCRandom_seedAll(state));
+ return THPUtils_packUInt64(THCRandom_seedAll(state));
END_HANDLE_TH_ERRORS
}
PyObject * THCPModule_initialSeed(PyObject *_unused)
{
HANDLE_TH_ERRORS
- return PyLong_FromUnsignedLong(THCRandom_initialSeed(state));
+ return THPUtils_packUInt64(THCRandom_initialSeed(state));
END_HANDLE_TH_ERRORS
}
diff --git a/torch/csrc/utils/python_numbers.h b/torch/csrc/utils/python_numbers.h
index ba08ec13ad..255e61375a 100644
--- a/torch/csrc/utils/python_numbers.h
+++ b/torch/csrc/utils/python_numbers.h
@@ -18,6 +18,15 @@ inline PyObject* THPUtils_packInt64(int64_t value) {
return PyLong_FromLongLong(value);
}
+inline PyObject* THPUtils_packUInt64(uint64_t value) {
+#if PY_MAJOR_VERSION == 2
+ if (value <= INT32_MAX) {
+ return PyInt_FromLong(static_cast<long>(value));
+ }
+#endif
+ return PyLong_FromUnsignedLongLong(value);
+}
+
inline PyObject* THPUtils_packDoubleAsInt(double value) {
#if PY_MAJOR_VERSION == 2
if (value <= INT32_MAX && value >= INT32_MIN) {
diff --git a/torch/multiprocessing/queue.py b/torch/multiprocessing/queue.py
index ad0a32b08b..9696ee4206 100644
--- a/torch/multiprocessing/queue.py
+++ b/torch/multiprocessing/queue.py
@@ -22,7 +22,10 @@ class ConnectionWrapper(object):
return pickle.loads(buf)
def __getattr__(self, name):
- return getattr(self.conn, name)
+ if 'conn' in self.__dict__:
+ return getattr(self.conn, name)
+ raise AttributeError("'{}' object has no attribute '{}'".format(
+ type(self).__name__, 'conn'))
class Queue(multiprocessing.queues.Queue):