summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/string
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2021-06-15 21:11:59 +0200
committerStefan Behnel <stefan_ml@behnel.de>2021-06-15 21:11:59 +0200
commit0ab91a54bd2c54abf9c09a60cdf10bc8a271219a (patch)
tree4192f9c06f86b6e43b551490d1d7d5ccc8967aeb /docs/examples/tutorial/string
parentaf95806773086e3554fa0f27576c86ad7f200b8a (diff)
downloadcython-0ab91a54bd2c54abf9c09a60cdf10bc8a271219a.tar.gz
docs: Resolve several exception handling/propagation issues in the examples.
Diffstat (limited to 'docs/examples/tutorial/string')
-rw-r--r--docs/examples/tutorial/string/c_func.pyx5
1 files changed, 3 insertions, 2 deletions
diff --git a/docs/examples/tutorial/string/c_func.pyx b/docs/examples/tutorial/string/c_func.pyx
index 3c94587fe..4763f2671 100644
--- a/docs/examples/tutorial/string/c_func.pyx
+++ b/docs/examples/tutorial/string/c_func.pyx
@@ -8,7 +8,8 @@ cdef Py_ssize_t n = strlen(hello_world)
cdef char* c_call_returning_a_c_string():
cdef char* c_string = <char *> malloc((n + 1) * sizeof(char))
if not c_string:
- raise MemoryError()
+ return NULL # malloc failed
+
strcpy(c_string, hello_world)
return c_string
@@ -16,7 +17,7 @@ cdef char* c_call_returning_a_c_string():
cdef void get_a_c_string(char** c_string_ptr, Py_ssize_t *length):
c_string_ptr[0] = <char *> malloc((n + 1) * sizeof(char))
if not c_string_ptr[0]:
- raise MemoryError()
+ return # malloc failed
strcpy(c_string_ptr[0], hello_world)
length[0] = n