[pulseaudio-discuss] [PATCH v2 5/6] card: simplify setting pa_card.name
Alexander E. Patrakov
patrakov at gmail.com
Sun Jun 12 13:58:30 UTC 2016
10.06.2016 22:55, Tanu Kaskinen пишет:
> ---
> src/pulsecore/card.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/src/pulsecore/card.c b/src/pulsecore/card.c
> index bc5b75b..896e959 100644
> --- a/src/pulsecore/card.c
> +++ b/src/pulsecore/card.c
> @@ -122,7 +122,6 @@ void pa_card_new_data_done(pa_card_new_data *data) {
>
> pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
> pa_card *c;
> - const char *name;
> void *state;
> pa_card_profile *profile;
> pa_device_port *port;
> @@ -135,16 +134,15 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
>
> c = pa_xnew0(pa_card, 1);
>
> - if (!(name = pa_namereg_register(core, data->name, PA_NAMEREG_CARD, c, data->namereg_fail))) {
> + if (!(c->name = pa_xstrdup(pa_namereg_register(core, data->name, PA_NAMEREG_CARD, c, data->namereg_fail)))) {
I think that the old code was more obvious.
pa_namereg_register() could return NULL, you checked for that
immediately, and acted upon the error. Now you pass this NULL through
pa_xstrdup(). This causes the reader to think what pa_xstrdup does with
a NULL. Yes, it returns a NULL, but I had to look at the source.
> pa_xfree(c);
> return NULL;
> }
>
> - pa_card_new_data_set_name(data, name);
> + pa_card_new_data_set_name(data, c->name);
> pa_hook_fire(&core->hooks[PA_CORE_HOOK_CARD_NEW], data);
>
> c->core = core;
> - c->name = pa_xstrdup(data->name);
> c->proplist = pa_proplist_copy(data->proplist);
> c->driver = pa_xstrdup(pa_path_get_filename(data->driver));
> c->module = data->module;
>
--
Alexander E. Patrakov
More information about the pulseaudio-discuss
mailing list