blob: ca0f0ffe1a404f2ce2cf0c2f65af574d8b078f0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import cython
from libc.stdlib cimport malloc
from libc.stdlib cimport free
cdef extern from "librns510.h":
void librns510_encode(const char *lat, const char *lon, char *code)
cdef extern from "librns510.h":
char *librns510_decode(const char *code, char *lat, char *lon)
def encode(char *lat, char *lon):
assert lat is not NULL
assert lon is not NULL
cdef bytes py_string
cdef char *out
out=<char *> malloc(128)
librns510_encode(lat,lon,out)
try:
py_string=out
finally:
free(out)
return py_string
def decode(char *code):
assert code is not NULL
cdef bytes py_lat
cdef bytes py_lon
cdef char *lat
cdef char *lon
lat=<char *> malloc(128)
lon=<char *> malloc(128)
librns510_decode(code,lat,lon)
try:
py_lat=lat
finally:
free(lat)
try:
py_lon=lon
finally:
free(lon)
return py_lat,py_lon
|