Skip to content

Commit a1bc7ca

Browse files
Python3.7 support.
Signed-off-by: David Rebbe <drebbe@intrepidcs.com>
1 parent 99cbb42 commit a1bc7ca

4 files changed

Lines changed: 27 additions & 20 deletions

File tree

build_all.bat

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,26 @@ C:\Python33\scripts\pip install wheel twine
77
C:\Python34\scripts\pip install wheel twine
88
C:\Python35\scripts\pip install wheel twine
99
C:\Python36-32\scripts\pip install wheel twine
10+
C:\Python37-32\scripts\pip install wheel twine
1011

1112
C:\Python27-64\scripts\pip install wheel twine
1213
C:\Python34-64\scripts\pip install wheel twine
1314
C:\Python35-64\scripts\pip install wheel twine
15+
C:\Python36-64\scripts\pip install wheel twine
16+
C:\Python37-64\scripts\pip install wheel twine
1417

1518
C:\Python27\python setup.py sdist bdist_wheel
1619
C:\Python33\python setup.py sdist bdist_wheel
1720
C:\Python34\python setup.py sdist bdist_wheel
1821
C:\Python35\python setup.py sdist bdist_wheel
1922
C:\Python36-32\python setup.py sdist bdist_wheel
23+
C:\Python37-32\python setup.py sdist bdist_wheel
2024

2125

2226
C:\Python27-64\python setup.py sdist bdist_wheel
2327
C:\Python34-64\python setup.py sdist bdist_wheel
2428
C:\Python35-64\python setup.py sdist bdist_wheel
29+
C:\Python36-64\python setup.py sdist bdist_wheel
30+
C:\Python37-64\python setup.py sdist bdist_wheel
2531

26-
C:\Python34\scripts\twine upload dist/* -r pypitest
32+
REM C:\Python34\scripts\twine upload dist/* -r pypitest

include/defines.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
#define MODULE_DESCRIPTION "Copyright Intrepid Control Systems, Inc."
77
#define VSPY3_BUILD_VERSION 802
88

9+
10+
// https://bugs.python.org/issue28769
11+
// 2.x = char* PyString_AsString(return_value);
12+
// 3.0-3.6 = char* PyUnicode_AsUTF8(value);
13+
// 3.7 = const char* PyUnicode_AsUTF8(value);
14+
#if (PY_MAJOR_VERSION >= 3) && (PY_MINOR_VERSION >= 7)
15+
#define PyUniStr_AsStrOrUTF8(obj) (char*)PyUnicode_AsUTF8(obj)
16+
#elif (PY_MAJOR_VERSION >= 3)
17+
#define PyUniStr_AsStrOrUTF8(obj) PyUnicode_AsUTF8(obj)
18+
#else
19+
#define PyStrOrUni_AsStrOrUTF8(obj) PyString_AsString(obj)
20+
#endif
21+
922
// Enable use of generic device settings object in 803 or newer.
1023
#if !defined(USE_GENERIC_DEVICE_SETTINGS) && (VSPY3_BUILD_VERSION >= 803)
1124
#define USE_GENERIC_DEVICE_SETTINGS

src/exceptions.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ char *pyics_base36enc(int sn)
2727
Py_DECREF(name);
2828
return NULL;
2929
} else {
30-
#if PY_MAJOR_VERSION >= 3
31-
return PyUnicode_AsUTF8(return_value);
32-
#else
33-
return PyString_AsString(return_value);
34-
#endif
30+
PyUniStr_AsStrOrUTF8(return_value);
3531
}
3632
}
3733
Py_DECREF(module);
@@ -90,11 +86,7 @@ PyObject* _set_ics_exception_dev(PyObject* exception, PyObject* obj, char* msg,
9086
if (obj && PyNeoDevice_CheckExact(obj)) {
9187
ss << " (";
9288
// Grab the String "name" out of the NeoDeviceObject
93-
#if PY_MAJOR_VERSION >= 3
94-
char* name = PyUnicode_AsUTF8(PyNeoDevice_GetNeoDevice(obj)->name);
95-
#else
96-
char* name = PyString_AsString(PyNeoDevice_GetNeoDevice(obj)->name);
97-
#endif
89+
char* name = PyUniStr_AsStrOrUTF8(PyNeoDevice_GetNeoDevice(obj)->name);
9890
if (name) {
9991
ss << name << " ";
10092
}

src/methods.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -678,10 +678,10 @@ PyObject* meth_coremini_load(PyObject* self, PyObject* args)
678678
int data_size = 0;
679679
#if PY_MAJOR_VERSION >= 3
680680
if (PyUnicode_CheckExact(arg_data)) {
681-
char* file_name = PyUnicode_AsUTF8(arg_data);
681+
char* file_name = PyUniStr_AsStrOrUTF8(arg_data);
682682
#else
683683
if (PyString_Check(arg_data)) {
684-
char* file_name = PyString_AsString(arg_data);
684+
char* file_name = PyUniStr_AsStrOrUTF8(arg_data);
685685
#endif
686686
if (!file_name) {
687687
return set_ics_exception_dev(exception_runtime_error(), obj, "Failed to convert file path to string");
@@ -1195,11 +1195,7 @@ PyObject* meth_flash_devices(PyObject* self, PyObject* args)
11951195
PyObject* key, * value;
11961196
while (PyDict_Next(dict, &pos, &key, &value)) {
11971197
unsigned long id = PyLong_AsUnsignedLong(key);
1198-
#if PY_MAJOR_VERSION >= 3
1199-
char* path = PyUnicode_AsUTF8(value);
1200-
#else
1201-
char* path = PyString_AsString(value);
1202-
#endif
1198+
char* path = PyUniStr_AsStrOrUTF8(value);
12031199
if (!path) {
12041200
return NULL;
12051201
}
@@ -3555,10 +3551,10 @@ PyObject* meth_load_readbin(PyObject* self, PyObject* args)
35553551
int data_size = 0;
35563552
#if PY_MAJOR_VERSION >= 3
35573553
if (PyUnicode_CheckExact(arg_data)) {
3558-
char* file_name = PyUnicode_AsUTF8(arg_data);
3554+
char* file_name = PyUniStr_AsStrOrUTF8(arg_data);
35593555
#else
35603556
if (PyString_Check(arg_data)) {
3561-
char* file_name = PyString_AsString(arg_data);
3557+
char* file_name = PyUniStr_AsStrOrUTF8(arg_data);
35623558
#endif
35633559
if (!file_name) {
35643560
return set_ics_exception_dev(exception_runtime_error(), obj, "Failed to convert file path to string");

0 commit comments

Comments
 (0)