Fix Top25 DuplicateCode score 76/242376/2
authorXuelian <xuelian.bai@samsung.com>
Wed, 26 Aug 2020 10:49:28 +0000 (18:49 +0800)
committerXuelian <xuelian.bai@samsung.com>
Wed, 26 Aug 2020 11:32:19 +0000 (19:32 +0800)
Define function and macro to eliminate duplicated code.
coregl_fastpath_gl.c:
Replace GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM with GET_PROG_REAL_OBJ
Define function _set_gl_vertex_attrib
coregl_tracepath.c:
Define function _mem_trace_change, _init_tstate_ftd
coregl_tracepath_egl.c:
Define function _get_current_data
DC Score : 4.64 -> 4.78
SAM Score : 4.0 -> 4.03

Change-Id: I22c7f9a32f5f426b3ab41b6eb32b0873991c17e2

src/modules/coregl_fastpath_gl.c
src/modules/coregl_tracepath.c
src/modules/coregl_tracepath_egl.c

index 0bf5258..7f87f0d 100644 (file)
    current_ctx = (GLGlueContext *)tstate->cstate->data; \
    AST(current_ctx != NULL);
 
+#define GET_PROG_REAL_OBJ(glue_handle, real_handle) \
+       if (_get_real_obj(&current_ctx->ostate, GL_OBJECT_TYPE_PROGRAM, glue_handle, real_handle) !=1) { \
+               _set_gl_error(GL_INVALID_VALUE); \
+               goto finish; \
+       }
 #define GET_REAL_OBJ(type, glue_handle, real_handle) \
        _get_real_obj(&current_ctx->ostate, type, glue_handle, real_handle)
 #define GET_GLUE_OBJ(type, real_handle, glue_handle) \
@@ -2031,10 +2036,7 @@ fastpath_glShaderSource(GLuint shader, GLsizei count, const char **string,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(shader, &real_obj);
 
        _orig_fastpath_glShaderSource(real_obj, count, string, length);
 
@@ -2088,10 +2090,7 @@ fastpath_glCompileShader(GLuint shader)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(shader, &real_obj);
 
        _orig_fastpath_glCompileShader(real_obj);
 
@@ -2111,10 +2110,7 @@ fastpath_glBindAttribLocation(GLuint program, GLuint index, const char *name)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glBindAttribLocation(real_obj, index, name);
 
@@ -2135,11 +2131,8 @@ fastpath_glAttachShader(GLuint program, GLuint shader)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj_program) != 1 ||
-                       GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj_shader) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj_program);
+       GET_PROG_REAL_OBJ(shader, &real_obj_shader);
 
        IF_GL_SUCCESS(_orig_fastpath_glAttachShader(real_obj_program,
                                  real_obj_shader)) {
@@ -2164,11 +2157,8 @@ fastpath_glDetachShader(GLuint program, GLuint shader)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj_program) != 1 ||
-                       GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj_shader) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj_program);
+       GET_PROG_REAL_OBJ(shader, &real_obj_shader);
 
        IF_GL_SUCCESS(_orig_fastpath_glDetachShader(real_obj_program,
                                  real_obj_shader)) {
@@ -2219,7 +2209,7 @@ fastpath_glIsProgram(GLuint program)
        INIT_FASTPATH_GL_FUNC();
 
        if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               ret = GL_FALSE;
+               ret = GL_FALSE;
                goto finish;
        }
 
@@ -2242,10 +2232,7 @@ fastpath_glLinkProgram(GLuint program)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glLinkProgram(real_obj);
 
@@ -2265,10 +2252,7 @@ fastpath_glValidateProgram(GLuint program)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glValidateProgram(real_obj);
 
