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
b9975566
Commit
b9975566
authored
Jul 06, 2018
by
scoder
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2408 from gabrieldemarmiesse/test_sharing_declarations__2
Adding tests for "sharing declarations" part 2
parents
e4913479
82f95375
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
31 deletions
+40
-31
docs/examples/userguide/sharing_declarations/c_lunch.pxd
docs/examples/userguide/sharing_declarations/c_lunch.pxd
+2
-0
docs/examples/userguide/sharing_declarations/landscaping.pyx
docs/examples/userguide/sharing_declarations/landscaping.pyx
+7
-0
docs/examples/userguide/sharing_declarations/lunch.h
docs/examples/userguide/sharing_declarations/lunch.h
+1
-0
docs/examples/userguide/sharing_declarations/lunch.pyx
docs/examples/userguide/sharing_declarations/lunch.pyx
+4
-0
docs/examples/userguide/sharing_declarations/setup.py
docs/examples/userguide/sharing_declarations/setup.py
+4
-0
docs/examples/userguide/sharing_declarations/shrubbing.pxd
docs/examples/userguide/sharing_declarations/shrubbing.pxd
+3
-0
docs/examples/userguide/sharing_declarations/shrubbing.pyx
docs/examples/userguide/sharing_declarations/shrubbing.pyx
+7
-0
docs/src/userguide/sharing_declarations.rst
docs/src/userguide/sharing_declarations.rst
+12
-31
No files found.
docs/examples/userguide/sharing_declarations/c_lunch.pxd
0 → 100644
View file @
b9975566
cdef
extern
from
"lunch.h"
:
void
eject_tomato
(
float
)
docs/examples/userguide/sharing_declarations/landscaping.pyx
0 → 100644
View file @
b9975566
cimport
shrubbing
import
shrubbing
def
main
():
cdef
shrubbing
.
Shrubbery
sh
sh
=
shrubbing
.
standard_shrubbery
()
print
(
"Shrubbery size is"
,
sh
.
width
,
'x'
,
sh
.
length
)
docs/examples/userguide/sharing_declarations/lunch.h
0 → 100644
View file @
b9975566
void
eject_tomato
(
float
speed
);
docs/examples/userguide/sharing_declarations/lunch.pyx
0 → 100644
View file @
b9975566
cimport
c_lunch
def
eject_tomato
(
float
speed
):
c_lunch
.
eject_tomato
(
speed
)
docs/examples/userguide/sharing_declarations/setup.py
0 → 100644
View file @
b9975566
from
distutils.core
import
setup
from
Cython.Build
import
cythonize
setup
(
ext_modules
=
cythonize
([
"landscaping.pyx"
,
"shrubbing.pyx"
]))
docs/examples/userguide/sharing_declarations/shrubbing.pxd
0 → 100644
View file @
b9975566
cdef
class
Shrubbery
:
cdef
int
width
cdef
int
length
docs/examples/userguide/sharing_declarations/shrubbing.pyx
0 → 100644
View file @
b9975566
cdef
class
Shrubbery
:
def
__cinit__
(
self
,
int
w
,
int
l
):
self
.
width
=
w
self
.
length
=
l
def
standard_shrubbery
():
return
Shrubbery
(
3
,
7
)
docs/src/userguide/sharing_declarations.rst
View file @
b9975566
...
...
@@ -147,17 +147,13 @@ for an imaginary module, and :keyword:`cimport` that module. You can then
refer to the C functions by qualifying them with the name of the module.
Here's an example:
:file:`c_lunch.pxd`:
:
:file:`c_lunch.pxd`:
cdef extern from "lunch.h":
void eject_tomato(float)
.. literalinclude:: ../../examples/userguide/sharing_declarations/c_lunch.pxd
:file:`lunch.pyx`:
:
:file:`lunch.pyx`:
cimport c_lunch
def eject_tomato(float speed):
c_lunch.eject_tomato(speed)
.. literalinclude:: ../../examples/userguide/sharing_declarations/lunch.pyx
You don't need any :file:`c_lunch.pyx` file, because the only things defined
in :file:`c_lunch.pxd` are extern C entities. There won't be any actual
...
...
@@ -222,38 +218,23 @@ Python methods.
Here is an example of a module which defines and exports an extension type,
and another module which uses it:
:file:`Shrubbing.pxd`::
cdef class Shrubbery:
cdef int width
cdef int length
:file:`Shrubbing.pyx`::
:file:`shrubbing.pxd`:
cdef class Shrubbery:
def __cinit__(self, int w, int l):
self.width = w
self.length = l
.. literalinclude:: ../../examples/userguide/sharing_declarations/shrubbing.pxd
def standard_shrubbery():
return Shrubbery(3, 7)
:file:`shrubbing.pyx`:
:file:`Landscaping.pyx`::
.. literalinclude:: ../../examples/userguide/sharing_declarations/shrubbing.pyx
cimport Shrubbing
import Shrubbing
:file:`landscaping.pyx`:
cdef Shrubbing.Shrubbery sh
sh = Shrubbing.standard_shrubbery()
print("Shrubbery size is %d x %d" % (sh.width, sh.length))
.. literalinclude:: ../../examples/userguide/sharing_declarations/landscaping.pyx
One would then need to compile both of these modules, e.g. using
:file:`setup.py`:
:
:file:`setup.py`:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize(["Landscaping.pyx", "Shrubbing.pyx"]))
.. literalinclude:: ../../examples/userguide/sharing_declarations/setup.py
Some things to note about this example:
...
...
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