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
Kirill Smelkov
cython
Commits
6e6baf58
Commit
6e6baf58
authored
6 years ago
by
scoder
Committed by
GitHub
6 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2407 from gabrieldemarmiesse/test_sharing_declarations_2
Adding tests for "sharing declarations" part 1
parents
c04ca703
27da4152
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
36 deletions
+42
-36
docs/examples/userguide/sharing_declarations/dishes.pxd
docs/examples/userguide/sharing_declarations/dishes.pxd
+6
-0
docs/examples/userguide/sharing_declarations/restaurant.pyx
docs/examples/userguide/sharing_declarations/restaurant.pyx
+12
-0
docs/examples/userguide/sharing_declarations/spammery.pyx
docs/examples/userguide/sharing_declarations/spammery.pyx
+11
-0
docs/examples/userguide/sharing_declarations/volume.pxd
docs/examples/userguide/sharing_declarations/volume.pxd
+1
-0
docs/examples/userguide/sharing_declarations/volume.pyx
docs/examples/userguide/sharing_declarations/volume.pyx
+2
-0
docs/src/userguide/sharing_declarations.rst
docs/src/userguide/sharing_declarations.rst
+10
-36
No files found.
docs/examples/userguide/sharing_declarations/dishes.pxd
0 → 100644
View file @
6e6baf58
cdef
enum
otherstuff
:
sausage
,
eggs
,
lettuce
cdef
struct
spamdish
:
int
oz_of_spam
otherstuff
filler
This diff is collapsed.
Click to expand it.
docs/examples/userguide/sharing_declarations/restaurant.pyx
0 → 100644
View file @
6e6baf58
from
__future__
import
print_function
cimport
dishes
from
dishes
cimport
spamdish
cdef
void
prepare
(
spamdish
*
d
):
d
.
oz_of_spam
=
42
d
.
filler
=
dishes
.
sausage
def
serve
():
cdef
spamdish
d
prepare
(
&
d
)
print
(
f'
{
d
.
oz_of_spam
}
oz spam, filler no.
{
d
.
filler
}
'
)
This diff is collapsed.
Click to expand it.
docs/examples/userguide/sharing_declarations/spammery.pyx
0 → 100644
View file @
6e6baf58
from
__future__
import
print_function
from
volume
cimport
cube
def
menu
(
description
,
size
):
print
(
description
,
":"
,
cube
(
size
),
"cubic metres of spam"
)
menu
(
"Entree"
,
1
)
menu
(
"Main course"
,
3
)
menu
(
"Dessert"
,
2
)
This diff is collapsed.
Click to expand it.
docs/examples/userguide/sharing_declarations/volume.pxd
0 → 100644
View file @
6e6baf58
cdef
float
cube
(
float
)
This diff is collapsed.
Click to expand it.
docs/examples/userguide/sharing_declarations/volume.pyx
0 → 100644
View file @
6e6baf58
cdef
float
cube
(
float
x
):
return
x
*
x
*
x
This diff is collapsed.
Click to expand it.
docs/src/userguide/sharing_declarations.rst
View file @
6e6baf58
...
@@ -80,28 +80,13 @@ Here is an example. :file:`dishes.pxd` is a definition file which exports a
...
@@ -80,28 +80,13 @@ Here is an example. :file:`dishes.pxd` is a definition file which exports a
C data type. :file:`restaurant.pyx` is an implementation file which imports and
C data type. :file:`restaurant.pyx` is an implementation file which imports and
uses it.
uses it.
:file:`dishes.pxd`:
:
:file:`dishes.pxd`:
cdef enum otherstuff:
.. literalinclude:: ../../examples/userguide/sharing_declarations/dishes.pxd
sausage, eggs, lettuce
cdef struct spamdish:
:file:`restaurant.pyx`:
int oz_of_spam
otherstuff filler
:file:`restaurant.pyx`::
.. literalinclude:: ../../examples/userguide/sharing_declarations/restaurant.pyx
cimport dishes
from dishes cimport spamdish
cdef void prepare(spamdish *d):
d.oz_of_spam = 42
d.filler = dishes.sausage
def serve():
cdef spamdish d
prepare(&d)
print("%d oz spam, filler no. %d" % (d.oz_of_spam, d.filler))
It is important to understand that the :keyword:`cimport` statement can only
It is important to understand that the :keyword:`cimport` statement can only
be used to import C data types, C functions and variables, and extension
be used to import C data types, C functions and variables, and extension
...
@@ -169,28 +154,17 @@ C functions defined at the top level of a module can be made available via
...
@@ -169,28 +154,17 @@ 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`:
cdef float cube(float)
:file:`volume.pyx`::
cdef float cube(float x):
return x * x * x
:file:`spammery.pyx`::
.. literalinclude:: ../../examples/userguide/sharing_declarations/volume.pxd
from __future__ import print_function
:file:`volume.pyx`:
from volume cimport cube
.. literalinclude:: ../../examples/userguide/sharing_declarations/volume.pyx
def menu(description, size):
:file:`spammery.pyx`:
print(description, ":", cube(size),
"cubic metres of spam")
menu("Entree", 1)
.. literalinclude:: ../../examples/userguide/sharing_declarations/spammery.pyx
menu("Main course", 3)
menu("Dessert", 2)
.. note::
.. note::
...
...
This diff is collapsed.
Click to expand it.
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