Skip to content

Commit 2d24468

Browse files
committed
In case of encode/decode error return empty data type, not False.
1 parent e38ac64 commit 2d24468

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ git clone https://github.com/mapcode-foundation/mapcode-cpp
5858
cd mapcode-python
5959
```
6060

61-
Compile the package in current directory: `python setup.py --inplace`
61+
Compile the package in current directory: `python setup.py build_ext --inplace`
6262
Install in your Python environment using: `python setup.py install`
6363

6464

65-
# Usage in Python
65+
# Python methods
6666

6767
## Mapcode syntax validation
6868

@@ -105,7 +105,7 @@ print mapcode.encode_single(52.376514, 4.908542)
105105
NLD 49.4V
106106

107107
For this coordinate there are multiple mapcodes possible, hence providing
108-
a territory code can give a different one.
108+
a territory code can give a different result.
109109

110110
print mapcode.encode_single(41.851944, 12.433114)
111111
ITA 0Z.0Z
@@ -133,7 +133,7 @@ print mapcode.encode(39.609999,45.949999, 'AZE')
133133

134134
## Decoding
135135

136-
Use the decode() method to decode a mapcode back to latitude and longitude.
136+
Use the decode() method to translate a mapcode back to latitude and longitude.
137137

138138
```python
139139
print mapcode.decode('NLD 49.4V')
@@ -161,5 +161,5 @@ A territory is require to give context to decoding:
161161
print mapcode.decode('IN VY.HV','USA')
162162
(39.72795, -86.118444)
163163
print mapcode.decode('IN VY.HV','RUS')
164-
(43.193485, 44.826592)```
165-
```
164+
(43.193485, 44.826592)
165+
```

mapcodemodule.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ static PyObject *decode(PyObject *self, PyObject *args)
7373
} else
7474
territorycode = 0;
7575

76-
if (decodeMapcodeToLatLon(&latitude, &longitude, mapcode, territorycode))
77-
return Py_False;
78-
79-
return Py_BuildValue("dd", latitude, longitude);
76+
if (decodeMapcodeToLatLon(&latitude, &longitude, mapcode, territorycode)) {
77+
/* return 999/999 as error values */
78+
latitude = 999;
79+
longitude = 999;
80+
}
81+
return Py_BuildValue("ff", latitude, longitude);
8082
}
8183

8284

@@ -103,7 +105,7 @@ static PyObject *encode(PyObject *self, PyObject *args)
103105
if (territoryname) {
104106
territorycode = convertTerritoryIsoNameToCode(territoryname, 0);
105107
if (territorycode < 0) {
106-
return Py_False;
108+
return PyList_New(0);
107109
}
108110
}
109111

@@ -119,7 +121,7 @@ static PyObject *encode(PyObject *self, PyObject *args)
119121
}
120122
return result;
121123
}
122-
return Py_False;
124+
return PyList_New(0);
123125
}
124126

125127

@@ -144,7 +146,7 @@ static PyObject *encode_single(PyObject *self, PyObject *args)
144146
if (territoryname) {
145147
territorycode = convertTerritoryIsoNameToCode(territoryname, 0);
146148
if (territorycode < 0)
147-
return Py_False;
149+
return Py_BuildValue("s", NULL);
148150
}
149151

150152
// printf("debug: encode_single: territorystring: %s, code: %d\n", territoryname, territorycode);
@@ -154,7 +156,7 @@ static PyObject *encode_single(PyObject *self, PyObject *args)
154156
result = Py_BuildValue("s", encode_single_result);
155157
return result;
156158
} else
157-
return Py_False;
159+
return Py_BuildValue("s", NULL);
158160
}
159161

160162

0 commit comments

Comments
 (0)