[Mesa-dev] [PATCH 2/2] mesa: use strdup() instead of _mesa_strdup()

Jose Fonseca jfonseca at vmware.com
Wed Mar 11 00:10:25 PDT 2015


On 11/03/15 01:42, Brian Paul wrote:
> We were already using strdup() in various places in Mesa.  Get rid
> of the _mesa_strdup() wrapper.  All the callers pass a non-NULL
> argument so the NULL check isn't needed either.
> ---
>   src/mesa/main/imports.c             | 18 ------------------
>   src/mesa/main/imports.h             |  3 ---
>   src/mesa/main/objectlabel.c         |  2 +-
>   src/mesa/main/shaderapi.c           |  2 +-
>   src/mesa/main/transformfeedback.c   |  2 +-
>   src/mesa/program/prog_instruction.c |  2 +-
>   src/mesa/program/prog_parameter.c   |  2 +-
>   src/mesa/program/prog_statevars.c   |  2 +-
>   src/mesa/program/program.c          |  6 +++---
>   9 files changed, 9 insertions(+), 30 deletions(-)
>
> diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c
> index a7ffe22..ac8deeb 100644
> --- a/src/mesa/main/imports.c
> +++ b/src/mesa/main/imports.c
> @@ -481,24 +481,6 @@ _mesa_half_to_float(GLhalfARB val)
>   /** \name String */
>   /*@{*/
>
> -/**
> - * Implemented using malloc() and strcpy.
> - * Note that NULL is handled accordingly.
> - */
> -char *
> -_mesa_strdup( const char *s )
> -{
> -   if (s) {
> -      size_t l = strlen(s);
> -      char *s2 = malloc(l + 1);
> -      if (s2)
> -         strcpy(s2, s);
> -      return s2;
> -   }
> -   else {
> -      return NULL;
> -   }
> -}
>
>   /** Compute simple checksum/hash for a string */
>   unsigned int
> diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
> index 7921000..ee6b399 100644
> --- a/src/mesa/main/imports.h
> +++ b/src/mesa/main/imports.h
> @@ -448,9 +448,6 @@ _mesa_half_is_negative(GLhalfARB h)
>      return h & 0x8000;
>   }
>
> -extern char *
> -_mesa_strdup( const char *s );
> -
>   extern unsigned int
>   _mesa_str_checksum(const char *str);
>
> diff --git a/src/mesa/main/objectlabel.c b/src/mesa/main/objectlabel.c
> index 78df96b..aecb5b1 100644
> --- a/src/mesa/main/objectlabel.c
> +++ b/src/mesa/main/objectlabel.c
> @@ -76,7 +76,7 @@ set_label(struct gl_context *ctx, char **labelPtr, const char *label,
>                   MAX_LABEL_LENGTH);
>
>            /* null-terminated string */
> -         *labelPtr = _mesa_strdup(label);
> +         *labelPtr = strdup(label);
>         }
>      }
>   }
> diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
> index 5731d58..3ea76af 100644
> --- a/src/mesa/main/shaderapi.c
> +++ b/src/mesa/main/shaderapi.c
> @@ -1460,7 +1460,7 @@ read_shader(const char *fname)
>
>      fclose(f);
>
> -   shader = _mesa_strdup(buffer);
> +   shader = strdup(buffer);
>      free(buffer);
>
>      return shader;
> diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c
> index a3e23ce..ce678c8 100644
> --- a/src/mesa/main/transformfeedback.c
> +++ b/src/mesa/main/transformfeedback.c
> @@ -762,7 +762,7 @@ _mesa_TransformFeedbackVaryings(GLuint program, GLsizei count,
>
>      /* Save the new names and the count */
>      for (i = 0; i < count; i++) {
> -      shProg->TransformFeedback.VaryingNames[i] = _mesa_strdup(varyings[i]);
> +      shProg->TransformFeedback.VaryingNames[i] = strdup(varyings[i]);
>      }
>      shProg->TransformFeedback.NumVarying = count;
>
> diff --git a/src/mesa/program/prog_instruction.c b/src/mesa/program/prog_instruction.c
> index 6a9bcb7..f9ebe4e 100644
> --- a/src/mesa/program/prog_instruction.c
> +++ b/src/mesa/program/prog_instruction.c
> @@ -89,7 +89,7 @@ _mesa_copy_instructions(struct prog_instruction *dest,
>      memcpy(dest, src, n * sizeof(struct prog_instruction));
>      for (i = 0; i < n; i++) {
>         if (src[i].Comment)
> -         dest[i].Comment = _mesa_strdup(src[i].Comment);
> +         dest[i].Comment = strdup(src[i].Comment);
>      }
>      return dest;
>   }
> diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
> index 5939f6f..cdfe251 100644
> --- a/src/mesa/program/prog_parameter.c
> +++ b/src/mesa/program/prog_parameter.c
> @@ -148,7 +148,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
>
>         for (i = 0; i < sz4; i++) {
>            struct gl_program_parameter *p = paramList->Parameters + oldNum + i;
> -         p->Name = name ? _mesa_strdup(name) : NULL;
> +         p->Name = name ? strdup(name) : NULL;
>            p->Type = type;
>            p->Size = size;
>            p->DataType = datatype;
> diff --git a/src/mesa/program/prog_statevars.c b/src/mesa/program/prog_statevars.c
> index 57b25a7..0c0c87f 100644
> --- a/src/mesa/program/prog_statevars.c
> +++ b/src/mesa/program/prog_statevars.c
> @@ -1045,7 +1045,7 @@ _mesa_program_state_string(const gl_state_index state[STATE_LENGTH])
>         break;
>      }
>
> -   return _mesa_strdup(str);
> +   return strdup(str);
>   }
>
>
> diff --git a/src/mesa/program/program.c b/src/mesa/program/program.c
> index 61a9e97..3c214d5 100644
> --- a/src/mesa/program/program.c
> +++ b/src/mesa/program/program.c
> @@ -79,7 +79,7 @@ _mesa_init_program(struct gl_context *ctx)
>      STATIC_ASSERT(NUM_TEXTURE_TARGETS <= (1 << 4));
>
>      ctx->Program.ErrorPos = -1;
> -   ctx->Program.ErrorString = _mesa_strdup("");
> +   ctx->Program.ErrorString = strdup("");
>
>      ctx->VertexProgram.Enabled = GL_FALSE;
>      ctx->VertexProgram.PointSizeEnabled =
> @@ -176,7 +176,7 @@ _mesa_set_program_error(struct gl_context *ctx, GLint pos, const char *string)
>      free((void *) ctx->Program.ErrorString);
>      if (!string)
>         string = "";
> -   ctx->Program.ErrorString = _mesa_strdup(string);
> +   ctx->Program.ErrorString = strdup(string);
>   }
>
>
> @@ -483,7 +483,7 @@ _mesa_clone_program(struct gl_context *ctx, const struct gl_program *prog)
>      assert(clone->Target == prog->Target);
>      assert(clone->RefCount == 1);
>
> -   clone->String = (GLubyte *) _mesa_strdup((char *) prog->String);
> +   clone->String = (GLubyte *) strdup((char *) prog->String);
>      clone->Format = prog->Format;
>      clone->Instructions = _mesa_alloc_instructions(prog->NumInstructions);
>      if (!clone->Instructions) {
>

Series is
Reviewed-by: Jose Fonseca <jfonseca at vmware.com>


More information about the mesa-dev mailing list