linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Alexey Dobriyan" <adobriyan@gmail.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, torvalds@linux-foundation.org
Subject: Re: [PATCH] type safe allocator
Date: Thu, 2 Aug 2007 16:04:06 +0400	[thread overview]
Message-ID: <b6fcc0a0708020504j7588061fq7e70a50499dcbdfe@mail.gmail.com> (raw)
In-Reply-To: <E1IGYuK-0001Jj-00@dorka.pomaz.szeredi.hu>

On 8/2/07, Miklos Szeredi <miklos@szeredi.hu> wrote:
> The linux kernel doesn't have a type safe object allocator a-la new()
> in C++ or g_new() in glib.
>
> Introduce two helpers for this purpose:
>
>    alloc_struct(type, gfp_flags);
>
>    zalloc_struct(type, gfp_flags);

ick.

> These macros take a type name (usually a 'struct foo') as first
> argument

So one has to type struct twice.

> and the usual gfp-flags as second argument.  They return a
> pointer cast to 'type *'.
>
> The traditional forms of allocating a structure are:
>
>   fooptr = kmalloc(sizeof(*fooptr), ...);
>
>   fooptr = kmalloc(sizeof(struct foo), ...);

Key word is "traditional". Good traditional form which even half-competent
C programmers immediately parse in retina.

> The new form is preferred over these, because of it's type safety and
> more descriptive nature.

> +/**
> + * alloc_struct - allocate given type object
> + * @type: the type of the object to allocate
> + * @flags: the type of memory to allocate.
> + */
> +#define alloc_struct(type, flags) ((type *) kmalloc(sizeof(type), flags))

someone will write alloc_struct(int, GFP_KERNEL), I promise.

Can you play instead with something Lisp based which has infinetely more
potential for idioms.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2007-08-02 12:04 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-01  9:06 [RFC PATCH] " Miklos Szeredi
2007-08-01  9:29 ` Adrian Bunk
2007-08-01  9:41   ` Miklos Szeredi
2007-08-01 10:44 ` Andi Kleen
2007-08-01  9:57   ` Miklos Szeredi
2007-08-01 11:34     ` Andi Kleen
2007-08-01 10:45       ` Miklos Szeredi
2007-08-01 11:44         ` Jan Engelhardt
2007-08-01 11:56           ` Miklos Szeredi
2007-08-02  3:56 ` Linus Torvalds
2007-08-02  7:27   ` Miklos Szeredi
2007-08-02 12:05     ` Al Viro
2007-08-02 13:05       ` Miklos Szeredi
2007-08-02 17:23     ` Linus Torvalds
2007-08-02  5:33 ` Christoph Lameter
2007-08-02  7:38   ` Miklos Szeredi
2007-08-02 19:16     ` Christoph Lameter
2007-08-02  7:37 ` Satyam Sharma
2007-08-02  7:40   ` Miklos Szeredi
2007-08-02 11:31 ` [PATCH] " Miklos Szeredi, Miklos Szeredi
2007-08-02 12:04   ` Alexey Dobriyan [this message]
2007-08-02 12:24     ` Jan Engelhardt
2007-08-02 13:06       ` Miklos Szeredi
2007-08-02 13:35         ` Jan Engelhardt
2007-08-02 13:49           ` Miklos Szeredi
2007-08-02 13:47     ` Peter Zijlstra
2007-08-02 14:06       ` Bernd Petrovitsch
2007-08-02 14:08         ` Jan Engelhardt
2007-08-02 18:36   ` Andrew Morton
2007-08-02 18:48     ` Miklos Szeredi

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=b6fcc0a0708020504j7588061fq7e70a50499dcbdfe@mail.gmail.com \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=miklos@szeredi.hu \
    --cc=torvalds@linux-foundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox