Commit 49e52342 authored by Keith Bennett's avatar Keith Bennett

Merge branch 'hotfix/2.4.11'

parents 6fe785cf f6561de5
......@@ -2,24 +2,29 @@
SDFDIR=../C
EXTDIR=../extension
PYTHONCMD=`which python`
clean=0
errcode=0
CFLAGS="-DSDF_DEBUG_ALL -D_XOPEN_SOURCE=600 -I$SDFDIR/include -L$SDFDIR/lib"
OPT="$CFLAGS -O3"
while getopts crdph name
while getopts crdph23 name
do
case $name in
c) clean=2 ;;
r) clean=1 ;;
d) OPT="$CFLAGS -g -O0 -Wall -Wno-unused-function -std=c99 -pedantic";
PYDBG="-g" ;;
2) PYTHONCMD=`which python2` ;;
3) PYTHONCMD=`which python3` ;;
h) cat <<EOF
build script options:
-c: Clean up files. Do not build anything.
-r: Rebuild. Clean up files and then build.
-d: Build with debugging flags enabled.
-2: Build for python2
-3: Build for python3
EOF
exit ;;
esac
......@@ -42,7 +47,7 @@ if [ $clean -le 1 ] ; then
gcc $OPT -o sdf2ascii sdf2ascii.c -lsdfc -ldl || errcode=1
gcc $OPT -o sdffilter sdffilter.c -lsdfc -ldl -lm || errcode=1
# Test if python is new enough for the --user flag
user=$(python -c 'import sys, os
user=$($PYTHONCMD -c 'import sys, os
newenough = sys.hexversion > 0x02060000
if newenough: sys.exit(newenough)
for p in sys.path:
......@@ -51,10 +56,10 @@ for p in sys.path:
break
sys.exit(newenough)')
if [ $? -eq 0 ]; then
CFLAGS="$OPT" python setup.py build $PYDBG -b pybuild install \
CFLAGS="$OPT" $PYTHONCMD setup.py build $PYDBG -b pybuild install \
--prefix="$user" --record pybuild/files.txt
else
CFLAGS="$OPT" python setup.py build $PYDBG -b pybuild install \
CFLAGS="$OPT" $PYTHONCMD setup.py build $PYDBG -b pybuild install \
--prefix= --user --record pybuild/files.txt
fi
which a2x > /dev/null 2>&1
......
......@@ -28,7 +28,7 @@
#include <mpi.h>
#endif
#define VERSION "2.4.10"
#define VERSION "2.4.11"
#define DBG_FLUSH() do { \
if (h && h->dbg_buf) { \
......
......@@ -49,7 +49,6 @@
#if PY_MAJOR_VERSION < 3
#define PyInt_FromLong PyLong_FromLong
#define PyASCII_FromString PyString_FromString
#define PyBytes_AsString PyString_AsString
#else
#define PyASCII_FromString PyUnicode_FromString
#endif
......@@ -204,6 +203,19 @@ static PyTypeObject SDFType = {
};
static inline char *PyBytes_As_C(PyObject *ob)
{
#if PY_MAJOR_VERSION < 3
return PyString_AsString(ob);
#else
PyObject *ascii = PyUnicode_AsASCIIString(ob);
char *str = PyBytes_AsString(ascii);
Py_DECREF(ascii);
return str;
#endif
}
/*
* Array type methods
******************************************************************************/
......@@ -925,7 +937,7 @@ static void extract_station_time_histories(sdf_file_t *h, PyObject *stations,
var_names = (char **)malloc(nvars*sizeof(char *));
for ( i=0; i<nvars; i++ ) {
sub = PyList_GetItem(variables, i);
var_names[i] = PyBytes_AsString(sub);
var_names[i] = PyBytes_As_C(sub);
if ( !var_names[i] ) {
free(var_names);
free(stat);
......@@ -1298,7 +1310,7 @@ static void dict_find_variable_ids(PyObject *dict, Block *station)
block = (Block*)value;
if (!block->b)
continue;
block_id = PyBytes_AsString(block->id);
block_id = PyBytes_As_C(block->id);
if (!block_id)
continue;
len = strlen(block_id) + 1;
......@@ -1316,7 +1328,7 @@ static void dict_find_variable_ids(PyObject *dict, Block *station)
if (!station->data) {
station->data = PyList_New(b->ndims);
if (!station->data) return;
if (!station->data) goto free_mem;
}
// Found one of our variable_ids. Insert it into the station list and
......@@ -1332,6 +1344,7 @@ static void dict_find_variable_ids(PyObject *dict, Block *station)
find[i] = find[i+1];
}
free_mem:
free(find);
return;
......@@ -1491,19 +1504,9 @@ static PyObject* SDF_read(PyObject *self, PyObject *args, PyObject *kw)
PyObject *key = PyTuple_GET_ITEM(item, 0);
PyObject *value = PyTuple_GET_ITEM(item, 1);
char *ckey, *ptr;
#if PY_MAJOR_VERSION >= 3
PyObject *ascii;
#endif
mangled = 0;
#if PY_MAJOR_VERSION < 3
ckey = strdup(PyBytes_AsString(key));
#else
ascii = PyUnicode_AsASCIIString(key);
ckey = strdup(PyBytes_AsString(ascii));
Py_DECREF(ascii);
#endif
ckey = strdup(PyBytes_As_C(key));
for (ptr = ckey; *ptr != '\0'; ptr++) {
if (*ptr >= '0' && *ptr <= '9')
......@@ -1580,7 +1583,7 @@ MOD_INIT(sdf)
if (!m)
return MOD_ERROR_VAL;
PyModule_AddStringConstant(m, "__version__", "2.4.10");
PyModule_AddStringConstant(m, "__version__", "2.4.11");
PyModule_AddStringConstant(m, "__commit_id__", SDF_COMMIT_ID);
PyModule_AddStringConstant(m, "__commit_date__", SDF_COMMIT_DATE);
s = sdf_get_library_commit_id();
......
......@@ -35,7 +35,7 @@
#include <mpi.h>
#endif
#define VERSION "2.4.10"
#define VERSION "2.4.11"
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment