from textwrap import dedent
stats = module_node.body.stats
for name, (statlistnode, scope) in self.pxds.iteritems():
- stats.append(statlistnode)
+ stats.append(statlistnode)
return module_node
return ([
# The pxd pipeline ends up with a CCodeWriter containing the
# code of the pxd, as well as a pxd scope.
return [parse_pxd] + self.create_pipeline(pxd=True) + [
- ExtractPxdCode(self)
+ ExtractPxdCode(self),
]
def process_pxd(self, source_desc, 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):
return Errors.report_error(exc)
def run_pipeline(self, pipeline, source):
- errors_occurred = False
+ err = None
data = source
try:
for phase in pipeline:
if phase is not None:
data = phase(data)
except CompileError, err:
- errors_occurred = True
+ # err is set
Errors.report_error(err)
- return (errors_occurred, data)
+ return (err, data)
def find_module(self, module_name,
relative_to = None, pos = None, need_pxd = 1):
if debug_find_module:
print("Context.find_module: Parsing %s" % 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)
except CompileError:
pass
else:
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
if not isinstance(source_desc, FileSourceDescriptor):
raise RuntimeError("Only file sources for code supported")
Errors.close_listing_file()
result.num_errors = Errors.num_errors
if result.num_errors > 0:
- errors_occurred = True
- if errors_occurred and result.c_file:
+ err = True
+ if err and result.c_file:
try:
Utils.castrate_file(result.c_file, os.stat(source_desc.filename))
except EnvironmentError:
pipeline = context.create_pyx_pipeline(options, result)
context.setup_errors(options)
- errors_occurred, enddata = context.run_pipeline(pipeline, source)
- context.teardown_errors(errors_occurred, options, result)
+ err, enddata = context.run_pipeline(pipeline, source)
+ context.teardown_errors(err, options, result)
return result
#------------------------------------------------------------------------
cdef extern from "numpy/arrayobject.h":
ctypedef void PyArrayObject
+ int PyArray_TYPE(PyObject* arr)
ctypedef class numpy.ndarray [object PyArrayObject]:
cdef:
object weakreflist
def __getbuffer__(self, Py_buffer* info, int flags):
- print "hello" + str(43) + "asdf" + "three"
- pass
+ cdef int typenum = PyArray_TYPE(self)
+
+
+## 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