Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 155de2c

Browse files
authored
Merge pull request #56 from abeaumont/feature/improve-error-handling
libuast: Bump to 1.4.1 and improve error handling
2 parents 4dc9f2a + 4b4372a commit 155de2c

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

bblfsh/pyuast.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,22 @@ static PyObject *PyFilter(PyObject *self, PyObject *args)
154154
return NULL;
155155

156156
Nodes *nodes = UastFilter(ctx, obj, query);
157-
if (nodes) {
158-
int len = NodesSize(nodes);
159-
PyObject *list = PyList_New(len);
160-
161-
for (int i = 0; i < len; i++) {
162-
PyObject *node = (PyObject *)NodeAt(nodes, i);
163-
Py_INCREF(node);
164-
PyList_SET_ITEM(list, i, node);
165-
}
166-
NodesFree(nodes);
167-
return PySeqIter_New(list);
157+
if (!nodes) {
158+
char *error = LastError();
159+
PyErr_SetString(PyExc_RuntimeError, error);
160+
free(error);
161+
return NULL;
168162
}
163+
int len = NodesSize(nodes);
164+
PyObject *list = PyList_New(len);
169165

166+
for (int i = 0; i < len; i++) {
167+
PyObject *node = (PyObject *)NodeAt(nodes, i);
168+
Py_INCREF(node);
169+
PyList_SET_ITEM(list, i, node);
170+
}
170171
NodesFree(nodes);
171-
return PySeqIter_New(PyList_New(0));
172+
return PySeqIter_New(list);
172173
}
173174

174175
static PyMethodDef extension_methods[] = {

bblfsh/test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ def testUASTFileContents(self):
5959
self._validate_filter(uast)
6060

6161
def testBrokenFilter(self):
62-
from sys import version_info
63-
if version_info[0:2] != (3, 4):
64-
# Skip test 3.4: cant capture SystemException from binary modules
65-
self.assertRaises(SystemError, filter, 0, "foo")
62+
self.assertRaises(RuntimeError, filter, 0, "foo")
6663

6764
def testFilterInternalType(self):
6865
node = Node()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from setuptools import setup, find_packages, Extension
66
from setuptools.command.build_ext import build_ext
77

8-
LIBUAST_VERSION = "v1.3.0"
8+
LIBUAST_VERSION = "v1.4.1"
99
SDK_VERSION = "v1.4.2"
1010
SDK_MAJOR = SDK_VERSION.split('.')[0]
1111
PYTHON = "python3"
@@ -123,7 +123,7 @@ def main():
123123
'bblfsh.pyuast',
124124
libraries=libraries,
125125
library_dirs=['/usr/lib', '/usr/local/lib'],
126-
extra_compile_args=['-std=c99'],
126+
extra_compile_args=['-std=gnu99'],
127127
include_dirs=['bblfsh/libuast/', '/usr/local/include', '/usr/local/include/libxml2',
128128
'/usr/include', '/usr/include/libxml2'], sources=sources)
129129

0 commit comments

Comments
 (0)