From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 9/9] menu: simplify usage for clients
Date: Thu, 26 Aug 2010 18:19:27 +0200 [thread overview]
Message-ID: <20100826161927.GA16555@game.jcrosoft.org> (raw)
In-Reply-To: <20100823164954.GW27749@pengutronix.de>
On 18:49 Mon 23 Aug , Sascha Hauer wrote:
> On Mon, Aug 23, 2010 at 05:18:05PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 08:24 Mon 23 Aug , Sascha Hauer wrote:
> > > Clients now only have to call menu_add_submenu or menu_add_command_entry
> > > instead of allocating many strings.
> > > This also fixes some problems in the menu code. The priv field in struct
> > > menu_entry was a pointer to struct menu or a pointer to an allocated string.
> > > It was never freed, only had to be freed when it was an allocated string.
> > > The reference to a submenu is now kept as a string and not to the menu
> > > itself. The code checked the existence of the submenu when creating it, but
> > > crashed when the submenu was removed and referenced afterwards. Now the
> > > code hapily allows references to nonexistant menus but complains during
> > > runtime when the menu is not there.
> > ok but no need to check if the pointer is null before freeing and please do
> > not remove the priv pointer as I use is in C API for complex menu to pass data
> > to the action
> > That's why I keep it as void*
>
> So there's data associated to *priv, how do you free it then when...
no need in my code as i use a pre-alocatied struct
but in your new proposition it will use a specific free callback
>
> > >
> > > #include <errno.h>
> > > #include <readkey.h>
> > > +#include <linux/err.h>
> > >
> > > static LIST_HEAD(menus);
> > >
> > > @@ -145,10 +146,7 @@ void menu_entry_free(struct menu_entry *me)
> > > if (!me)
> > > return;
> > >
> > > - if (me->display)
> > > - free(me->display);
> > > -
> > > - free(me);
> > > + me->free(me);
> > we must check the pointer first as in the C API we must be able to overwrite
> > it or we must check that the C API provice it
>
> ... you don't provide a free function?
>
> You can't overwrite menu_entry_free as it is called from menu_free.
the idea is to allow it as in my mind the client must be able to pass any priv
data to create specific action
>
> > > }
> > >
> > > static void print_menu_entry(struct menu *m, struct menu_entry *me, int reverse)
> > > @@ -277,14 +275,76 @@ int menu_show(struct menu *m)
> > >
> > > void menu_action_exit(struct menu *m, struct menu_entry *me) {}
> > >
> > > -void menu_action_run(struct menu *m, struct menu_entry *me)
> > > +struct submenu {
> > > + char *submenu;
> > > + struct menu_entry entry;
> > > +};
>
> Note how struct menu_entry here is contained in a bigger struct. This
> way you can associate private data to a menu_entry using container_of
> without the use of a priv pointer.
I known but it will complex the code for adding custom by forcing the client
to declare his own struct for every menu or action
>
> That said we can keep the priv pointer, but you can't use it for data
> which must be freed, at least not without providing a free function.
> That was what I was trying to enforce, maybe that went a bit too far.
no I like the idea I just think how to allow the client to create custon
action very easly
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2010-08-26 16:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-23 6:24 Update patches for menu framework Sascha Hauer
2010-08-23 6:24 ` [PATCH 1/9] menu: initialize entries list in menu_alloc Sascha Hauer
2010-08-23 6:24 ` [PATCH 2/9] menu: Use strdup instead of malloc/strncpy Sascha Hauer
2010-08-23 6:24 ` [PATCH 3/9] menu: simplify menu_free with list_for_each_entry_safe Sascha Hauer
2010-08-23 6:24 ` [PATCH 4/9] menu: remove superfluous struct menu_entry member from struct menu Sascha Hauer
2010-08-23 6:24 ` [PATCH 5/9] menu: use list_for_each_entry where appropriate Sascha Hauer
2010-08-23 6:24 ` [PATCH 6/9] menu: use an initialized struct list as menu list Sascha Hauer
2010-08-23 6:24 ` [PATCH 7/9] menu: fix memory corruption Sascha Hauer
2010-08-23 11:40 ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-23 12:44 ` Uwe Kleine-König
2010-08-23 6:24 ` [PATCH 8/9] menu: do not go to free if there's nothing to free Sascha Hauer
2010-08-23 6:24 ` [PATCH 9/9] menu: simplify usage for clients Sascha Hauer
2010-08-23 15:18 ` Jean-Christophe PLAGNIOL-VILLARD
2010-08-23 16:49 ` Sascha Hauer
2010-08-26 16:19 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
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=20100826161927.GA16555@game.jcrosoft.org \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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