Re: [Mesa-dev] [PATCH 1/5] st/xvmc: use goto to make code more readable (v2)
On Thu, Dec 22, 2016 at 4:56 PM, Christian Königwrote: > Am 16.12.2016 um 12:58 schrieb Nayan Deshmukh: >> >> v2: add missing semicolon >> >> Signed-off-by: Nayan Deshmukh > > > Patch #2-#4 are Reviewed-by: Christian König . > > For patch #1 and #5 I'm a bit hesitated to add them without testing. I agree with you, maybe we can commit patch #2-#4 for now and meanwhile I will try to do some testing with XvMC. > XvMC isn't widely used any more, but we should still try to not break it. > > Maybe you can try to come up with something? I am not able to run XvMC on my system now, but I'll try it some more later in the evening. Regards, Nayan > > Regards, > Christian. > > >> --- >> src/gallium/state_trackers/xvmc/context.c | 40 >> +++ >> 1 file changed, 19 insertions(+), 21 deletions(-) >> >> diff --git a/src/gallium/state_trackers/xvmc/context.c >> b/src/gallium/state_trackers/xvmc/context.c >> index e9014c8..fb9f435 100644 >> --- a/src/gallium/state_trackers/xvmc/context.c >> +++ b/src/gallium/state_trackers/xvmc/context.c >> @@ -226,23 +226,20 @@ Status XvMCCreateContext(Display *dpy, XvPortID >> port, int surface_type_id, >>context_priv = CALLOC(1, sizeof(XvMCContextPrivate)); >> if (!context_priv) >> - return BadAlloc; >> + goto no_context_priv; >>/* TODO: Reuse screen if process creates another context */ >> vscreen = vl_dri2_screen_create(dpy, scrn); >>if (!vscreen) { >> XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL screen.\n"); >> - FREE(context_priv); >> - return BadAlloc; >> + goto no_screen; >> } >>pipe = vscreen->pscreen->context_create(vscreen->pscreen, vscreen, >> 0); >> if (!pipe) { >> XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL context.\n"); >> - vscreen->destroy(vscreen); >> - FREE(context_priv); >> - return BadAlloc; >> + goto no_context; >> } >>templat.profile = ProfileToPipe(mc_type); >> @@ -257,29 +254,17 @@ Status XvMCCreateContext(Display *dpy, XvPortID >> port, int surface_type_id, >>if (!context_priv->decoder) { >> XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL decoder.\n"); >> - pipe->destroy(pipe); >> - vscreen->destroy(vscreen); >> - FREE(context_priv); >> - return BadAlloc; >> + goto no_decoder; >> } >>if (!vl_compositor_init(_priv->compositor, pipe)) { >> XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor.\n"); >> - context_priv->decoder->destroy(context_priv->decoder); >> - pipe->destroy(pipe); >> - vscreen->destroy(vscreen); >> - FREE(context_priv); >> - return BadAlloc; >> + goto no_compositor; >> } >>if (!vl_compositor_init_state(_priv->cstate, pipe)) { >> XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor >> state.\n"); >> - vl_compositor_cleanup(_priv->compositor); >> - context_priv->decoder->destroy(context_priv->decoder); >> - pipe->destroy(pipe); >> - vscreen->destroy(vscreen); >> - FREE(context_priv); >> - return BadAlloc; >> + goto no_compositor_state; >> } >> @@ -313,6 +298,19 @@ Status XvMCCreateContext(Display *dpy, XvPortID >> port, int surface_type_id, >> XVMC_MSG(XVMC_TRACE, "[XvMC] Context %p created.\n", context); >>return Success; >> + >> +no_compositor_state: >> + vl_compositor_cleanup(_priv->compositor); >> +no_compositor: >> + context_priv->decoder->destroy(context_priv->decoder); >> +no_decoder: >> + pipe->destroy(pipe); >> +no_context: >> + vscreen->destroy(vscreen); >> +no_screen: >> + FREE(context_priv); >> +no_context_priv: >> + return BadAlloc; >> } >> PUBLIC > > > ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 1/5] st/xvmc: use goto to make code more readable (v2)
Am 16.12.2016 um 12:58 schrieb Nayan Deshmukh: v2: add missing semicolon Signed-off-by: Nayan DeshmukhPatch #2-#4 are Reviewed-by: Christian König . For patch #1 and #5 I'm a bit hesitated to add them without testing. XvMC isn't widely used any more, but we should still try to not break it. Maybe you can try to come up with something? Regards, Christian. --- src/gallium/state_trackers/xvmc/context.c | 40 +++ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/gallium/state_trackers/xvmc/context.c b/src/gallium/state_trackers/xvmc/context.c index e9014c8..fb9f435 100644 --- a/src/gallium/state_trackers/xvmc/context.c +++ b/src/gallium/state_trackers/xvmc/context.c @@ -226,23 +226,20 @@ Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id, context_priv = CALLOC(1, sizeof(XvMCContextPrivate)); if (!context_priv) - return BadAlloc; + goto no_context_priv; /* TODO: Reuse screen if process creates another context */ vscreen = vl_dri2_screen_create(dpy, scrn); if (!vscreen) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL screen.\n"); - FREE(context_priv); - return BadAlloc; + goto no_screen; } pipe = vscreen->pscreen->context_create(vscreen->pscreen, vscreen, 0); if (!pipe) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL context.\n"); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_context; } templat.profile = ProfileToPipe(mc_type); @@ -257,29 +254,17 @@ Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id, if (!context_priv->decoder) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL decoder.\n"); - pipe->destroy(pipe); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_decoder; } if (!vl_compositor_init(_priv->compositor, pipe)) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor.\n"); - context_priv->decoder->destroy(context_priv->decoder); - pipe->destroy(pipe); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_compositor; } if (!vl_compositor_init_state(_priv->cstate, pipe)) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor state.\n"); - vl_compositor_cleanup(_priv->compositor); - context_priv->decoder->destroy(context_priv->decoder); - pipe->destroy(pipe); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_compositor_state; } @@ -313,6 +298,19 @@ Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id, XVMC_MSG(XVMC_TRACE, "[XvMC] Context %p created.\n", context); return Success; + +no_compositor_state: + vl_compositor_cleanup(_priv->compositor); +no_compositor: + context_priv->decoder->destroy(context_priv->decoder); +no_decoder: + pipe->destroy(pipe); +no_context: + vscreen->destroy(vscreen); +no_screen: + FREE(context_priv); +no_context_priv: + return BadAlloc; } PUBLIC ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
[Mesa-dev] [PATCH 1/5] st/xvmc: use goto to make code more readable (v2)
v2: add missing semicolon Signed-off-by: Nayan Deshmukh--- src/gallium/state_trackers/xvmc/context.c | 40 +++ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/gallium/state_trackers/xvmc/context.c b/src/gallium/state_trackers/xvmc/context.c index e9014c8..fb9f435 100644 --- a/src/gallium/state_trackers/xvmc/context.c +++ b/src/gallium/state_trackers/xvmc/context.c @@ -226,23 +226,20 @@ Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id, context_priv = CALLOC(1, sizeof(XvMCContextPrivate)); if (!context_priv) - return BadAlloc; + goto no_context_priv; /* TODO: Reuse screen if process creates another context */ vscreen = vl_dri2_screen_create(dpy, scrn); if (!vscreen) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL screen.\n"); - FREE(context_priv); - return BadAlloc; + goto no_screen; } pipe = vscreen->pscreen->context_create(vscreen->pscreen, vscreen, 0); if (!pipe) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL context.\n"); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_context; } templat.profile = ProfileToPipe(mc_type); @@ -257,29 +254,17 @@ Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id, if (!context_priv->decoder) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL decoder.\n"); - pipe->destroy(pipe); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_decoder; } if (!vl_compositor_init(_priv->compositor, pipe)) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor.\n"); - context_priv->decoder->destroy(context_priv->decoder); - pipe->destroy(pipe); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_compositor; } if (!vl_compositor_init_state(_priv->cstate, pipe)) { XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor state.\n"); - vl_compositor_cleanup(_priv->compositor); - context_priv->decoder->destroy(context_priv->decoder); - pipe->destroy(pipe); - vscreen->destroy(vscreen); - FREE(context_priv); - return BadAlloc; + goto no_compositor_state; } @@ -313,6 +298,19 @@ Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id, XVMC_MSG(XVMC_TRACE, "[XvMC] Context %p created.\n", context); return Success; + +no_compositor_state: + vl_compositor_cleanup(_priv->compositor); +no_compositor: + context_priv->decoder->destroy(context_priv->decoder); +no_decoder: + pipe->destroy(pipe); +no_context: + vscreen->destroy(vscreen); +no_screen: + FREE(context_priv); +no_context_priv: + return BadAlloc; } PUBLIC -- 2.9.3 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev