Skip to content

Commit cc7af49

Browse files
authored
Issue 224: define empty python string with Py_CONSTANT_EMPTY_STR (#228)
* define empty python string with Py_CONSTANT_EMPTY_STR * support older versions of python * update config
1 parent 00d7206 commit cc7af49

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def add_filters(filters, pkgs, pkgs_data):
150150
# ----------------------------------------------------------------------------
151151
# set compiler options
152152
# ----------------------------------------------------------------------------
153-
if sys.platform == "win32":
154-
pass
153+
if sys.platform in ["win32", "win64"]:
154+
arguments = ['/std:c++17']
155155
else:
156156
# old version
157157
# arguments = ['-std=c++17', '-Wall', '-Wextra',

src/cpp/h5cpp/numpy/hdf5_variable_strings_support.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,27 @@ struct VarLengthStringTrait<numpy::ArrayAdapter>
116116
PyObject ***dataptr = (PyObject***)NpyIter_GetDataPtrArray(iter);
117117
for(auto string: buffer)
118118
{
119+
PyObject *ptr;
119120
if(string == NULL)
120121
{
121122
char empty[] = {'\0'};
122123
string = empty;
124+
#if PY_VERSION_HEX >= 0x030d0000
125+
ptr = Py_GetConstant(Py_CONSTANT_EMPTY_STR);
126+
#elif PY_MAJOR_VERSION >= 3
127+
ptr = PyUnicode_FromString(string);
128+
#else
129+
ptr = PyString_FromString(string);
130+
#endif
123131
}
132+
else
133+
{
124134
#if PY_MAJOR_VERSION >= 3
125-
PyObject *ptr = PyUnicode_FromString(string);
135+
ptr = PyUnicode_FromString(string);
126136
#else
127-
PyObject *ptr = PyString_FromString(string);
137+
ptr = PyString_FromString(string);
128138
#endif
139+
}
129140
if(ptr==NULL)
130141
{
131142
std::cerr<<"could not create python string!"<<std::endl;

0 commit comments

Comments
 (0)