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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
cad5ced6
Commit
cad5ced6
authored
Mar 04, 2011
by
Lisandro Dalcin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add setjmp.pxd and tests
parent
42091eac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
Cython/Includes/libc/setjmp.pxd
Cython/Includes/libc/setjmp.pxd
+5
-0
tests/run/setjmp.pyx
tests/run/setjmp.pyx
+54
-0
No files found.
Cython/Includes/libc/setjmp.pxd
0 → 100644
View file @
cad5ced6
cdef
extern
from
"setjmp.h"
nogil
:
ctypedef
struct
jmp_buf
:
pass
int
setjmp
(
jmp_buf
STATE
)
void
longjmp
(
jmp_buf
STATE
,
int
VALUE
)
tests/run/setjmp.pyx
0 → 100644
View file @
cad5ced6
from
libc.setjmp
cimport
*
cdef
void
check_nonzero
(
jmp_buf
ctx
,
int
x
)
nogil
:
if
x
==
0
:
longjmp
(
ctx
,
1
)
def
nonzero
(
int
x
):
"""
>>> nonzero(-1)
True
>>> nonzero(0)
False
>>> nonzero(1)
True
>>> nonzero(2)
True
"""
cdef
jmp_buf
ctx
if
setjmp
(
ctx
)
==
0
:
check_nonzero
(
ctx
,
x
)
return
True
else
:
return
False
from
libc.string
cimport
strcpy
cdef
char
error_msg
[
256
]
cdef
jmp_buf
error_ctx
cdef
void
error
(
char
msg
[])
nogil
:
strcpy
(
error_msg
,
msg
)
longjmp
(
error_ctx
,
1
)
cdef
void
c_call
(
int
x
)
nogil
:
if
x
<=
0
:
error
(
b"expected a positive value"
)
def
execute_c_call
(
int
x
):
"""
>>> execute_c_call(+2)
>>> execute_c_call(+1)
>>> execute_c_call(+0)
Traceback (most recent call last):
...
RuntimeError: expected a positive value
>>> execute_c_call(-1)
Traceback (most recent call last):
...
RuntimeError: expected a positive value
"""
if
not
setjmp
(
error_ctx
):
c_call
(
x
)
else
:
raise
RuntimeError
(
error_msg
.
decode
())
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