Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
bba475cf
Commit
bba475cf
authored
Aug 02, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle errors during pxd compile correctly
parent
c370f942
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
21 deletions
+63
-21
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+6
-6
Cython/Compiler/Main.py
Cython/Compiler/Main.py
+17
-13
Cython/Includes/numpy.pxd
Cython/Includes/numpy.pxd
+40
-2
No files found.
Cython/Compiler/Buffer.py
View file @
bba475cf
...
@@ -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
...
...
Cython/Compiler/Main.py
View file @
bba475cf
...
@@ -113,7 +113,7 @@ class Context:
...
@@ -113,7 +113,7 @@ class Context:
from
textwrap
import
dedent
from
textwrap
import
dedent
stats
=
module_node
.
body
.
stats
stats
=
module_node
.
body
.
stats
for
name
,
(
statlistnode
,
scope
)
in
self
.
pxds
.
iteritems
():
for
name
,
(
statlistnode
,
scope
)
in
self
.
pxds
.
iteritems
():
stats
.
append
(
statlistnode
)
stats
.
append
(
statlistnode
)
return
module_node
return
module_node
return
([
return
([
...
@@ -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
):
err
ors_occurred
=
Fals
e
err
=
Non
e
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
(
err
ors_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
,
err
ors_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
:
err
ors_occurred
=
True
err
=
True
if
err
ors_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
)
err
ors_occurred
,
enddata
=
context
.
run_pipeline
(
pipeline
,
source
)
err
,
enddata
=
context
.
run_pipeline
(
pipeline
,
source
)
context
.
teardown_errors
(
err
ors_occurred
,
options
,
result
)
context
.
teardown_errors
(
err
,
options
,
result
)
return
result
return
result
#------------------------------------------------------------------------
#------------------------------------------------------------------------
...
...
Cython/Includes/numpy.pxd
View file @
bba475cf
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment