Commit c12cf843 authored by Rasmus Bondesson's avatar Rasmus Bondesson
Browse files

Remove trailing whitespace in doc/*

--HG--
branch : doc-improvements
parent 0c72583dfdc6
......@@ -823,7 +823,7 @@ write the rest of the build script):
print lib.mysize
Extra arguments to ``ffi.verify()``:
* ``tmpdir`` controls where the C
files are created and compiled. Unless the ``CFFI_TMPDIR`` environment
variable is set, the default is
......
......@@ -17,6 +17,3 @@ copy-paste from header files or documentation.
ref
cdef
embedding
......@@ -140,10 +140,10 @@ Win32 and Win64 work and are tested at least each official release.
The recommended C compiler compatible with Python 2.7 is this one:
http://www.microsoft.com/en-us/download/details.aspx?id=44266
There is a known problem with distutils on Python 2.7, as
explained in https://bugs.python.org/issue23246, and the same
There is a known problem with distutils on Python 2.7, as
explained in https://bugs.python.org/issue23246, and the same
problem applies whenever you want to run compile() to build a dll with
this specific compiler suite download.
this specific compiler suite download.
``import setuptools`` might help, but YMMV
For Python 3.4 and beyond:
......
......@@ -3,7 +3,7 @@ Overview
=======================================================
.. contents::
The first section presents a simple working
example of using CFFI to call a C function in a compiled shared object
......@@ -126,7 +126,7 @@ May look familiar to those who have used ctypes_.
>>> ffi = FFI()
>>> ffi.cdef("""
... int printf(const char *format, ...); // copy-pasted from the man page
... """)
... """)
>>> C = ffi.dlopen(None) # loads the entire C namespace
>>> arg = ffi.new("char[]", b"world") # equivalent to C code: char arg[] = "world";
>>> C.printf(b"hi there, %s.\n", arg) # call printf
......@@ -301,28 +301,28 @@ with the files ``pi.c`` and ``pi.h``:
/* filename: pi.c*/
# include <stdlib.h>
# include <math.h>
/* Returns a very crude approximation of Pi
given a int: a number of iteration */
float pi_approx(int n){
double i,x,y,sum=0;
for(i=0;i<n;i++){
x=rand();
y=rand();
if (sqrt(x*x+y*y) < sqrt((double)RAND_MAX*RAND_MAX))
sum++; }
return 4*(float)sum/(float)n; }
.. code-block:: C
/* filename: pi.h*/
float pi_approx(int n);
Create a script named ``pi_extension_build.py``, building
the C extension:
......@@ -330,21 +330,21 @@ the C extension:
from cffi import FFI
ffibuilder = FFI()
ffibuilder.cdef("float pi_approx(int n);")
ffibuilder.set_source("_pi", # name of the output C extension
"""
#include "pi.h"
""",
sources=['pi.c'], # includes pi.c as additional sources
libraries=['m']) # on Unix, link with the math library
if __name__ == "__main__":
ffibuilder.compile(verbose=True)
Build the extension:
.. code-block:: shell
python pi_extension_build.py
......@@ -354,14 +354,14 @@ Observe, in the working directory, the generated output files:
Linux for example). It can be called from Python:
.. code-block:: python
from _pi.lib import pi_approx
approx = pi_approx(10)
assert str(approx).startswith("3.")
approx = pi_approx(10000)
assert str(approx).startswith("3.1")
assert str(approx).startswith("3.1")
.. _performance:
......
......@@ -308,7 +308,7 @@ performance difference). It can still be useful in writing typechecks,
e.g.:
.. code-block:: python
def myfunction(ptr):
assert ffi.typeof(ptr) is ffi.typeof("foo_t*")
...
......
......@@ -459,7 +459,7 @@ that you really meant the 42 to be passed as a C ``int``, and not a
if necessary with ``ffi.cast()``:
.. code-block:: python
lib.printf("hello, %d\n", ffi.cast("int", 42))
lib.printf("hello, %ld\n", ffi.cast("long", 42))
lib.printf("hello, %f\n", ffi.cast("double", 42))
......@@ -966,7 +966,7 @@ arguments are passed:
ffibuilder.compile(verbose=True)
.. code-block:: python
# file "example.py"
from _example import ffi, lib
......
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