@@ -7,8 +7,8 @@ want a better understanding of Pymunk for example to extend it.
7
7
8
8
First off, Pymunk is a pythonic wrapper around the C-library Chipmunk.
9
9
10
- To wrap Chipmunk Pymunk uses CFFI. On top of the CFFI wrapping is a handmade
11
- pythonic layer to make it nice to use from Python code.
10
+ To wrap Chipmunk Pymunk uses CFFI in API mode . On top of the CFFI wrapping is
11
+ a handmade pythonic layer to make it nice to use from Python code.
12
12
13
13
Why CFFI?
14
14
---------
@@ -23,7 +23,7 @@ Advantages (compared to ctypes):
23
23
* Its an active project. The developers and users are active, there are new
24
24
releases being made and its possible to ask and get answers within a day on
25
25
the CFFI mailing list.
26
- * Its said to be the way forward for pypy , with promise of better performance
26
+ * Its said to be the way forward for Pypy , with promise of better performance
27
27
compares to ctypes.
28
28
* A little easier than ctypes to wrap things since you can just copy-paste the
29
29
c headers.
@@ -125,13 +125,11 @@ Code Layout
125
125
Most of Pymunk should be quite straight forward.
126
126
127
127
Except for the documented API Pymunk has a couple of interesting parts. Low
128
- level bindings to Chipmunk, a custom library load function, a custom
129
- documentation generation extension and a customized setup.py file to allow
130
- compilation of Chipmunk.
128
+ level bindings to Chipmunk, a custom documentation generation extension and a
129
+ customized setup.py file to allow compilation of Chipmunk.
131
130
132
- The low level chipmunk bindings are located in the two files _chipmunk_cffi.py
133
- and _chipmunk_cffi_abi.py. In order to locate and load the compiled chipmunk
134
- library file pymunk uses a custom load_library function in _libload.py
131
+ The low level chipmunk bindings are located in the file
132
+ pymunk_extension_build.py.
135
133
136
134
docs/src/ext/autoexample.py
137
135
A Sphinx extension that scans a directory and extracts the toplevel
@@ -147,15 +145,11 @@ pymunk/_chipmkunk_cffi_abi.py
147
145
This file contains the pure Cffi wrapping definitons. Bascially a giant
148
146
string created by copy-paster from the relevant header files of Chipmunk.
149
147
150
- pymunk/_libload.py
151
- This file contains the custom Cffi library load function that is used
152
- by the rest of pymunk to load the Chipmunk library file.
153
-
154
148
setup.py
155
149
Except for the standard setup stuff this file also contain the custom
156
150
build commands to build Chipmunk from source, using a build_ext extension.
157
151
158
- tests/*
152
+ pymunk/ tests/*
159
153
Collection of (unit) tests. Does not cover all cases, but most core
160
154
things are there. The tests require a working chipmunk library file.
161
155
@@ -180,7 +174,14 @@ argument. The matching is as broad as possible, so `UnitTest` matches all the
180
174
unit tests, `test_arbiter ` all tests in `test_arbiter.py ` and
181
175
`testResetitution ` matches the exact `testRestitution ` test case ::
182
176
183
- > python -m pymunk.tests testRestitution
177
+ > python -m pymunk.tests -f testRestitution
178
+
179
+ To see all options to the tests command use -h ::
180
+
181
+ > python -m pymunk.tests -h
182
+
183
+ Since the tests cover even the optional parts, you either have to make sure
184
+ all the optional dependencies are installed, or filter out those tests.
184
185
185
186
186
187
Working with non-wrapped parts of Chipmunk
@@ -194,7 +195,7 @@ wrapped by pymunk. The Chipmunk method to get this property is named
194
195
cpBodyIsSleeping.
195
196
196
197
First we need to check if its included in the cdef definition in
197
- _chipmunk_cffi.abi .py. If its not just add it.
198
+ pymunk_extension_build .py. If its not just add it.
198
199
199
200
`cpBool cpBodyIsSleeping(const cpBody *body); `
200
201
@@ -206,20 +207,13 @@ Then to make it easy to use we want to create a python method that looks nice::
206
207
Now we are ready with the mapping and ready to use our new method.
207
208
208
209
209
- Weak References and __del__ Methods
210
+ Weak References and free Methods
210
211
-----------------------------------
211
212
212
213
Internally Pymunk allocates structs from Chipmunk (the c library). For example a
213
214
Body struct is created from inside the constructor method when a pymunk.Body is
214
- created. Because of this several Pymunk objects uses a __del__() method that
215
- cleans up the underlying c struct when the object is deleted.
216
-
217
- Use of a __del__() method prevents the normal CPython GC (garbage collection)
218
- from handling cyclic references since it wont know in which order to run the
219
- __del__() methods. Some Pymunk objects naturally keeps cyclic references to each
220
- other to make them easier to use. One such example is the body and shape object.
221
- A shape is attached to a body, and a body has a set of all shapes that has been
222
- attached. To make it easier for the user of the library these cyclic references
223
- have been broken up so that the reference in one direction is weak and dont
224
- affect GC. Usually the user do not need to worry about this, but in the cases a
225
- reference is weak it is marked in the API documentation of the specific method.
215
+ created. Because of this its important that the corresponding c side memory is
216
+ deallocated properly when not needed anymore, usually when the Python side
217
+ object is garbage collected. Most Pymunk objects use `ffi.gc ` with a custom
218
+ free function to do this. Note that the order of freeing is very important to
219
+ avoid errors.
0 commit comments