annotate Sources/README.txt @ 150:3c98306828de

todo cleanup
author Alain Mazy <am@osimis.io>
date Mon, 22 Jan 2024 17:58:48 +0100
parents 262189b417cd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
125
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 Note about the "memory leaks" in the Python allocators
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 ======================================================
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 This concerns functions "PyTuple_SetItem()" and
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 "PyDict_SetItemString()", whose documentation is the following:
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 >>>>>
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 Insert a reference to object o at position pos of the tuple pointed
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 to by p. Return 0 on success. If pos is out of bounds, return -1 and
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 set an IndexError exception.
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 Note: This function "steals" a reference to o and discards a
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 reference to an item already in the tuple at the affected position.
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 Insert val into the dictionary p using key as a key. key should be a
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 const char* UTF-8 encoded bytes string. The key object is created
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 using PyUnicode_FromString(key). Return 0 on success or -1 on
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 failure. This function does not steal a reference to val.
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 <<<<<
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 As can be seen:
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 * PyTuple_SetItem() steals the reference.
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 * PyDict_SetItemString() does *not* steal the reference.
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 Consequently, when passing an object created by the Orthanc Python
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 plugin:
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 * PyTuple_SetItem() must use "PythonObject::Release()".
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 * PyDict_SetItemString() must use "PythonObject::GetPyObject()".
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 In releases <= 4.0 of the Python plugin, PyDict_SetItemString() was
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 using "PythonObject::Release()" instead of
262189b417cd added README.txt
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 "PythonObject::GetPyObject()", which resulted in memory leaks.