Skip to content
Permalink
Browse files
Mapscript python: fix 'ISO C90 forbids mixed declarations and code' w…
…arning, and convert line endings to Unix style
  • Loading branch information
rouault committed Sep 30, 2019
1 parent 95ddad7 commit 9c7ca891b7f6096906e13e659d5c085cedc65ad5
Showing 1 changed file with 34 additions and 35 deletions.
@@ -95,41 +95,40 @@ CreateTupleFromDoubleArray( double *first, unsigned int size ) {
* Typemap to turn a Python dict into two sequences and
* an item count. Used for msApplySubstitutions
*/
%typemap(in) (char **names, char **values, int npairs) {
/* Check if is a dict */
if (PyDict_Check($input)) {

int size = PyDict_Size($input);
$3 = size;
$1 = (char **) malloc((size+1)*sizeof(char *));
$2 = (char **) malloc((size+1)*sizeof(char *));
int i = 0;

PyObject* keys = PyDict_Keys($input);
PyObject* values = PyDict_Values($input);
PyObject *key;
PyObject *val;

for (i = 0; i < size; i++) {
key = PyList_GetItem(keys, i);
val = PyList_GetItem(values, i);

$1[i] = PyString_AsString(key);
$2[i] = PyString_AsString(val);
}

$1[i] = 0;
$2[i] = 0;

} else {
PyErr_SetString(PyExc_TypeError, "Input not a dictionary");
SWIG_fail;
}
}

%typemap(freearg) (char **names, char **values, int npairs) {
free((char *) $1);
free((char *) $2);
%typemap(in) (char **names, char **values, int npairs) {
/* Check if is a dict */
if (PyDict_Check($input)) {

int i = 0;
int size = PyDict_Size($input);

PyObject* keys = PyDict_Keys($input);
PyObject* values = PyDict_Values($input);

$3 = size;
$1 = (char **) malloc((size+1)*sizeof(char *));
$2 = (char **) malloc((size+1)*sizeof(char *));

for (i = 0; i < size; i++) {
PyObject* key = PyList_GetItem(keys, i);
PyObject* val = PyList_GetItem(values, i);

$1[i] = PyString_AsString(key);
$2[i] = PyString_AsString(val);
}

$1[i] = 0;
$2[i] = 0;

} else {
PyErr_SetString(PyExc_TypeError, "Input not a dictionary");
SWIG_fail;
}
}

%typemap(freearg) (char **names, char **values, int npairs) {
free((char *) $1);
free((char *) $2);
}

/**************************************************************************

3 comments on commit 9c7ca89

@rouault
Copy link
Contributor Author

@rouault rouault commented on 9c7ca89 Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @geographika . You might want to check the settings of your text editor, so that it respects the line ending of the files you edit (most of them should be Unix style hopefully)

@geographika
Copy link
Member

@geographika geographika commented on 9c7ca89 Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rouault thanks for the warning. The line ending extension in Visual Studio I have is set up for C files but not .i files. Is there anyway you know to add automatic linting to Travis to fail these pull requests?

@rouault
Copy link
Contributor Author

@rouault rouault commented on 9c7ca89 Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway you know to add automatic linting to Travis to fail these pull requests?

some script that would check the output of the file utility ?

Please sign in to comment.