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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
7462ac5a
Commit
7462ac5a
authored
Feb 01, 2013
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Undo a couple of documentation fixes (where the old style was intentional).
parent
365b547f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
34 deletions
+35
-34
docs/src/tutorial/caveats.rst
docs/src/tutorial/caveats.rst
+1
-1
docs/src/tutorial/queue_example/queue.pyx
docs/src/tutorial/queue_example/queue.pyx
+5
-4
docs/src/userguide/extension_types.rst
docs/src/userguide/extension_types.rst
+6
-6
docs/src/userguide/external_C_code.rst
docs/src/userguide/external_C_code.rst
+6
-6
docs/src/userguide/language_basics.rst
docs/src/userguide/language_basics.rst
+16
-16
docs/src/userguide/sharing_declarations.rst
docs/src/userguide/sharing_declarations.rst
+1
-1
No files found.
docs/src/tutorial/caveats.rst
View file @
7462ac5a
...
@@ -9,7 +9,7 @@ for Python users, so this list may change in the future.
...
@@ -9,7 +9,7 @@ for Python users, so this list may change in the future.
- Given two typed ``int`` variables ``a`` and ``b``, ``a % b`` has the
- Given two typed ``int`` variables ``a`` and ``b``, ``a % b`` has the
same sign as the second argument (following Python semantics) rather than
same sign as the second argument (following Python semantics) rather than
having the same sign as the first (as in C). The C behavior can be
having the same sign as the first (as in C). The C behavior can be
obtained, at some speed gain, by enabling the division directive
obtained, at some speed gain, by enabling the
c
division directive
(versions prior to Cython 0.12 always followed C semantics).
(versions prior to Cython 0.12 always followed C semantics).
- Care is needed with unsigned types. ``cdef unsigned n = 10;
- Care is needed with unsigned types. ``cdef unsigned n = 10;
print(range(-n, n))`` will print an empty list, since ``-n`` wraps
print(range(-n, n))`` will print an empty list, since ``-n`` wraps
...
...
docs/src/tutorial/queue_example/queue.pyx
View file @
7462ac5a
...
@@ -8,7 +8,8 @@ cdef class Queue:
...
@@ -8,7 +8,8 @@ cdef class Queue:
def
__cinit__
(
self
):
def
__cinit__
(
self
):
self
.
_c_queue
=
cqueue
.
queue_new
()
self
.
_c_queue
=
cqueue
.
queue_new
()
if
self
.
_c_queue
is
NULL
:
if
self
.
_c_queue
is
NULL
:
raise
MemoryError
()
# raise MemoryError() allocates memory
python_exc
.
PyErr_NoMemory
()
def
__dealloc__
(
self
):
def
__dealloc__
(
self
):
if
self
.
_c_queue
is
not
NULL
:
if
self
.
_c_queue
is
not
NULL
:
...
@@ -16,14 +17,14 @@ cdef class Queue:
...
@@ -16,14 +17,14 @@ cdef class Queue:
cpdef
int
append
(
self
,
int
value
)
except
-
1
:
cpdef
int
append
(
self
,
int
value
)
except
-
1
:
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
value
):
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
value
):
raise
MemoryError
()
python_exc
.
PyErr_NoMemory
()
return
0
return
0
cdef
int
extend
(
self
,
int
*
values
,
Py_ssize_t
count
)
except
-
1
:
cdef
int
extend
(
self
,
int
*
values
,
Py_ssize_t
count
)
except
-
1
:
cdef
Py_ssize_t
i
cdef
Py_ssize_t
i
for
i
in
range
(
count
):
for
i
in
range
(
count
):
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
values
[
i
]):
if
not
cqueue
.
queue_push_tail
(
self
.
_c_queue
,
<
void
*>
values
[
i
]):
raise
MemoryError
()
python_exc
.
PyErr_NoMemory
()
return
0
return
0
cpdef
int
peek
(
self
)
except
?
0
:
cpdef
int
peek
(
self
)
except
?
0
:
...
@@ -44,7 +45,7 @@ cdef class Queue:
...
@@ -44,7 +45,7 @@ cdef class Queue:
raise
IndexError
(
"Queue is empty"
)
raise
IndexError
(
"Queue is empty"
)
return
value
return
value
def
__bool__
(
self
):
def
__bool__
(
self
):
# or __nonzero__ for Python 2.x
return
not
cqueue
.
queue_is_empty
(
self
.
_c_queue
)
return
not
cqueue
.
queue_is_empty
(
self
.
_c_queue
)
DEF
repeat_count
=
10000
DEF
repeat_count
=
10000
...
...
docs/src/userguide/extension_types.rst
View file @
7462ac5a
...
@@ -104,7 +104,7 @@ follows::
...
@@ -104,7 +104,7 @@ follows::
Now the Cython compiler knows that ``sh`` has a C attribute called
Now the Cython compiler knows that ``sh`` has a C attribute called
:attr:`width` and will generate code to access it directly and efficiently.
:attr:`width` and will generate code to access it directly and efficiently.
The same consideration applies to local variables, for example::
The same consideration applies to local variables, for example
,
::
cdef Shrubbery another_shrubbery(Shrubbery sh1):
cdef Shrubbery another_shrubbery(Shrubbery sh1):
cdef Shrubbery sh2
cdef Shrubbery sh2
...
@@ -396,7 +396,7 @@ that need to refer to each other, e.g.::
...
@@ -396,7 +396,7 @@ that need to refer to each other, e.g.::
If you are forward-declaring an extension type that has a base class, you must
If you are forward-declaring an extension type that has a base class, you must
specify the base class in both the forward declaration and its subsequent
specify the base class in both the forward declaration and its subsequent
definition, for example::
definition, for example
,
::
cdef class A(B)
cdef class A(B)
...
@@ -410,7 +410,7 @@ Making extension types weak-referenceable
...
@@ -410,7 +410,7 @@ Making extension types weak-referenceable
By default, extension types do not support having weak references made to
By default, extension types do not support having weak references made to
them. You can enable weak referencing by declaring a C attribute of type
them. You can enable weak referencing by declaring a C attribute of type
object called :attr:`__weakref__`. For example::
object called :attr:`__weakref__`. For example
,
::
cdef class ExplodingAnimal:
cdef class ExplodingAnimal:
"""This animal will self-destruct when it is
"""This animal will self-destruct when it is
...
@@ -507,7 +507,7 @@ Implicit importing
...
@@ -507,7 +507,7 @@ Implicit importing
------------------
------------------
Cython requires you to include a module name in an extern extension class
Cython requires you to include a module name in an extern extension class
declaration, for example::
declaration, for example
,
::
cdef extern class MyModule.Spam:
cdef extern class MyModule.Spam:
...
...
...
@@ -521,13 +521,13 @@ example an implicit::
...
@@ -521,13 +521,13 @@ example an implicit::
statement will be executed at module load time.
statement will be executed at module load time.
The module name can be a dotted name to refer to a module inside a package
The module name can be a dotted name to refer to a module inside a package
hierarchy, for example::
hierarchy, for example
,
::
cdef extern class My.Nested.Package.Spam:
cdef extern class My.Nested.Package.Spam:
...
...
You can also specify an alternative name under which to import the type using
You can also specify an alternative name under which to import the type using
an as clause, for example::
an as clause, for example
,
::
cdef extern class My.Nested.Package.Spam as Yummy:
cdef extern class My.Nested.Package.Spam as Yummy:
...
...
...
...
docs/src/userguide/external_C_code.rst
View file @
7462ac5a
...
@@ -24,7 +24,7 @@ External declarations
...
@@ -24,7 +24,7 @@ External declarations
By default, C functions and variables declared at the module level are local
By default, C functions and variables declared at the module level are local
to the module (i.e. they have the C static storage class). They can also be
to the module (i.e. they have the C static storage class). They can also be
declared extern to specify that they are defined elsewhere, for example::
declared extern to specify that they are defined elsewhere, for example
,
::
cdef extern int spam_counter
cdef extern int spam_counter
...
@@ -87,7 +87,7 @@ match the C ones, and in some cases they shouldn't or can't. In particular:
...
@@ -87,7 +87,7 @@ match the C ones, and in some cases they shouldn't or can't. In particular:
to platform-dependent flavours of numeric types, you will need a
to platform-dependent flavours of numeric types, you will need a
corresponding :keyword:`ctypedef` statement, but you don't need to match
corresponding :keyword:`ctypedef` statement, but you don't need to match
the type exactly, just use something of the right general kind (int, float,
the type exactly, just use something of the right general kind (int, float,
etc). For example::
etc). For example
,
::
ctypedef int word
ctypedef int word
...
@@ -185,7 +185,7 @@ Accessing Python/C API routines
...
@@ -185,7 +185,7 @@ Accessing Python/C API routines
---------------------------------
---------------------------------
One particular use of the ``cdef extern from`` statement is for gaining access to
One particular use of the ``cdef extern from`` statement is for gaining access to
routines in the Python/C API. For example::
routines in the Python/C API. For example
,
::
cdef extern from "Python.h":
cdef extern from "Python.h":
...
@@ -204,7 +204,7 @@ Windows Calling Conventions
...
@@ -204,7 +204,7 @@ Windows Calling Conventions
----------------------------
----------------------------
The ``__stdcall`` and ``__cdecl`` calling convention specifiers can be used in
The ``__stdcall`` and ``__cdecl`` calling convention specifiers can be used in
Cython, with the same syntax as used by C compilers on Windows, for example::
Cython, with the same syntax as used by C compilers on Windows, for example
,
::
cdef extern int __stdcall FrobnicateWindow(long handle)
cdef extern int __stdcall FrobnicateWindow(long handle)
...
@@ -245,7 +245,7 @@ Cython keywords. For example, if you want to call an external function called
...
@@ -245,7 +245,7 @@ Cython keywords. For example, if you want to call an external function called
print, you can rename it to something else in your Cython module.
print, you can rename it to something else in your Cython module.
As well as functions, C names can be specified for variables, structs, unions,
As well as functions, C names can be specified for variables, structs, unions,
enums, struct and union members, and enum values. For example::
enums, struct and union members, and enum values. For example
,
::
cdef extern int one "ein", two "zwei"
cdef extern int one "ein", two "zwei"
cdef extern float three "drei"
cdef extern float three "drei"
...
@@ -388,7 +388,7 @@ Multiple public and API declarations
...
@@ -388,7 +388,7 @@ Multiple public and API declarations
You can declare a whole group of items as :keyword:`public` and/or
You can declare a whole group of items as :keyword:`public` and/or
:keyword:`api` all at once by enclosing them in a :keyword:`cdef` block, for
:keyword:`api` all at once by enclosing them in a :keyword:`cdef` block, for
example::
example
,
::
cdef public api:
cdef public api:
void order_spam(int tons)
void order_spam(int tons)
...
...
docs/src/userguide/language_basics.rst
View file @
7462ac5a
...
@@ -27,8 +27,8 @@ and C :keyword:`struct`, :keyword:`union` or :keyword:`enum` types::
...
@@ -27,8 +27,8 @@ and C :keyword:`struct`, :keyword:`union` or :keyword:`enum` types::
float volume
float volume
cdef union Food:
cdef union Food:
char
*
spam
char
*
spam
float
*
eggs
float
*
eggs
cdef enum CheeseType:
cdef enum CheeseType:
cheddar, edam,
cheddar, edam,
...
@@ -42,7 +42,7 @@ and C :keyword:`struct`, :keyword:`union` or :keyword:`enum` types::
...
@@ -42,7 +42,7 @@ and C :keyword:`struct`, :keyword:`union` or :keyword:`enum` types::
See also :ref:`struct-union-enum-styles`
See also :ref:`struct-union-enum-styles`
There is currently no special syntax for defining a constant, but you can use
There is currently no special syntax for defining a constant, but you can use
an anonymous :keyword:`enum` declaration for this purpose, for example::
an anonymous :keyword:`enum` declaration for this purpose, for example
,
::
cdef enum:
cdef enum:
tons_of_spam = 3
tons_of_spam = 3
...
@@ -52,11 +52,11 @@ an anonymous :keyword:`enum` declaration for this purpose, for example::
...
@@ -52,11 +52,11 @@ an anonymous :keyword:`enum` declaration for this purpose, for example::
defining a type, not when referring to it. For example, to declare a variable
defining a type, not when referring to it. For example, to declare a variable
pointing to a ``Grail`` you would write::
pointing to a ``Grail`` you would write::
cdef Grail
*
gp
cdef Grail
*
gp
and not::
and not::
cdef struct Grail
*
gp # WRONG
cdef struct Grail
*
gp # WRONG
There is also a ``ctypedef`` statement for giving names to types, e.g.::
There is also a ``ctypedef`` statement for giving names to types, e.g.::
...
@@ -76,9 +76,9 @@ can group them into a :keyword:`cdef` block like this::
...
@@ -76,9 +76,9 @@ can group them into a :keyword:`cdef` block like this::
int i
int i
float f
float f
Spam
*
p
Spam
*
p
void f(Spam
*
s):
void f(Spam
*
s):
print s.tons, "Tons of spam"
print s.tons, "Tons of spam"
...
@@ -103,9 +103,9 @@ can be called from anywhere, but uses the faster C calling conventions
...
@@ -103,9 +103,9 @@ can be called from anywhere, but uses the faster C calling conventions
when being called from other Cython code.
when being called from other Cython code.
Parameters of either type of function can be declared to have C data types,
Parameters of either type of function can be declared to have C data types,
using normal C declaration syntax. For example::
using normal C declaration syntax. For example
,
::
def spam(int i, char
*
s):
def spam(int i, char
*
s):
...
...
cdef int eggs(unsigned long l, float f):
cdef int eggs(unsigned long l, float f):
...
@@ -144,7 +144,7 @@ parameters and a new reference is returned).
...
@@ -144,7 +144,7 @@ parameters and a new reference is returned).
The name object can also be used to explicitly declare something as a Python
The name object can also be used to explicitly declare something as a Python
object. This can be useful if the name being declared would otherwise be taken
object. This can be useful if the name being declared would otherwise be taken
as the name of a type, for example::
as the name of a type, for example
,
::
cdef ftang(object int):
cdef ftang(object int):
...
...
...
@@ -234,14 +234,14 @@ It's important to understand that the except clause does not cause an error to
...
@@ -234,14 +234,14 @@ It's important to understand that the except clause does not cause an error to
be raised when the specified value is returned. For example, you can't write
be raised when the specified value is returned. For example, you can't write
something like::
something like::
cdef extern FILE *fopen(char
* filename, char*
mode) except NULL # WRONG!
cdef extern FILE *fopen(char
*filename, char *
mode) except NULL # WRONG!
and expect an exception to be automatically raised if a call to :func:`fopen`
and expect an exception to be automatically raised if a call to :func:`fopen`
returns ``NULL``. The except clause doesn't work that way; its only purpose is
returns ``NULL``. The except clause doesn't work that way; its only purpose is
for propagating Python exceptions that have already been raised, either by a Cython
for propagating Python exceptions that have already been raised, either by a Cython
function or a C function that calls Python/C API routines. To get an exception
function or a C function that calls Python/C API routines. To get an exception
from a non-Python-aware function such as :func:`fopen`, you will have to check the
from a non-Python-aware function such as :func:`fopen`, you will have to check the
return value and raise it yourself, for example::
return value and raise it yourself, for example
,
::
cdef FILE* p
cdef FILE* p
p = fopen("spam.txt", "r")
p = fopen("spam.txt", "r")
...
@@ -290,7 +290,7 @@ live long enough, you will need to copy the C string.
...
@@ -290,7 +290,7 @@ live long enough, you will need to copy the C string.
Cython detects and prevents some mistakes of this kind. For instance, if you
Cython detects and prevents some mistakes of this kind. For instance, if you
attempt something like::
attempt something like::
cdef char
*
s
cdef char
*
s
s = pystring1 + pystring2
s = pystring1 + pystring2
then Cython will produce the error message ``Obtaining char* from temporary
then Cython will produce the error message ``Obtaining char* from temporary
...
@@ -304,7 +304,7 @@ compile it.
...
@@ -304,7 +304,7 @@ compile it.
The solution is to assign the result of the concatenation to a Python
The solution is to assign the result of the concatenation to a Python
variable, and then obtain the ``char*`` from that, i.e.::
variable, and then obtain the ``char*`` from that, i.e.::
cdef char
*
s
cdef char
*
s
p = pystring1 + pystring2
p = pystring1 + pystring2
s = p
s = p
...
@@ -347,7 +347,7 @@ direct equivalent in Python.
...
@@ -347,7 +347,7 @@ direct equivalent in Python.
* There is no unary ``*`` operator in Cython. Instead of ``*p``, use ``p[0]``
* There is no unary ``*`` operator in Cython. Instead of ``*p``, use ``p[0]``
* There is an ``&`` operator, with the same semantics as in C.
* There is an ``&`` operator, with the same semantics as in C.
* The null C pointer is called ``NULL``, not ``0`` (and ``NULL`` is a reserved word).
* The null C pointer is called ``NULL``, not ``0`` (and ``NULL`` is a reserved word).
* Type casts are written ``<type>value`` , for example::
* Type casts are written ``<type>value`` , for example
,
::
cdef char* p, float* q
cdef char* p, float* q
p = <char*>q
p = <char*>q
...
@@ -489,7 +489,7 @@ The include statement
...
@@ -489,7 +489,7 @@ The include statement
Use :ref:`sharing-declarations` instead.
Use :ref:`sharing-declarations` instead.
A Cython source file can include material from other files using the include
A Cython source file can include material from other files using the include
statement, for example::
statement, for example
,
::
include "spamstuff.pxi"
include "spamstuff.pxi"
...
...
docs/src/userguide/sharing_declarations.rst
View file @
7462ac5a
...
@@ -160,7 +160,7 @@ Sharing C Functions
...
@@ -160,7 +160,7 @@ Sharing C Functions
C functions defined at the top level of a module can be made available via
C functions defined at the top level of a module can be made available via
:keyword:`cimport` by putting headers for them in the ``.pxd`` file, for
:keyword:`cimport` by putting headers for them in the ``.pxd`` file, for
example::
example
,
::
:file:`volume.pxd`::
:file:`volume.pxd`::
...
...
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