@@ -2288,10 +2272,7 @@ fastpath_glUseProgram(GLuint program)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        if CURR_STATE_COMPARE(gl_current_program, 0, real_obj) {
                IF_GL_SUCCESS(_orig_fastpath_glUseProgram(real_obj)) {
@@ -2325,10 +2306,7 @@ fastpath_glGetActiveAttrib(GLuint program, GLuint index, GLsizei bufsize,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetActiveAttrib(real_obj, index, bufsize, length, size, type,
                                                                         name);
@@ -2350,10 +2328,7 @@ fastpath_glGetActiveUniform(GLuint program, GLuint index, GLsizei bufsize,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetActiveUniform(real_obj, index, bufsize, length, size, type,
                                                                          name);
@@ -2377,10 +2352,7 @@ fastpath_glGetAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        IF_GL_SUCCESS(_orig_fastpath_glGetAttachedShaders(real_obj, maxcount,
                                  &real_count, shaders)) {
@@ -2409,10 +2381,7 @@ fastpath_glGetAttribLocation(GLuint program, const char *name)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        ret = _orig_fastpath_glGetAttribLocation(real_obj, name);
 
@@ -2433,10 +2402,7 @@ fastpath_glGetShaderiv(GLuint shader, GLenum pname, GLint *params)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(shader, &real_obj);
 
        switch (pname) {
        case GL_DELETE_STATUS:
@@ -2466,10 +2432,7 @@ fastpath_glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(shader, &real_obj);
 
        _orig_fastpath_glGetShaderInfoLog(real_obj, bufsize, length, infolog);
 
@@ -2489,10 +2452,7 @@ fastpath_glGetProgramiv(GLuint program, GLenum pname, GLint *params)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        switch (pname) {
        case GL_DELETE_STATUS:
@@ -2522,10 +2482,7 @@ fastpath_glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetProgramInfoLog(real_obj, bufsize, length, infolog);
 
@@ -2546,10 +2503,7 @@ fastpath_glGetShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(shader, &real_obj);
 
        _orig_fastpath_glGetShaderSource(real_obj, bufsize, length, source);
 
@@ -2569,10 +2523,7 @@ fastpath_glGetUniformfv(GLuint program, GLint location, GLfloat *params)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetUniformfv(real_obj, location, params);
 
@@ -2592,10 +2543,7 @@ fastpath_glGetUniformiv(GLuint program, GLint location, GLint *params)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetUniformiv(real_obj, location, params);
 
@@ -2616,10 +2564,7 @@ fastpath_glUseProgramStagesEXT(GLuint pipeline, GLbitfield stages,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glUseProgramStagesEXT(pipeline, stages, real_obj);
 
@@ -2639,10 +2584,7 @@ _fp_glActiveShaderProgram(GLuint pipeline, GLuint program, FASTPATH_FUNC_TYPE ft
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_program_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_program_obj);
 
        if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAMPIPELINE, pipeline,
                                         &real_pipeline_obj) != 1) {
@@ -2687,10 +2629,7 @@ _fp_glProgramParameteri(GLuint program, GLenum pname, GLint value,
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        switch (ftype) {
        case FASTPATH_FUNC_TYPE_STANDARD:
@@ -2730,10 +2669,7 @@ _fp_glProgramUniformi(GLuint program, GLint location, int count, GLint *v,
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        switch (ftype) {
        case FASTPATH_FUNC_TYPE_STANDARD:
@@ -2839,10 +2775,7 @@ _fp_glProgramUniformf(GLuint program, GLint location, int count, GLfloat *v, FAS
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        switch (ftype) {
        case FASTPATH_FUNC_TYPE_STANDARD:
@@ -2950,10 +2883,7 @@ _fp_glProgramUniformiv(GLuint program, GLint location, GLsizei count,
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        switch (ftype) {
        case FASTPATH_FUNC_TYPE_STANDARD:
@@ -3059,10 +2989,7 @@ _fp_glProgramUniformfv(GLuint program, GLint location, GLsizei count,
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj) ;
 
        switch (ftype) {
        case FASTPATH_FUNC_TYPE_STANDARD:
@@ -3169,10 +3096,7 @@ fastpath_glProgramUniformMatrix2fvEXT(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj) ;
 
        _orig_fastpath_glProgramUniformMatrix2fvEXT(real_obj, location, count,
                        transpose, value);
@@ -3194,10 +3118,7 @@ fastpath_glProgramUniformMatrix3fvEXT(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix3fvEXT(real_obj, location, count,
                        transpose, value);
@@ -3219,10 +3140,7 @@ fastpath_glProgramUniformMatrix4fvEXT(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix4fvEXT(real_obj, location, count,
                        transpose, value);
@@ -3244,11 +3162,7 @@ fastpath_glGetUniformLocation(GLuint program, const char *name)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               ret = -1;
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        ret = _orig_fastpath_glGetUniformLocation(real_obj, name);
 
@@ -3268,10 +3182,7 @@ fastpath_glDeleteShader(GLuint shader)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, shader, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(shader, &real_obj);
 
        _detach_program_object(&current_ctx->ostate, real_obj, 0, 1);
 
@@ -3290,10 +3201,7 @@ fastpath_glDeleteProgram(GLuint program)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _detach_program_object(&current_ctx->ostate, real_obj, 1, 1);
 
@@ -4370,6 +4278,21 @@ finish:
        _COREGL_FASTPATH_FUNC_END();
 }
 
+static void
+_set_gl_vertex_attrib(GLGlueContext *current_ctx, GLuint index, GLfloat x, GLfloat y,
+               GLfloat z, GLfloat w)
+{
+       if (current_ctx->gl_vertex_array_binding[0] == 0) {
+               current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
+               current_ctx->gl_vertex_array_size[index] = 0;
+               current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
+
+               current_ctx->gl_vertex_attrib_value[index * 4 + 0] = x;
+               current_ctx->gl_vertex_attrib_value[index * 4 + 1] = y;
+               current_ctx->gl_vertex_attrib_value[index * 4 + 2] = z;
+               current_ctx->gl_vertex_attrib_value[index * 4 + 3] = w;
+       }
+}
 
 void
 fastpath_glVertexAttrib1f(GLuint index, GLfloat x)
@@ -4379,16 +4302,7 @@ fastpath_glVertexAttrib1f(GLuint index, GLfloat x)
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib1f(index, x)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = x;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = 0;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = 0;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = 1;
-               }
+               _set_gl_vertex_attrib(current_ctx, index, x, 0, 0, 1);
        }
        goto finish;
 
@@ -4405,16 +4319,7 @@ fastpath_glVertexAttrib1fv(GLuint index, const GLfloat *values)
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib1fv(index, values)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = values[0];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = 0;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = 0;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = 1;
-               }
+               _set_gl_vertex_attrib(current_ctx, index, values[0], 0, 0, 1);
        }
        goto finish;
 
@@ -4431,16 +4336,7 @@ fastpath_glVertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib2f(index, x, y)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = x;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = y;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = 0;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = 1;
-               }
+               _set_gl_vertex_attrib(current_ctx, index, x, y, 0, 1);
        }
        goto finish;
 
@@ -4457,16 +4353,7 @@ fastpath_glVertexAttrib2fv(GLuint index, const GLfloat *values)
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib2fv(index, values)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = values[0];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = values[1];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = 0;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = 1;
-               }
+               _set_gl_vertex_attrib(current_ctx, index, values[0], values[1], 0, 1);
        }
        goto finish;
 
@@ -4483,16 +4370,7 @@ fastpath_glVertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib3f(index, x, y, z)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = x;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = y;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = z;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = 1;
-               }
+               _set_gl_vertex_attrib(current_ctx, index, x, y, z, 1);
        }
        goto finish;
 
@@ -4509,16 +4387,7 @@ fastpath_glVertexAttrib3fv(GLuint index, const GLfloat *values)
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib3fv(index, values)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = values[0];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = values[1];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = values[2];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = 1;
-               }
+               _set_gl_vertex_attrib(current_ctx, index, values[0], values[1], values[2], 1);
        }
        goto finish;
 
@@ -4536,16 +4405,7 @@ fastpath_glVertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z,
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib4f(index, x, y, z, w)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = x;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = y;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = z;
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = w;
-               }
+               _set_gl_vertex_attrib(current_ctx, index, x, y, z, w);
        }
        goto finish;
 
@@ -4562,16 +4422,7 @@ fastpath_glVertexAttrib4fv(GLuint index, const GLfloat *values)
        INIT_FASTPATH_GL_FUNC();
 
        IF_GL_SUCCESS(_orig_fastpath_glVertexAttrib4fv(index, values)) {
-               if (current_ctx->gl_vertex_array_binding[0] == 0) {
-                       current_ctx->_vattrib_flag |= _VATTRIB_FLAG_BIT_gl_vertex_attrib_value;
-                       current_ctx->gl_vertex_array_size[index] = 0;
-                       current_ctx->gl_vertex_array_integer[index] = GL_FALSE;
-
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 0] = values[0];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 1] = values[1];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 2] = values[2];
-                       current_ctx->gl_vertex_attrib_value[index * 4 + 3] = values[3];
-               }
+               _set_gl_vertex_attrib(current_ctx, index, values[0], values[1], values[2], values[3]);
        }
        goto finish;
 
