Commit bba475cf authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Handle errors during pxd compile correctly

parent c370f942
...@@ -492,12 +492,12 @@ def use_py2_buffer_functions(env): ...@@ -492,12 +492,12 @@ def use_py2_buffer_functions(env):
find_buffer_types(env) find_buffer_types(env)
# For now, hard-code numpy imported as "numpy" # For now, hard-code numpy imported as "numpy"
try: # try:
ndarrtype = env.entries[u'numpy'].as_module.entries['ndarray'].type # ndarrtype = env.entries[u'numpy'].as_module.entries['ndarray'].type
types.append((ndarrtype.typeptr_cname, "numpy_getbuffer", "numpy_releasebuffer")) # types.append((ndarrtype.typeptr_cname, "numpy_getbuffer", "numpy_releasebuffer"))
env.use_utility_code(numpy_code) # env.use_utility_code(numpy_code)
except KeyError: # except KeyError:
pass # pass
code = dedent(""" code = dedent("""
#if PY_VERSION_HEX < 0x02060000 #if PY_VERSION_HEX < 0x02060000
......
...@@ -136,27 +136,28 @@ class Context: ...@@ -136,27 +136,28 @@ class Context:
# The pxd pipeline ends up with a CCodeWriter containing the # The pxd pipeline ends up with a CCodeWriter containing the
# code of the pxd, as well as a pxd scope. # code of the pxd, as well as a pxd scope.
return [parse_pxd] + self.create_pipeline(pxd=True) + [ return [parse_pxd] + self.create_pipeline(pxd=True) + [
ExtractPxdCode(self) ExtractPxdCode(self),
] ]
def process_pxd(self, source_desc, scope, module_name): def process_pxd(self, source_desc, scope, module_name):
pipeline = self.create_pxd_pipeline(scope, module_name) pipeline = self.create_pxd_pipeline(scope, module_name)
return self.run_pipeline(pipeline, source_desc) result = self.run_pipeline(pipeline, source_desc)
return result
def nonfatal_error(self, exc): def nonfatal_error(self, exc):
return Errors.report_error(exc) return Errors.report_error(exc)
def run_pipeline(self, pipeline, source): def run_pipeline(self, pipeline, source):
errors_occurred = False err = None
data = source data = source
try: try:
for phase in pipeline: for phase in pipeline:
if phase is not None: if phase is not None:
data = phase(data) data = phase(data)
except CompileError, err: except CompileError, err:
errors_occurred = True # err is set
Errors.report_error(err) Errors.report_error(err)
return (errors_occurred, data) return (err, data)
def find_module(self, module_name, def find_module(self, module_name,
relative_to = None, pos = None, need_pxd = 1): relative_to = None, pos = None, need_pxd = 1):
...@@ -210,7 +211,10 @@ class Context: ...@@ -210,7 +211,10 @@ class Context:
if debug_find_module: if debug_find_module:
print("Context.find_module: Parsing %s" % pxd_pathname) print("Context.find_module: Parsing %s" % pxd_pathname)
source_desc = FileSourceDescriptor(pxd_pathname) source_desc = FileSourceDescriptor(pxd_pathname)
errors_occured, (pxd_codenodes, pxd_scope) = self.process_pxd(source_desc, scope, module_name) err, result = self.process_pxd(source_desc, scope, module_name)
if err:
raise err
(pxd_codenodes, pxd_scope) = result
self.pxds[module_name] = (pxd_codenodes, pxd_scope) self.pxds[module_name] = (pxd_codenodes, pxd_scope)
except CompileError: except CompileError:
pass pass
...@@ -409,15 +413,15 @@ class Context: ...@@ -409,15 +413,15 @@ class Context:
else: else:
Errors.open_listing_file(None) Errors.open_listing_file(None)
def teardown_errors(self, errors_occurred, options, result): def teardown_errors(self, err, options, result):
source_desc = result.compilation_source.source_desc source_desc = result.compilation_source.source_desc
if not isinstance(source_desc, FileSourceDescriptor): if not isinstance(source_desc, FileSourceDescriptor):
raise RuntimeError("Only file sources for code supported") raise RuntimeError("Only file sources for code supported")
Errors.close_listing_file() Errors.close_listing_file()
result.num_errors = Errors.num_errors result.num_errors = Errors.num_errors
if result.num_errors > 0: if result.num_errors > 0:
errors_occurred = True err = True
if errors_occurred and result.c_file: if err and result.c_file:
try: try:
Utils.castrate_file(result.c_file, os.stat(source_desc.filename)) Utils.castrate_file(result.c_file, os.stat(source_desc.filename))
except EnvironmentError: except EnvironmentError:
...@@ -485,8 +489,8 @@ def run_pipeline(source, options, full_module_name = None): ...@@ -485,8 +489,8 @@ def run_pipeline(source, options, full_module_name = None):
pipeline = context.create_pyx_pipeline(options, result) pipeline = context.create_pyx_pipeline(options, result)
context.setup_errors(options) context.setup_errors(options)
errors_occurred, enddata = context.run_pipeline(pipeline, source) err, enddata = context.run_pipeline(pipeline, source)
context.teardown_errors(errors_occurred, options, result) context.teardown_errors(err, options, result)
return result return result
#------------------------------------------------------------------------ #------------------------------------------------------------------------
......
...@@ -3,6 +3,7 @@ cdef extern from "Python.h": ...@@ -3,6 +3,7 @@ cdef extern from "Python.h":
cdef extern from "numpy/arrayobject.h": cdef extern from "numpy/arrayobject.h":
ctypedef void PyArrayObject ctypedef void PyArrayObject
int PyArray_TYPE(PyObject* arr)
ctypedef class numpy.ndarray [object PyArrayObject]: ctypedef class numpy.ndarray [object PyArrayObject]:
cdef: cdef:
...@@ -17,8 +18,45 @@ cdef extern from "numpy/arrayobject.h": ...@@ -17,8 +18,45 @@ cdef extern from "numpy/arrayobject.h":
object weakreflist object weakreflist
def __getbuffer__(self, Py_buffer* info, int flags): def __getbuffer__(self, Py_buffer* info, int flags):
print "hello" + str(43) + "asdf" + "three" cdef int typenum = PyArray_TYPE(self)
pass
## PyArrayObject *arr = (PyArrayObject*)obj;
## PyArray_Descr *type = (PyArray_Descr*)arr->descr;
## int typenum = PyArray_TYPE(obj);
## if (!PyTypeNum_ISNUMBER(typenum)) {
## PyErr_Format(PyExc_TypeError, "Only numeric NumPy types currently supported.");
## return -1;
## }
## /*
## NumPy format codes doesn't completely match buffer codes;
## seems safest to retranslate.
## 01234567890123456789012345*/
## const char* base_codes = "?bBhHiIlLqQfdgfdgO";
## char* format = (char*)malloc(4);
## char* fp = format;
## *fp++ = type->byteorder;
## if (PyTypeNum_ISCOMPLEX(typenum)) *fp++ = 'Z';
## *fp++ = base_codes[typenum];
## *fp = 0;
## view->buf = arr->data;
## view->readonly = !PyArray_ISWRITEABLE(obj);
## view->ndim = PyArray_NDIM(arr);
## view->strides = PyArray_STRIDES(arr);
## view->shape = PyArray_DIMS(arr);
## view->suboffsets = NULL;
## view->format = format;
## view->itemsize = type->elsize;
## view->internal = 0;
## return 0;
## print "hello" + str(43) + "asdf" + "three"
## pass
......
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