]> sigrok.org Git - libsigrokdecode.git/blame - HACKING
usb_packet: handle errors from usb_signalling
[libsigrokdecode.git] / HACKING
CommitLineData
1859c480
UH
1-------------------------------------------------------------------------------
2HACKING
3-------------------------------------------------------------------------------
4
5Coding style
6------------
7
8This project is programmed using the Linux kernel coding style, see
9http://lxr.linux.no/linux/Documentation/CodingStyle for details.
10
11Please use the same style for any code contributions, thanks!
12
13The Python decoders should follow the usual Python conventions and use
14Python idioms as far as it makes sense. The coding style should mostly follow
15the Python PEP-8, which includes the convention of 4 spaces for indentation.
16See http://www.python.org/dev/peps/pep-0008/ for details.
17
18
19Contributions
20-------------
21
22 - Patches should be sent to the development mailinglist at
23 sigrok-devel@lists.sourceforge.net (please subscribe to the list first).
24
25 https://lists.sourceforge.net/lists/listinfo/sigrok-devel
26
27 - Alternatively, you can also clone the git repository and let us know
28 from where to pull/review your changes. You can use gitorious.org,
29 github.com, or any other public git hosting site.
30
31
32Random notes
33------------
34
0672779d
UH
35 - Don't do variable declarations in compound statements, only at the
36 beginning of a function.
37
38 - Generally avoid assigning values to variables at declaration time,
39 especially so for complex and/or run-time dependent values.
40
077fa8ac 41 - Consistently use g_*malloc() / g_*malloc0(). Do not use standard
1859c480
UH
42 malloc()/calloc() if it can be avoided (sometimes other libs such
43 as libftdi can return malloc()'d memory, for example).
44
45 - Always properly match allocations with the proper *free() functions. If
077fa8ac 46 glib's g_*malloc()/g_*malloc0() was used, use g_free() to free the
1859c480
UH
47 memory. Otherwise use standard free(). Never use the wrong function!
48
077fa8ac
UH
49 - We assume that "small" memory allocations (< 1MB) will always succeed.
50 Thus, it's fine to use g_malloc() or g_malloc0() for allocations of
51 simple/small structs and such (instead of using g_try_malloc()), and
52 there's no need to check the return value.
53
54 Do use g_try_malloc() or g_try_malloc0() for large (>= 1MB) allocations
55 and check the return value.
1859c480
UH
56
57 - You should never print any messages (neither to stdout nor stderr nor
58 elsewhere) "manually" via e.g. printf() or g_log() or similar functions.
59 Only srd_err()/srd_warn()/srd_info()/srd_dbg()/srd_spew() should be used.
60
61 - Use glib's gboolean / TRUE / FALSE for boolean types consistently.
62 Do not use <stdbool.h> and its true / false, and do not invent private
63 definitions for this either.
64
65 - Consistently use the same naming convention for #include guards in headers:
66 <PROJECTNAME>_<PATH_TO_FILE>_<FILE>
67 This ensures that all #include guards are always unique and consistent.
0672779d 68 Example: LIBSIGROKDECODE_LIBSIGROKDECODE_INTERNAL_H
1859c480
UH
69
70 - Consistently use the same naming convention for API functions:
71 <libprefix>_<groupname>_<action>().
72
73 Examples:
74 srd_log_loglevel_set(), srd_log_loglevel_get(), srd_log_handler_set(),
75 srd_log_handler_set_default(), and so on.
76
77 Getter/setter function names should usually end with "_get" or "_set".
78 Functions creating new "objects" should end with "_new".
79 Functions destroying "objects" should end with "_destroy".
80 Functions adding or removing items (e.g. from lists) should end with
81 either "_add" or "_remove".
82 Functions operating on all items from a list (not on only one of them),
83 should end with "_all", e.g. "_remove_all", "_get_all", and so on.
84 Use "_remove_all" in favor of "_clear" for consistency.
85
0672779d
UH
86 - All enums should generally use an explicit start number of 10000.
87 If there are multiple "categories" in the enum entries, each category
88 should be 10000 entries apart from the next one. The start of categories
89 are thus 10000, 20000, 30000, and so on.
90
91 Adding items to an enum MUST always append to a "category", never add
92 items in the middle of a category. The order of items MUST NOT be changed.
93 Any of the above would break the ABI.
94
95 The enum item 0 is special and is used as terminator in some lists, thus
96 enums should not use this for "valid" entries (and start at 10000 instead).
97
31e615a5
UH
98
99Doxygen
100-------
101
1859c480
UH
102 - In Doxygen comments, put an empty line between the block of @param lines
103 and the final @return line. The @param lines themselves (if there is more
104 than one) are not separated by empty lines.
105
31e615a5
UH
106 - Mark private functions (SRD_PRIV) with /** @private */, so that Doxygen
107 doesn't include them in the output. Functions that are "static" anyway
108 don't need to be marked like this.
109
110 - Mark private variables/#defines with /** @cond PRIVATE */ and
111 /** @endcond */, so that Doxygen doesn't include them in the output.
112 Variables that are "static" don't need to be marked like this.
113
f11e9498 114 - Mark all public API functions (SRD_API) with a @since tag which indicates
0672779d
UH
115 in which release the respective function was added (e.g. "@since 0.1.0").
116
117 If the function has existed before, but its API changed later, the @since
118 tag should mention only the release when the API last changed.
119
120 Example: The srd_foo() call was added in 0.1.0, but the API changed in
121 the later 0.2.0 release. The docs should read "@since 0.2.0" in that case.
f11e9498
UH
122
123 Non-public functions (static ones, and those marked SRD_PRIV) don't need
124 to have @since markers.
125
126 The @since tag should be the last one, i.e. it should come after @param,
127 @return, @see, and so on.
128
1859c480
UH
129
130Protocol decoder guidelines
131---------------------------
132
133 - The 'desc' metadata field for a protocol decoder, which contains a
134 short, one-line description of the protocol/bus, should be at most 55
135 characters long, and end with a full stop. This short description can be
136 displayed on the command-line using "sigrok-cli -V -l 3", or in various
137 different places in GUIs.
138
139 - Longer, multi-line descriptions should be placed in the protocol
140 decoder's __init__.py file as docstring. It can be viewed (for a specific
141 protocol decoder, e.g., UART) via "sigrok-cli -a uart", or in various
142 other places in GUIs.
143
144 - Generally use strings for states (of the PD state machine), not integers.
145 This avoids having to keep a list of state definitions at the top of file.
146 The performance overhead for this is negligible in practice.
147
148 Recommended:
149 self.state = 'IDLE'
150 self.state = 'GET STOP BIT'
151 Not recommended:
152 self.state = IDLE
153 self.state = GET_STOP_BIT
154 (where IDLE = 0 and GET_STOP_BIT = 1, for example)
155
156 - Generally use strings for commands/IDs in generated protocol packets.
157 This avoids having to know magic numbers of the PD in higher-level PDs.
158 The performance overhead for this is negligible in practice.
159
160 Recommended:
161 self.put(x, y, p, ['STOPBIT', 0, 0])
162 self.put(x, y, p, ['ADDRESS READ', 0x51])
163 Not recommended:
164 self.put(x, y, p, [STOPBIT, 0, 0])
165 self.put(x, y, p, [ADDRESS_READ, 0x51])
166 (with STOPBIT = 3 and ADDRESS_READ = 7, for example)
167
168 - Use ALL-CAPS names for PD states and protocol packet commands/ID.
169 Words should be separated by spaces (not underscores or the like).
170
171 Recommended:
172 'FIND ADDRESS', 'GET TEMPERATURE', 'START'
173 Not recommended:
174 'FIND_ADDRESS', 'Get Temperature', 'start'
175
176
0672779d
UH
177Testsuite
178---------
179
180You can run the libsigrokdecode testsuite using:
181
182 $ make check
183
184
185Protocol decoder test framework
186-------------------------------
187
c414f199
UH
188Please see the sigrok-test repository for a protocol decoder test suite that
189checks the decoded data of various PDs against known-good reference data.
0672779d
UH
190
191
1859c480
UH
192Release engineering
193-------------------
194
195See
196
197 http://sigrok.org/wiki/Developers/Release_process
198
199for a list of items that need to be done when releasing a new tarball.
200