Commit 7462ac5a authored by Robert Bradshaw's avatar Robert Bradshaw

Undo a couple of documentation fixes (where the old style was intentional).

parent 365b547f
......@@ -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
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
obtained, at some speed gain, by enabling the division directive
obtained, at some speed gain, by enabling the cdivision directive
(versions prior to Cython 0.12 always followed C semantics).
- Care is needed with unsigned types. ``cdef unsigned n = 10;
print(range(-n, n))`` will print an empty list, since ``-n`` wraps
......
......@@ -8,7 +8,8 @@ cdef class Queue:
def __cinit__(self):
self._c_queue = cqueue.queue_new()
if self._c_queue is NULL:
raise MemoryError()
# raise MemoryError() allocates memory
python_exc.PyErr_NoMemory()
def __dealloc__(self):
if self._c_queue is not NULL:
......@@ -16,14 +17,14 @@ cdef class Queue:
cpdef int append(self, int value) except -1:
if not cqueue.queue_push_tail(self._c_queue, <void*>value):
raise MemoryError()
python_exc.PyErr_NoMemory()
return 0
cdef int extend(self, int* values, Py_ssize_t count) except -1:
cdef Py_ssize_t i
for i in range(count):
if not cqueue.queue_push_tail(self._c_queue, <void*>values[i]):
raise MemoryError()
python_exc.PyErr_NoMemory()
return 0
cpdef int peek(self) except? 0:
......@@ -44,7 +45,7 @@ cdef class Queue:
raise IndexError("Queue is empty")
return value
def __bool__(self):
def __bool__(self): # or __nonzero__ for Python 2.x
return not cqueue.queue_is_empty(self._c_queue)
DEF repeat_count=10000
......
......@@ -104,7 +104,7 @@ follows::
Now the Cython compiler knows that ``sh`` has a C attribute called
: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 sh2
......@@ -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
specify the base class in both the forward declaration and its subsequent
definition, for example::
definition, for example,::
cdef class A(B)
......@@ -410,7 +410,7 @@ Making extension types weak-referenceable
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
object called :attr:`__weakref__`. For example::
object called :attr:`__weakref__`. For example,::
cdef class ExplodingAnimal:
"""This animal will self-destruct when it is
......@@ -507,7 +507,7 @@ Implicit importing
------------------
Cython requires you to include a module name in an extern extension class
declaration, for example::
declaration, for example,::
cdef extern class MyModule.Spam:
...
......@@ -521,13 +521,13 @@ example an implicit::
statement will be executed at module load time.
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:
...
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:
...
......
......@@ -24,7 +24,7 @@ External declarations
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
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
......@@ -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
corresponding :keyword:`ctypedef` statement, but you don't need to match
the type exactly, just use something of the right general kind (int, float,
etc). For example::
etc). For example,::
ctypedef int word
......@@ -185,7 +185,7 @@ Accessing Python/C API routines
---------------------------------
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":
......@@ -204,7 +204,7 @@ Windows Calling Conventions
----------------------------
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)
......@@ -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.
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 float three "drei"
......@@ -388,7 +388,7 @@ Multiple public and API declarations
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
example::
example,::
cdef public api:
void order_spam(int tons)
......
......@@ -27,8 +27,8 @@ and C :keyword:`struct`, :keyword:`union` or :keyword:`enum` types::
float volume
cdef union Food:
char* spam
float* eggs
char *spam
float *eggs
cdef enum CheeseType:
cheddar, edam,
......@@ -42,7 +42,7 @@ and C :keyword:`struct`, :keyword:`union` or :keyword:`enum` types::
See also :ref:`struct-union-enum-styles`
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:
tons_of_spam = 3
......@@ -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
pointing to a ``Grail`` you would write::
cdef Grail* gp
cdef Grail *gp
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.::
......@@ -76,9 +76,9 @@ can group them into a :keyword:`cdef` block like this::
int i
float f
Spam* p
Spam *p
void f(Spam* s):
void f(Spam *s):
print s.tons, "Tons of spam"
......@@ -103,9 +103,9 @@ can be called from anywhere, but uses the faster C calling conventions
when being called from other Cython code.
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):
......@@ -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
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):
...
......@@ -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
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`
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
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
return value and raise it yourself, for example::
return value and raise it yourself, for example,::
cdef FILE* p
p = fopen("spam.txt", "r")
......@@ -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
attempt something like::
cdef char* s
cdef char *s
s = pystring1 + pystring2
then Cython will produce the error message ``Obtaining char* from temporary
......@@ -304,7 +304,7 @@ compile it.
The solution is to assign the result of the concatenation to a Python
variable, and then obtain the ``char*`` from that, i.e.::
cdef char* s
cdef char *s
p = pystring1 + pystring2
s = p
......@@ -347,7 +347,7 @@ direct equivalent in Python.
* There is no unary ``*`` operator in Cython. Instead of ``*p``, use ``p[0]``
* 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).
* Type casts are written ``<type>value`` , for example::
* Type casts are written ``<type>value`` , for example,::
cdef char* p, float* q
p = <char*>q
......@@ -489,7 +489,7 @@ The include statement
Use :ref:`sharing-declarations` instead.
A Cython source file can include material from other files using the include
statement, for example::
statement, for example,::
include "spamstuff.pxi"
......
......@@ -160,7 +160,7 @@ Sharing C Functions
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
example::
example,::
:file:`volume.pxd`::
......
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