Commit 9a7d4405 authored by Mark Florisson's avatar Mark Florisson

Refactor None checking code -- use NoneCheckNode everywhere

parent 3bbf6177
This diff is collapsed.
......@@ -127,6 +127,7 @@ class Node(object):
is_name = 0
is_none = 0
is_nonecheck = 0
is_literal = 0
is_terminator = 0
temps = None
......
/////////////// RaiseNoneAttrError.proto ///////////////
static CYTHON_INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname);
/////////////// RaiseNoneAttrError ///////////////
static CYTHON_INLINE void __Pyx_RaiseNoneAttributeError(const char* attrname) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", attrname);
}
/////////////// RaiseNoneIndexingError.proto ///////////////
static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void);
/////////////// RaiseNoneIndexingError ///////////////
static CYTHON_INLINE void __Pyx_RaiseNoneIndexingError(void) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
}
/////////////// RaiseNoneIterError.proto ///////////////
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);
......
......@@ -2120,6 +2120,10 @@ def test_dtype_object_scalar_assignment():
#
### Test slices that are set to None
#
# for none memoryview slice attribute testing, slicing, indexing, etc, see
# nonecheck.pyx
@testcase
def test_coerce_to_from_None(double[:] m1, double[:] m2 = None):
"""
......@@ -2130,56 +2134,6 @@ def test_coerce_to_from_None(double[:] m1, double[:] m2 = None):
"""
return m1, m2
@testcase
def test_noneslice_attrib(double[:] m):
"""
>>> test_noneslice_attrib(None)
'NoneType' object has no attribute 'copy'
'NoneType' object has no attribute 'T'
"""
cdef double[:] m2
with cython.nonecheck(True):
try:
m2 = m.copy()
except Exception, e:
print e.args[0]
try:
m2 = m.T
except Exception, e:
print e.args[0]
@testcase
def test_noneslice_index(double[:] m):
"""
>>> test_noneslice_index(None)
Cannot index None memoryview slice
Cannot index None memoryview slice
Cannot index None memoryview slice
Cannot index None memoryview slice
"""
with cython.nonecheck(True):
try:
a = m[10]
except Exception, e:
print e.args[0]
try:
b = m[:]
except Exception, e:
print e.args[0]
try:
m[10] = 2
except Exception, e:
print e.args[0]
try:
m[:] = 2
except Exception, e:
print e.args[0]
@testcase
def test_noneslice_compare(double[:] m):
"""
......
......@@ -88,3 +88,85 @@ def check_buffer_set(object[int] buf):
TypeError: 'NoneType' object is not subscriptable
"""
buf[0] = 1
@cython.nonecheck(True)
def test_memslice_get(double[:] buf):
"""
>>> test_memslice_get(None)
Traceback (most recent call last):
TypeError: Cannot index None memoryview slice
"""
return buf[0]
@cython.nonecheck(True)
def test_memslice_set(double[:] buf):
"""
>>> test_memslice_set(None)
Traceback (most recent call last):
TypeError: Cannot index None memoryview slice
"""
buf[0] = 1.0
@cython.nonecheck(True)
def test_memslice_copy(double[:] buf):
"""
>>> test_memslice_copy(None)
Traceback (most recent call last):
AttributeError: Cannot access 'copy' attribute of None memoryview slice
"""
cdef double[:] copy = buf.copy()
@cython.nonecheck(True)
def test_memslice_transpose(double[:] buf):
"""
>>> test_memslice_transpose(None)
Traceback (most recent call last):
AttributeError: Cannot transpose None memoryview slice
"""
cdef double[:] T = buf.T
@cython.nonecheck(True)
def test_memslice_shape(double[:] buf):
"""
>>> test_memslice_shape(None)
Traceback (most recent call last):
AttributeError: Cannot access 'shape' attribute of None memoryview slice
"""
cdef Py_ssize_t extent = buf.shape[0]
@cython.nonecheck(True)
def test_memslice_slice(double[:] buf):
"""
>>> test_memslice_slice(None)
Traceback (most recent call last):
TypeError: Cannot slice None memoryview slice
"""
cdef double[:] sliced = buf[1:]
@cython.nonecheck(True)
def test_memslice_slice2(double[:] buf):
"""
Should this raise an error? It may not slice at all.
>>> test_memslice_slice(None)
Traceback (most recent call last):
TypeError: Cannot slice None memoryview slice
"""
cdef double[:] sliced = buf[:]
@cython.nonecheck(True)
def test_memslice_slice_assign(double[:] buf):
"""
>>> test_memslice_slice_assign(None)
Traceback (most recent call last):
TypeError: Cannot assign to None memoryview slice
"""
buf[...] = 2
@cython.nonecheck(True)
def test_memslice_slice_assign2(double[:] buf):
"""
>>> test_memslice_slice_assign2(None)
Traceback (most recent call last):
TypeError: Cannot slice None memoryview slice
"""
buf[:] = buf[::-1]
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