aboutsummaryrefslogtreecommitdiffstats
path: root/docs/development/c-bindings.rst
diff options
context:
space:
mode:
authorLaurens Van Houtven <_@lvh.cc>2014-06-23 14:08:27 +0200
committerLaurens Van Houtven <_@lvh.cc>2014-06-23 14:08:27 +0200
commit220a98ddfee87e049ddb91229b05e6f9c82a5ddf (patch)
tree40d288e98985fe6fd34ea5909b1d94f32e9fa24e /docs/development/c-bindings.rst
parent0a1d9e17858f0ab5465d3455970f6525607096ba (diff)
downloadcryptography-220a98ddfee87e049ddb91229b05e6f9c82a5ddf.tar.gz
cryptography-220a98ddfee87e049ddb91229b05e6f9c82a5ddf.tar.bz2
cryptography-220a98ddfee87e049ddb91229b05e6f9c82a5ddf.zip
Move C bindings style guide to C bindings document
Diffstat (limited to 'docs/development/c-bindings.rst')
-rw-r--r--docs/development/c-bindings.rst72
1 files changed, 72 insertions, 0 deletions
diff --git a/docs/development/c-bindings.rst b/docs/development/c-bindings.rst
index 910f4d3d..1349af73 100644
--- a/docs/development/c-bindings.rst
+++ b/docs/development/c-bindings.rst
@@ -7,6 +7,78 @@ C bindings are bindings to C libraries, using cffi_ whenever possible.
Bindings live in :py:mod:`cryptography.hazmat.bindings`.
+Style guide
+-----------
+
+Don't name parameters:
+
+.. code-block:: c
+
+ /* Good */
+ long f(long);
+ /* Bad */
+ long f(long x);
+
+...unless they're inside a struct:
+
+.. code-block:: c
+
+ struct my_struct {
+ char *name;
+ int number;
+ ...;
+ };
+
+Include ``void`` if the function takes no arguments:
+
+.. code-block:: c
+
+ /* Good */
+ long f(void);
+ /* Bad */
+ long f();
+
+Wrap lines at 80 characters like so:
+
+.. code-block:: c
+
+ /* Pretend this went to 80 characters */
+ long f(long, long,
+ int *)
+
+Include a space after commas between parameters:
+
+.. code-block:: c
+
+ /* Good */
+ long f(int, char *)
+ /* Bad */
+ long f(int,char *)
+
+Use C-style ``/* */`` comments instead of C++-style ``//``:
+
+.. code-block:: c
+
+ // Bad
+ /* Good */
+
+Values set by ``#define`` should be assigned the appropriate type. If you see
+this:
+
+.. code-block:: c
+
+ #define SOME_INTEGER_LITERAL 0x0;
+ #define SOME_UNSIGNED_INTEGER_LITERAL 0x0001U;
+ #define SOME_STRING_LITERAL "hello";
+
+...it should be added to the bindings like so:
+
+.. code-block:: c
+
+ static const int SOME_INTEGER_LITERAL;
+ static const unsigned int SOME_UNSIGNED_INTEGER_LITERAL;
+ static const char *const SOME_STRING_LITERAL;
+
Adding constant, types, functions...
------------------------------------