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
2a053274
Commit
2a053274
authored
Jan 20, 2011
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mention standard cimport files in clibraries tutorial
parent
2d3d7be9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
src/tutorial/clibraries.rst
src/tutorial/clibraries.rst
+17
-9
No files found.
src/tutorial/clibraries.rst
View file @
2a053274
...
...
@@ -96,8 +96,21 @@ but maps to Python's boolean values ``True`` and ``False`` when
converted to a Python object. This way of tightening declarations in
a ``.pxd`` file can often simplify the code that uses them.
After declaring our C library, we can start to design the Queue class
that should wrap the C queue. It will live in a file called
It is good practice to define one ``.pxd`` file for each library that
you use, and sometimes even for each header file (or functional group)
if the API is large. That simplifies their reuse in other projects.
Sometimes, you may need to use C functions from the standard C
library, or want to call C-API functions from CPython directly. For
common needs like this, Cython ships with a set of standard ``.pxd``
files that provide these declarations in a readily usable way that is
adapted to their use in Cython. The main packages are ``cpython``,
``libc`` and ``libcpp``. The NumPy library also has a standard
``.pxd`` file ``numpy``, as it is often used in Cython code. See
Cython'
s
``
Cython
/
Includes
/``
source
package
for
a
complete
list
of
provided
``.
pxd
``
files
.
After
declaring
our
C
library
's API, we can start to design the Queue
class that should wrap the C queue. It will live in a file called
``queue.pyx``. [#]_
.. [#] Note that the name of the ``.pyx`` file must be different from
...
...
@@ -166,16 +179,11 @@ We can thus change the init function as follows::
exception
instance
in
order
to
raise
it
may
actually
fail
because
we
are
running
out
of
memory
.
Luckily
,
CPython
provides
a
C
-
API
function
``
PyErr_NoMemory
()``
that
safely
raises
the
right
exception
for
us
.
As
of
version
0.14.1
,
Cython
automatically
exception
for
us
.
Since
version
0.14.1
,
Cython
automatically
substitutes
this
C
-
API
call
whenever
you
write
``
raise
MemoryError
``
or
``
raise
MemoryError
()``.
If
you
use
an
older
version
,
you
have
to
cimport
the
C
-
API
function
from
the
standard
package
``
cpython
.
exc
``
and
call
it
directly
.
This
package
contains
pre
-
defined
``.
pxd
``
files
that
ship
with
Cython
.
If
you
need
any
CPython
C
-
API
functions
,
you
can
cimport
them
from
there
.
See
Cython
's ``Cython/Includes/`` source package for a complete
list of provided ``.pxd`` files, including parts of the standard C
library.
package
``
cpython
.
exc
``
and
call
it
directly
.
The
next
thing
to
do
is
to
clean
up
when
the
Queue
instance
is
no
longer
used
(
i
.
e
.
all
references
to
it
have
been
deleted
).
To
this
...
...
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