From 220a98ddfee87e049ddb91229b05e6f9c82a5ddf Mon Sep 17 00:00:00 2001 From: Laurens Van Houtven <_@lvh.cc> Date: Mon, 23 Jun 2014 14:08:27 +0200 Subject: Move C bindings style guide to C bindings document --- docs/development/c-bindings.rst | 72 +++++++++++++++++++++++++++++++++ docs/development/submitting-patches.rst | 72 --------------------------------- 2 files changed, 72 insertions(+), 72 deletions(-) (limited to 'docs/development') 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... ------------------------------------ diff --git a/docs/development/submitting-patches.rst b/docs/development/submitting-patches.rst index f8c8093c..fe2df431 100644 --- a/docs/development/submitting-patches.rst +++ b/docs/development/submitting-patches.rst @@ -78,78 +78,6 @@ C bindings More information on C bindings can be found in :doc:`the dedicated section of the documentation <c-bindings>`. -When binding C code with ``cffi`` we have our own style guide, it's pretty -simple. - -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; - Tests ----- -- cgit v1.2.3