@@ -7,18 +7,25 @@ submit changes for drgn.
77Building
88--------
99
10- The easiest way to develop drgn is by building and running it locally. See the
11- `installation documentation
12- <https://drgn.readthedocs.io/en/latest/installation.html#development> `_.
10+ The easiest way to develop drgn is by building and running it locally. Please
11+ build with warnings enabled. Install the dependencies from the `installation
12+ instructions <README.rst#from-source> `_, then run:
13+
14+ .. code-block :: console
15+
16+ $ git clone https://github.com/osandov/drgn.git
17+ $ cd drgn
18+ $ CFLAGS="-Wall -Werror -g -O2" python3 setup.py build_ext -i
19+ $ python3 -m drgn --help
1320
1421 Testing
1522-------
1623
17- .. highlight :: console
18-
1924Tests should be added for all features and bug fixes.
2025
21- drgn's test suite can be run with::
26+ drgn's test suite can be run with:
27+
28+ .. code-block :: console
2229
2330 $ python3 setup.py test
2431
@@ -27,7 +34,9 @@ add ``-K``. See `vmtest <vmtest/README.rst>`_ for more details.
2734
2835Tests can also be run manually with `unittest
2936<https://docs.python.org/3/library/unittest.html#command-line-interface> `_
30- after building locally::
37+ after building locally:
38+
39+ .. code-block :: console
3140
3241 $ python3 -m unittest discover -v
3342
@@ -49,14 +58,32 @@ C code in drgn mostly follows the `Linux kernel coding style
4958<https://www.kernel.org/doc/html/latest/process/coding-style.html> `_ except
5059that drgn requires C11 or newer, so declarations may be mixed with code.
5160
52- A few other guidelines:
61+ A few other guidelines/conventions :
5362
63+ * Constants should be defined as enums or ``static const `` variables rather
64+ than macros.
5465* Functions that can fail should return a ``struct drgn_error * `` (and return
5566 their result via an out parameter if necessary).
5667* Out parameters should be named ``ret `` (or suffixed with ``_ret `` if there
57- are multiple).
58- * Constants should be defined as enums or ``static const `` variables rather
59- than macros.
68+ are multiple) and be the last parameter(s) of the function.
69+ * Functions that initialize an already allocated structure should be suffixed
70+ with ``_init `` and take the structure to initialize as the first argument,
71+ e.g., ``struct drgn_error *foo_init(struct foo *foo, int foo_flags) ``.
72+ * The matching function to deinitialize a structure should be suffixed with
73+ ``_deinit ``, e.g., ``void foo_deinit(struct foo *foo) ``. If possible, the
74+ definition should be placed directly after the definition of ``_init `` so
75+ that it is easier to visually verify that everything is cleaned up.
76+ * Functions that allocate and initialize a structure should be suffixed with
77+ ``_create `` and either return the structure as an out parameter (e.g.,
78+ ``struct drgn_error *foo_create(int foo_flags, struct foo **ret) ``) or as the
79+ return value if they can only fail with an out-of-memory error (e.g.,
80+ ``struct foo *foo_create(int foo_flags) ``).
81+ * The matching function to free an allocated structure should be suffixed with
82+ ``_destroy ``, e.g., ``void foo_destroy(struct foo *foo) ``. If possible, the
83+ definition should be placed directly after the definition of ``_create ``.
84+ ``_destroy `` should usually allow a ``NULL `` argument, just like ``free() ``.
85+ * Functions that return a result in a ``struct drgn_object * `` parameter should
86+ only modify the object if the function succeeds.
6087
6188drgn assumes some `implementation-defined behavior
6289<https://gcc.gnu.org/onlinedocs/gcc/C-Implementation.html> `_ for sanity:
@@ -74,7 +101,9 @@ Python
74101Python code in drgn should be compatible with Python 3.6 and newer.
75102
76103Python code should be formatted with `black <https://github.com/psf/black >`_
77- and `isort <https://github.com/timothycrosley/isort >`_::
104+ and `isort <https://github.com/timothycrosley/isort >`_:
105+
106+ .. code-block :: console
78107
79108 $ isort . && black .
80109
0 commit comments