@@ -4832,10 +4683,7 @@ _fp_glGetProgramBinary(GLuint program, GLsizei bufsize, GLsizei *length,
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        switch (ftype) {
        case FASTPATH_FUNC_TYPE_STANDARD:
@@ -4889,10 +4737,7 @@ _fp_glProgramBinary(GLuint program, GLenum binaryFormat, const void *binary,
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        switch (ftype) {
        case FASTPATH_FUNC_TYPE_STANDARD:
@@ -5456,16 +5301,7 @@ _fp_glDeleteVertexArrays(GLsizei n, const GLuint *arrays, FASTPATH_FUNC_TYPE fty
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (arrays == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
+       objid_array = _init_objid_array(current_ctx, n, arrays);
        if (objid_array == NULL) goto finish;
        {
                int real_n = 0;
@@ -5794,10 +5630,7 @@ fastpath_glTransformFeedbackVaryings(GLuint program, GLsizei count,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj) ;
 
        _orig_fastpath_glTransformFeedbackVaryings(real_obj, count, varyings,
                        bufferMode);
@@ -5818,10 +5651,7 @@ fastpath_glGetTransformFeedbackVarying(GLuint program, GLuint index,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetTransformFeedbackVarying(real_obj, index, bufSize, length,
                        size, type, name);
@@ -5994,10 +5824,7 @@ fastpath_glGetUniformuiv(GLuint program, GLint location, GLuint *params)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetUniformuiv(real_obj, location, params);
 
@@ -6018,10 +5845,7 @@ fastpath_glGetFragDataLocation(GLuint program, const GLchar *name)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        ret = _orig_fastpath_glGetFragDataLocation(real_obj, name);
 
@@ -6081,10 +5905,7 @@ fastpath_glGetUniformIndices(GLuint program, GLsizei uniformCount,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetUniformIndices(real_obj, uniformCount, uniformNames,
                                                                           uniformIndices);
@@ -6106,10 +5927,7 @@ fastpath_glGetActiveUniformsiv(GLuint program, GLsizei uniformCount,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetActiveUniformsiv(real_obj, uniformCount, uniformIndices,
                                                                                 pname, params);
@@ -6131,10 +5949,7 @@ fastpath_glGetUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        ret = _orig_fastpath_glGetUniformBlockIndex(real_obj, uniformBlockName);
 
@@ -6155,10 +5970,7 @@ fastpath_glGetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetActiveUniformBlockiv(real_obj, uniformBlockIndex, pname,
                        params);
@@ -6179,10 +5991,7 @@ fastpath_glGetActiveUniformBlockName(GLuint program, GLuint uniformBlockIndex,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetActiveUniformBlockName(real_obj, uniformBlockIndex, bufSize,
                        length, uniformBlockName);
@@ -6204,10 +6013,7 @@ fastpath_glUniformBlockBinding(GLuint program, GLuint uniformBlockIndex,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glUniformBlockBinding(real_obj, uniformBlockIndex,
                                                                                 uniformBlockBinding);
@@ -7139,10 +6945,7 @@ fastpath_glProgramUniformMatrix2fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix2fv(real_obj, location, count, transpose,
                        value);
@@ -7164,10 +6967,7 @@ fastpath_glProgramUniformMatrix3fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix3fv(real_obj, location, count, transpose,
                        value);
@@ -7189,10 +6989,7 @@ fastpath_glProgramUniformMatrix4fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix4fv(real_obj, location, count, transpose,
                        value);
@@ -7323,10 +7120,7 @@ fastpath_glProgramUniform1ui(GLuint program, GLint location, GLuint x)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniform1ui(real_obj, location, x);
 
@@ -7346,10 +7140,7 @@ fastpath_glProgramUniform2ui(GLuint program, GLint location, GLuint x, GLuint y)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniform2ui(real_obj, location, x, y);
 
@@ -7370,10 +7161,7 @@ fastpath_glProgramUniform3ui(GLuint program, GLint location, GLuint x, GLuint y,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniform3ui(real_obj, location, x, y, z);
 
@@ -7394,10 +7182,7 @@ fastpath_glProgramUniform4ui(GLuint program, GLint location, GLuint x, GLuint y,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniform4ui(real_obj, location, x, y, z, w);
 
@@ -7417,10 +7202,7 @@ fastpath_glProgramUniform1uiv(GLuint program, GLint location, GLsizei count,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniform1uiv(real_obj, location, count, value);
 
@@ -7441,10 +7223,7 @@ fastpath_glProgramUniform2uiv(GLuint program, GLint location, GLsizei count,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniform2uiv(real_obj, location, count, value);
 
@@ -7465,10 +7244,7 @@ fastpath_glProgramUniform3uiv(GLuint program, GLint location, GLsizei count,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj) ;
 
        _orig_fastpath_glProgramUniform3uiv(real_obj, location, count, value);
 
@@ -7489,10 +7265,7 @@ fastpath_glProgramUniform4uiv(GLuint program, GLint location, GLsizei count,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniform4uiv(real_obj, location, count, value);
 
@@ -7512,10 +7285,7 @@ fastpath_glProgramUniformMatrix2x3fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix2x3fv(real_obj, location, count, transpose,
                        value);
@@ -7537,10 +7307,7 @@ fastpath_glProgramUniformMatrix3x2fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix3x2fv(real_obj, location, count, transpose,
                        value);
@@ -7562,10 +7329,7 @@ fastpath_glProgramUniformMatrix4x2fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix4x2fv(real_obj, location, count, transpose,
                        value);
@@ -7586,10 +7350,7 @@ fastpath_glProgramUniformMatrix2x4fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix2x4fv(real_obj, location, count, transpose,
                        value);
@@ -7611,10 +7372,7 @@ fastpath_glProgramUniformMatrix3x4fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix3x4fv(real_obj, location, count, transpose,
                        value);
@@ -7636,10 +7394,7 @@ fastpath_glProgramUniformMatrix4x3fv(GLuint program, GLint location,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glProgramUniformMatrix4x3fv(real_obj, location, count, transpose,
                        value);
@@ -8385,10 +8140,7 @@ fastpath_glGetnUniformfv(GLuint program, GLint location, GLsizei bufSize,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetnUniformfv(real_obj, location, bufSize, params);
 
@@ -8408,10 +8160,7 @@ fastpath_glGetnUniformiv(GLuint program, GLint location, GLsizei bufSize,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetnUniformiv(real_obj, location, bufSize, params);
 
@@ -8431,10 +8180,7 @@ fastpath_glGetnUniformuiv(GLuint program, GLint location, GLsizei bufSize,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (GET_REAL_OBJ(GL_OBJECT_TYPE_PROGRAM, program, &real_obj) != 1) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       GET_PROG_REAL_OBJ(program, &real_obj);
 
        _orig_fastpath_glGetnUniformuiv(real_obj, location, bufSize, params);
 
index 00fcda1..e8cb2b9 100644 (file)
@@ -682,8 +682,8 @@ finish:
        return ret;
 }
 
-void
-tracepath_mem_trace_add(const char *desc, int alloc_size)
+static void
+_mem_trace_change(const char *desc, int alloc_size, int type)
 {
        Memuse_Data *mtd = NULL;
 
@@ -692,56 +692,45 @@ tracepath_mem_trace_add(const char *desc, int alloc_size)
 
                if (mtd_table == NULL) {
                        mtd_table = (Memuse_Data **)calloc(1,
-                                                                                          sizeof(Memuse_Data *) * MAX_TRACE_TABLE_SIZE);
+                                       sizeof(Memuse_Data *) * MAX_TRACE_TABLE_SIZE);
                }
 
                mtd = (Memuse_Data *)_get_trace_data((Trace_Data **)mtd_table,
-                                                                                        sizeof(Memuse_Data), desc);
+                               sizeof(Memuse_Data), desc);
 
                AST(mtd != NULL);
 
-               mtd->alloc_count++;
+               if (type == 1) {
+                       mtd->alloc_count++;
 
-               if (mtd->memsize == 0)
-                       mtd->memsize = alloc_size;
+                       if (mtd->memsize == 0)
+                               mtd->memsize = alloc_size;
 
-               AST(mtd->memsize == alloc_size);
+                       AST(mtd->memsize == alloc_size);
+               } else if (type == 2) {
+                       AST(mtd->memsize == alloc_size);
+
+                       AST(mtd->alloc_count > mtd->remove_count);
+                       mtd->remove_count++;
+               }
 
                AST(mutex_unlock(&mtd_access_mutex) == 1);
 
                if (get_trace_mem_all_flag() == 1)
                        _COREGL_TRACE_MEM_OUTPUT(1);
        }
+}
 
+void
+tracepath_mem_trace_add(const char *desc, int alloc_size)
+{
+       _mem_trace_change(desc, alloc_size, 1);
 }
 
 void
 tracepath_mem_trace_remove(const char *desc, int alloc_size)
 {
-       Memuse_Data *mtd = NULL;
-
-       if (get_trace_mem_flag() == 1) {
-               AST(mutex_lock(&mtd_access_mutex) == 1);
-
-               if (mtd_table == NULL) {
-                       mtd_table = (Memuse_Data **)calloc(1,
-                                                                                          sizeof(Memuse_Data *) * MAX_TRACE_TABLE_SIZE);
-               }
-
-               mtd = (Memuse_Data *)_get_trace_data((Trace_Data **)mtd_table,
-                                                                                        sizeof(Memuse_Data), desc);
-
-               AST(mtd != NULL);
-               AST(mtd->memsize == alloc_size);
-
-               AST(mtd->alloc_count > mtd->remove_count);
-               mtd->remove_count++;
-
-               AST(mutex_unlock(&mtd_access_mutex) == 1);
-
-               if (get_trace_mem_all_flag() == 1)
-                       _COREGL_TRACE_MEM_OUTPUT(1);
-       }
+       _mem_trace_change(desc, alloc_size, 2);
 }
 
 void *
@@ -941,6 +930,27 @@ _print_elapsed_time(Apicall_Data **ftd_table)
        }
 }
 
+static int
+_init_tstate_ftd(GLThreadState **tstate, MY_MODULE_TSTATE **tstate_tm, Apicall_Data ***ftd_table)
+{
+       *tstate = get_current_thread_state();
+
+       if (*tstate == NULL) {
+               init_new_thread_state();
+
+               *tstate = get_current_thread_state();
+               AST(*tstate != NULL);
+       }
+
+       GET_MY_TSTATE(*tstate_tm, *tstate);
+       if (*tstate_tm == NULL) return 0;
+
+       *ftd_table = (*tstate_tm)->ftd_table;
+       if (*ftd_table == NULL) return 0;
+
+       return 1;
+}
+
 void
 tracepath_api_trace_output(int force_output)
 {
@@ -985,20 +995,8 @@ tracepath_api_trace_output(int force_output)
                                                                          traced_other_elapsed_time);
        traced_other_elapsed_time = other_elapsed_time;
 
-       tstate = get_current_thread_state();
-
-       if (tstate == NULL) {
-               init_new_thread_state();
-
-               tstate = get_current_thread_state();
-               AST(tstate != NULL);
-       }
-
-       GET_MY_TSTATE(tstate_tm, tstate);
-       if (tstate_tm == NULL) goto finish;
-
-       ftd_table = tstate_tm->ftd_table;
-       if (ftd_table == NULL) goto finish;
+       if(!_init_tstate_ftd(&tstate, &tstate_tm, &ftd_table))
+               goto finish;
 
        {
                static Apicall_Data *trace_hint_swap = NULL;
@@ -1097,20 +1095,8 @@ tracepath_api_trace_reset_frame()
                goto finish;
        }
 
-       tstate = get_current_thread_state();
-
-       if (tstate == NULL) {
-               init_new_thread_state();
-
-               tstate = get_current_thread_state();
-               AST(tstate != NULL);
-       }
-
-       GET_MY_TSTATE(tstate_tm, tstate);
-       if (tstate_tm == NULL) goto finish;
-
-       ftd_table = tstate_tm->ftd_table;
-       if (ftd_table == NULL) goto finish;
+       if(!_init_tstate_ftd(&tstate, &tstate_tm, &ftd_table))
+               goto finish;
 
        for (i = 0; i < MAX_TRACE_TABLE_SIZE; i++) {
                if (ftd_table[i] != NULL) {
index f6e8274..3bd06d6 100644 (file)
@@ -166,9 +166,8 @@ finish:
 
 #endif // COREGL_TRACEPATH_TRACE_CONTEXT_INFO
 
-
-void
-tracepath_add_context(GLContext ctx, GLDisplay dpy, GLContext share_ctx)
+static Ctx_Data *
+_get_current_ctx_data(GLContext ctx)
 {
        Ctx_Data *current = NULL;
        Ctx_Data *data = NULL;
@@ -176,7 +175,6 @@ tracepath_add_context(GLContext ctx, GLDisplay dpy, GLContext share_ctx)
        AST(mutex_lock(&ctx_access_mutex) == 1);
 
        current = ctx_data;
-
        while (current != NULL) {
                if (current->handle == ctx) {
                        data = current;
@@ -185,6 +183,15 @@ tracepath_add_context(GLContext ctx, GLDisplay dpy, GLContext share_ctx)
                current = current->next;
        }
 
+       return data;
+}
+
+
+void
+tracepath_add_context(GLContext ctx, GLDisplay dpy, GLContext share_ctx)
+{
+       Ctx_Data *data = _get_current_ctx_data(ctx);
+
        if (data == NULL) {
                data = (Ctx_Data *)calloc(1, sizeof(Ctx_Data));
                if (data == NULL) goto finish;
@@ -216,20 +223,8 @@ finish:
 Ctx_Data *
 tracepath_get_context(GLContext ctx)
 {
-       Ctx_Data *current = NULL;
-       Ctx_Data *data = NULL;
-
-       AST(mutex_lock(&ctx_access_mutex) == 1);
+       Ctx_Data *data = _get_current_ctx_data(ctx);
 
-       current = ctx_data;
-
-       while (current != NULL) {
-               if (current->handle == ctx) {
-                       data = current;
-                       break;
-               }
-               current = current->next;
-       }
        if (data == NULL) {
                COREGL_WARN("Error making context [%p] current. (invalid EGL context)", ctx);
                goto finish;