From: Ian Campbell <Ian.Campbell@citrix.com>
To: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: xen-devel@lists.xensource.com, stefano.stabellini@eu.citrix.com
Subject: Re: [PATCH 1/4] libxl: CODING_STYLE: Much new material
Date: Mon, 10 Nov 2014 12:27:33 +0000 [thread overview]
Message-ID: <1415622453.25176.4.camel@citrix.com> (raw)
In-Reply-To: <1415198630-29937-2-git-send-email-ian.jackson@eu.citrix.com>
On Wed, 2014-11-05 at 14:43 +0000, Ian Jackson wrote:
> Discuss:
>
> Memory allocation
> Conventional variable names
> Convenience macros
> Error handling
> Idempotent data structure construction/destruction
> Asynchronous/long-running operations
>
> Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
> ---
> tools/libxl/CODING_STYLE | 169 +++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 168 insertions(+), 1 deletion(-)
>
> diff --git a/tools/libxl/CODING_STYLE b/tools/libxl/CODING_STYLE
> index 110a48f..3e72852 100644
> --- a/tools/libxl/CODING_STYLE
> +++ b/tools/libxl/CODING_STYLE
> @@ -1,6 +1,173 @@
> -Libxenlight Coding Style
> +LIBXENLIGHT CODING STYLE
> ========================
>
> +
> +MEMORY ALLOCATION
> +-----------------
> +
> +Memory allocation for libxl-internal purposes should normally be done
> +with the provided gc mechanisms; there is then no need to free. See
> +"libxl memory management" in libxl.h.
> +
> +
> +CONVENTIONAL VARIABLE NAMES
> +---------------------------
> +
> +The following local variable names should be used where applicable:
> +
> + int rc; /* a libxl error code - and not anything else */
> + int r; /* the return value from a system call (or libxc call) */
Quite a bit more "ret" for this one. Probably quite a few are being
misused as rc too, which is perhaps why you omitted it?
> +ERROR HANDLING
> +--------------
> +
> +Unless, there are good reasons to do otherwise, the following error
> +handling and cleanup paradigm should be used:
> +
> + * All local variables referring to resources which might need
> + cleaning up are declared at the top of the function, and
> + initialised to a sentinel value indicating "nothing allocated".
> + For example,
> + libxl_evgen_disk_eject *evg = NULL;
> + int nullfd = -1;
> +
> + * If the function is to return a libxl error value, `rc' is
> + used to contain the error codem, but it is NOT initialised:
I suspect this is a typo? (but then I never studied latin...)
> + * Function calls which might fail (ie most function calls) are
> + handled by putting the return/status value into a variable, and
> + then checking it in a separate statement:
> + evg->vdev = strdup(vdev);
> + if (!evg->vdev) { rc = ERROR_NOMEM; goto out; }
A slightly dodgy example because this should be GCSTRDUP(NOGC, vdev) and
therefore can't fail ;-)
> +IDEMPOTENT DATA STRUCTURE CONSTRUCTION/DESTRUCTION
> +--------------------------------------------------
> +
> +Nontrivial data structures (in structs) should come with an idempotent
> +_destroy function, which must free all resources associated with the
_dispose.
> +data structure (but not free the struct itself).
> +
> +Such a struct should also come with an _init function which
> +initialises the struct so that _destroy is a no-op.
again
next prev parent reply other threads:[~2014-11-10 12:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-05 14:43 [RFC PATCH 0/4] libxl: CODING_STYLE improvements Ian Jackson
2014-11-05 14:43 ` [PATCH 1/4] libxl: CODING_STYLE: Much new material Ian Jackson
2014-11-07 12:01 ` Wei Liu
2014-11-10 12:27 ` Ian Campbell [this message]
2014-11-14 18:43 ` Ian Jackson
2015-07-28 10:25 ` Ian Campbell
2014-11-05 14:43 ` [PATCH 2/4] libxl: CODING_STYLE: Deprecate `error' for out blocks Ian Jackson
2014-11-05 14:43 ` [PATCH 3/4] libxl: CODING_STYLE: Mention function out parameters Ian Jackson
2014-11-05 14:43 ` [PATCH 4/4] libxl: CODING_STYLE: Discuss existing style problems Ian Jackson
2014-11-10 12:30 ` Ian Campbell
2014-11-14 18:45 ` Ian Jackson
-- strict thread matches above, loose matches on Subject: below --
2014-11-14 18:52 [PATCH for-4.5 v2 0/4] libxl: CODING_STYLE Ian Jackson
2014-11-14 18:52 ` [PATCH 1/4] libxl: CODING_STYLE: Much new material Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415622453.25176.4.camel@citrix.com \
--to=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.