Commit f6159408 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Removed an outdated pxd, added a declaration of exc.pxd and made two examples for exceptions.

parent 7f3987e0
This diff is collapsed.
......@@ -153,6 +153,13 @@ cdef extern from "Python.h":
# PyErr_SetFromErrno(type);" when the system call returns an
# error.
PyObject* PyErr_SetFromErrnoWithFilenameObject(object type, object filenameObject) except NULL
# Similar to PyErr_SetFromErrno(), with the additional behavior
# that if filenameObject is not NULL, it is passed to the
# constructor of type as a third parameter.
# In the case of OSError exception, this is used to define
# the filename attribute of the exception instance.
PyObject* PyErr_SetFromErrnoWithFilename(object type, char *filename) except NULL
# Return value: Always NULL. Similar to PyErr_SetFromErrno(),
# with the additional behavior that if filename is not NULL, it is
......
......@@ -4,4 +4,4 @@ cdef extern from "string.h":
cdef char* data = "hfvcakdfagbcffvschvxcdfgccbcfhvgcsnfxjh"
cdef char* pos = strstr(needle='akd', haystack=data)
print(pos != NULL)
print(pos is not NULL)
from libc.stdio cimport FILE, fopen
from libc.stdlib cimport malloc, free
from cpython.exc cimport PyErr_SetFromErrnoWithFilenameObject
def main():
def open_file():
cdef FILE* p
p = fopen("spam.txt", "r")
if p == NULL:
raise OSError("Couldn't open the spam file")
# ...
if p is NULL:
PyErr_SetFromErrnoWithFilenameObject(OSError, "spam.txt")
...
def allocating_memory(number=10):
cdef double *my_array = <double *> malloc(number * sizeof(double))
if not my_array:
raise MemoryError()
...
free(my_array)
......@@ -419,7 +419,7 @@ compatible types.::
cdef void* ptr
def __dealloc__(self):
if self.ptr != NULL:
if self.ptr is not NULL:
free(self.ptr)
@staticmethod
......
......@@ -131,7 +131,7 @@ It currently supports OpenMP, but later on more backends might be supported.
with nogil, parallel():
local_buf = <int *> malloc(sizeof(int) * size)
if local_buf == NULL:
if local_buf is NULL:
abort()
# populate our local buffer in a sequential loop
......
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