You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tech_notes.md
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,55 @@
4
4
5
5
Note to self: as of Jan 2019 also using github_jm\didactique\doc\know_how.md to log the exploratory and release processes around `refcount`
6
6
7
+
## Poetry
8
+
9
+
2022-12
10
+
11
+
Having to update dependent package versions [GitPython vulnerable to Remote Code Execution due to improper user input validation](https://github.com/csiro-hydroinformatics/pyrefcount/security/dependabot/4). It is probably not a burning issue given this should be only a dev-time dependency and certainly not runtime (otherwise poetry is crap)
12
+
13
+
```sh
14
+
cd~/src/pyrefcount
15
+
poetry --version # in a conda env for poetry...
16
+
```
17
+
18
+
`ModuleNotFoundError: No module named 'importlib_metadata'`. Right...
19
+
20
+
```sh
21
+
cd~/bin
22
+
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj micromamba
23
+
micromamba shell init -s bash -p ~/micromamba
24
+
```
25
+
26
+
```sh
27
+
source~/.bashrc
28
+
alias mm=micromamba
29
+
mm create -n poetry python=3.9
30
+
mm activate poetry
31
+
mm list
32
+
```
33
+
34
+
`pip install poetry`
35
+
36
+
```
37
+
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
38
+
plantuml-markdown 3.6.3 requires Markdown, which is not installed.
39
+
```
40
+
41
+
Huh??
42
+
43
+
`pip install Markdown` seems to fix it. Odd.
44
+
45
+
poetry --version returns 1.3.1 which seems to be what is available from conda-forge anyway. So:
Copy file name to clipboardExpand all lines: refcount/interop.py
+42-20Lines changed: 42 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -19,29 +19,51 @@
19
19
classCffiNativeHandle(NativeHandle):
20
20
"""Reference counting wrapper class for CFFI pointers
21
21
22
+
This class is originally inspired from a class with a similar purpose in C#. See https://github.com/rdotnet/dynamic-interop-dll
23
+
24
+
Say you have a C API as follows:
25
+
26
+
* `void* create_some_object();`
27
+
* `dispose_of_some_object(void* obj);`
28
+
29
+
and accessing it using Python and [CFFI](https://cffi.readthedocs.io).
30
+
Users would use the `calllib` function:
31
+
32
+
```python
33
+
from cffi import FFI
34
+
ffi = FFI()
35
+
36
+
# cdef() expects a single string declaring the C types, functions and
37
+
# globals needed to use the shared object. It must be in valid C syntax.
38
+
ffi.cdef('''
39
+
void* create_some_object();
40
+
dispose_of_some_object(void* obj);
41
+
''')
42
+
mydll_so = ffi.dlopen('/path/to/mydll.so')
43
+
cffi_void_ptr = mydll_so.create_some_object()
44
+
```
45
+
46
+
at some point when done you need to dispose of it to clear native memory:
47
+
48
+
```python
49
+
mydll_so.dispose_of_some_object(cffi_void_ptr)
50
+
```
51
+
52
+
In practice in real systems one quickly ends up with cases
53
+
where it is unclear when to dispose of the object.
54
+
If you call the `dispose_of_some_object` function more
55
+
than once, or too soon, you quickly crash the program, or possibly worse outcomes with numeric non-sense.
56
+
`CffiNativeHandle` is designed to alleviate this headache by
57
+
using native reference counting of `handle` classes to reliably dispose of objects.
58
+
22
59
Attributes:
23
60
_handle (object): The handle (e.g. cffi pointer) to the native resource.
24
61
_type_id (Optional[str]): An optional identifier for the type of underlying resource. This can be used to usefully maintain type information about the pointer/handle across an otherwise opaque C API. See package documentation.
25
62
_finalizing (bool): a flag telling whether this object is in its deletion phase. This has a use in some advanced cases with reverse callback, possibly not relevant in Python.
26
63
"""
27
64
28
-
# Say you have a C API as follows:
29
-
# * `void* create_some_object();`
30
-
# * `dispose_of_some_object(void* obj);`
31
-
# and accessing it using Python and CFFI. Users would use the `calllib` function:
0 commit comments