Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 445d453d authored by Pablo Ceballos's avatar Pablo Ceballos Committed by Android (Google) Code Review
Browse files

Merge "glgen: Better support for null arguments in JNI"

parents cebfc641 b62e242c
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
eglInitialize check major 1 check minor 1
eglGetConfigs check configs config_size
eglChooseConfig check configs config_size check num_config 1 sentinel attrib_list EGL_NONE
eglInitialize nullAllowed major nullAllowed minor check major 1 check minor 1
eglGetConfigs nullAllowed configs check configs config_size
eglChooseConfig nullAllowed configs check configs config_size check num_config 1 sentinel attrib_list EGL_NONE
eglGetConfigAttrib check value 1
//STUB function: //eglCreateWindowSurface sentinel attrib_list EGL_NONE
eglCreatePbufferSurface sentinel attrib_list EGL_NONE
//unsupported: eglCreatePixmapSurface sentinel attrib_list EGL_NONE
//STUB function: //eglCreateWindowSurface nullAllowed attrib_list sentinel attrib_list EGL_NONE
eglCreatePbufferSurface nullAllowed attrib_list sentinel attrib_list EGL_NONE
//unsupported: eglCreatePixmapSurface nullAllowed attrib_list sentinel attrib_list EGL_NONE
eglCreatePixmapSurface unsupported
eglCopyBuffers unsupported
eglQuerySurface check value 1
eglCreatePbufferFromClientBuffer sentinel attrib_list EGL_NONE
//STUB function: eglCreatePbufferFromClientBuffer nullAllowed attrib_list sentinel attrib_list EGL_NONE
eglCreateContext sentinel attrib_list EGL_NONE
eglQueryContext check value 1
+9 −4
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
# is not perfect but better than nothing.
#

glBufferData nullAllowed check data size
glBufferData nullAllowed data check data size
glBufferSubData check data size
# glCompressedTexImage2D
# glCompressedTexSubImage2D
@@ -45,7 +45,7 @@ glGenRenderbuffers check renderbuffers n
glGenTextures check textures n
// glGetActiveAttrib
// glGetActiveUniform
glGetAttachedShaders nullAllowed check count 1 check shaders maxcount
glGetAttachedShaders nullAllowed count check count 1 check shaders maxcount
// glGetBooleanv
glGetBufferParameter check params 1
glGetClipPlanef check eqn 4
@@ -57,8 +57,10 @@ glGetFramebufferAttachmentParameterivOES check params 1
// glGetIntegerv
glGetLight ifcheck params 3 pname GL_SPOT_DIRECTION ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION
glGetMaterial ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,GL_AMBIENT_AND_DIFFUSE
glGetProgramBinary nullAllowed length
// glGetProgramInfoLog
glGetProgramiv check params 1
glGetProgramResourceiv nullAllowed length
glGetRenderbufferParameteriv check params 1
glGetRenderbufferParameterivOES check params 1
// glGetShaderInfoLog
@@ -66,6 +68,7 @@ glGetShaderiv check params 1
glGetShaderPrecisionFormat check range 1 check precision 1
// glGetShaderSource
// glGetString
glGetSynciv nullAllowed length
glGetTexEnv ifcheck params 4 pname GL_TEXTURE_ENV_COLOR
glGetTexGen ifcheck params 4 pname GL_OBJECT_PLANE,GL_EYE_PLANE
glGetTexParameter check params 1
@@ -76,15 +79,17 @@ glLightModel ifcheck params 4 pname GL_LIGHT_MODEL_AMBIENT
glLoadMatrix check m 16
glMaterial ifcheck params 4 pname GL_AMBIENT,GL_DIFFUSE,GL_SPECULAR,GL_EMISSION,GL_AMBIENT_AND_DIFFUSE
glMultMatrix check m 16
glObjectLabelKHR nullAllowed label
glPointParameter check params 1
glQueryMatrixxOES check mantissa 16 check exponent 16 return -1
# glReadPixels
glShaderBinary check binary length
// glShaderSource
glTexEnv ifcheck params 4 pname GL_TEXTURE_ENV_COLOR
glTexImage2D nullAllowed
glTexImage2D nullAllowed pixels
glTexImage3D nullAllowed pixels
glTexParameter check params 1
glTexSubImage2D nullAllowed
glTexSubImage2D nullAllowed pixels
glUniform1 check v count
glUniform2 check v count*2
glUniform3 check v count*3
+3 −3
Original line number Diff line number Diff line
@@ -19,9 +19,9 @@ glMaterial ifcheck params 1 pname GL_SHININESS ifcheck params 4 pname GL_AMBIENT
glMultMatrix check m 16
glPointParameter check params 1
glTexEnv ifcheck params 1 pname GL_TEXTURE_ENV_MODE,GL_COMBINE_RGB,GL_COMBINE_ALPHA ifcheck params 4 pname GL_TEXTURE_ENV_COLOR
glTexImage2D nullAllowed
glTexSubImage2D nullAllowed
glBufferData nullAllowed check data size
glTexImage2D nullAllowed pixels
glTexSubImage2D nullAllowed pixels
glBufferData nullAllowed data check data size
glBufferSubData check data size
glTexParameter check params 1
glQueryMatrixxOES check mantissa 16 check exponent 16 return -1
+172 −59
Original line number Diff line number Diff line
@@ -222,12 +222,13 @@ public class JniCodeEmitter {
        needsExit = true;
    }

    boolean isNullAllowed(CFunc cfunc) {
    boolean isNullAllowed(CFunc cfunc, String cname) {
        String[] checks = mChecker.getChecks(cfunc.getName());
        int index = 1;
        if (checks != null) {
            while (index < checks.length) {
                if (checks[index].equals("nullAllowed")) {
                if (checks[index].equals("nullAllowed") &&
                    checks[index + 1].equals(cname)) {
                    return true;
                } else {
                    index = skipOneCheck(checks, index);
@@ -252,6 +253,22 @@ public class JniCodeEmitter {
        return false;
    }

    boolean hasCheckTest(CFunc cfunc, String cname) {
        String[] checks = mChecker.getChecks(cfunc.getName());
        int index = 1;
        if (checks != null) {
            while (index < checks.length) {
                if (checks[index].startsWith("check") &&
                    cname != null && cname.equals(checks[index + 1])) {
                    return true;
                } else {
                    index = skipOneCheck(checks, index);
                }
            }
        }
        return false;
    }

    boolean hasIfTest(CFunc cfunc) {
        String[] checks = mChecker.getChecks(cfunc.getName());
        int index = 1;
@@ -281,7 +298,7 @@ public class JniCodeEmitter {
        } else if (checks[index].equals("requires")) {
            index += 2;
        } else if (checks[index].equals("nullAllowed")) {
            index += 1;
            index += 2;
        } else {
            System.out.println("Error: unknown keyword \"" +
                               checks[index] + "\"");
@@ -469,6 +486,37 @@ public class JniCodeEmitter {
        }
    }

    void emitStringCheck(CFunc cfunc, String cname, PrintStream out, String iii) {

        String[] checks = mChecker.getChecks(cfunc.getName());

        int index = 1;
        if (checks != null) {
            while (index < checks.length) {
                if (checks[index].startsWith("check")) {
                    if (cname != null && !cname.equals(checks[index + 1])) {
                    index += 3;
                    continue;
                }
                    out.println(iii + "_stringlen = _env->GetStringUTFLength(" + cname + ");");
                    out.println(iii + "if (" + checks[index + 2] + " > _stringlen) {");
                    out.println(iii + indent + "_exception = 1;");
                    out.println(iii + indent +
                            "_exceptionType = \"java/lang/ArrayIndexOutOfBoundsException\";");
                    out.println(iii + indent +
                            "_exceptionMessage = \"length of " + cname + " is shorter than " +
                            checks[index + 2] + " argument\";");
                    out.println(iii + indent + "goto exit;");
                    out.println(iii + "}");
                    index += 3;
                    needsExit = true;
                } else {
                    index = skipOneCheck(checks, index);
                }
            }
        }
    }

    void emitLocalVariablesForSentinel(CFunc cfunc, PrintStream out) {

        String[] checks = mChecker.getChecks(cfunc.getName());
@@ -1066,12 +1114,20 @@ public class JniCodeEmitter {

        // Emit local variable declaration for strings
        if (stringArgs.size() > 0) {
            boolean requiresStringLengthCheck = false;
            for (int i = 0; i < stringArgs.size(); i++) {
                int idx = stringArgs.get(i).intValue();
                int cIndex = jfunc.getArgCIndex(idx);
                String cname = cfunc.getArgName(cIndex);

                out.println(indent + "const char* _native" + cname + " = 0;");
                if (hasCheckTest(cfunc, cname)) {
                    requiresStringLengthCheck = true;
                }
            }

            if (requiresStringLengthCheck) {
                out.println(indent + "jsize _stringlen = 0;");
            }

            out.println();
@@ -1084,8 +1140,15 @@ public class JniCodeEmitter {
                int cIndex = jfunc.getArgCIndex(idx);
                String cname = cfunc.getArgName(cIndex);

                boolean nullAllowed = isNullAllowed(cfunc, cname);
                String nullAllowedIndent = nullAllowed ? indent : "";

                CType type = cfunc.getArgType(jfunc.getArgCIndex(idx));
                String decl = type.getDeclaration();

                if (nullAllowed) {
                    out.println(indent + "if (" + cname + ") {");
                } else {
                    needsExit = true;
                    out.println(indent + "if (!" + cname + ") {");
                    out.println(indent + indent + "_exception = 1;");
@@ -1095,8 +1158,16 @@ public class JniCodeEmitter {
                            "_exceptionMessage = \"" + cname + " == null\";");
                    out.println(indent + indent + "goto exit;");
                    out.println(indent + "}");
                }

                out.println(indent + "_native" + cname + " = _env->GetStringUTFChars(" + cname + ", 0);");
                out.println(nullAllowedIndent + indent + "_native" + cname +
                        " = _env->GetStringUTFChars(" + cname + ", 0);");

                emitStringCheck(cfunc, cname, out, nullAllowedIndent + indent);

                if (nullAllowed) {
                    out.println(indent + "}");
                }
            }

            out.println();
@@ -1115,85 +1186,126 @@ public class JniCodeEmitter {
                remaining = ((numArrays + numBuffers) <= 1) ? "_remaining" :
                    "_" + cname + "Remaining";

                boolean nullAllowed = isNullAllowed(cfunc, cname);
                String nullAllowedIndent = nullAllowed ? indent : "";

                if (jfunc.getArgType(idx).isArray()
                       && !jfunc.getArgType(idx).isEGLHandle()) {
                    needsExit = true;

                    if (nullAllowed) {
                        out.println(indent + "if (" + cname + "_ref) {");
                    }
                    else
                    {
                        out.println(indent + "if (!" + cname + "_ref) {");
                        out.println(indent + indent + "_exception = 1;");
                        out.println(indent + indent +
                                "_exceptionType = \"java/lang/IllegalArgumentException\";");
                                "_exceptionType = " +
                                "\"java/lang/IllegalArgumentException\";");
                        out.println(indent + indent +
                                "_exceptionMessage = \"" + cname +" == null\";");
                                "_exceptionMessage = \"" + cname +
                                " == null\";");
                        out.println(indent + indent + "goto exit;");
                        out.println(indent + "}");
                    out.println(indent + "if (" + offset + " < 0) {");
                    out.println(indent + indent + "_exception = 1;");
                    out.println(indent + indent +
                                "_exceptionType = \"java/lang/IllegalArgumentException\";");
                    out.println(indent + indent +
                    }

                    out.println(nullAllowedIndent + indent + "if (" + offset +
                            " < 0) {");
                    out.println(nullAllowedIndent + indent + indent +
                            "_exception = 1;");
                    out.println(nullAllowedIndent + indent + indent +
                            "_exceptionType = " +
                            "\"java/lang/IllegalArgumentException\";");
                    out.println(nullAllowedIndent + indent + indent +
                            "_exceptionMessage = \"" + offset +" < 0\";");
                    out.println(indent + indent + "goto exit;");
                    out.println(indent + "}");
                    out.println(nullAllowedIndent + indent + indent +
                            "goto exit;");
                    out.println(nullAllowedIndent + indent + "}");

                    out.println(indent + remaining + " = " +
                    out.println(nullAllowedIndent + indent + remaining + " = " +
                            (mUseCPlusPlus ? "_env" : "(*_env)") +
                            "->GetArrayLength(" +
                            (mUseCPlusPlus ? "" : "_env, ") +
                            cname + "_ref) - " + offset + ";");

                    emitNativeBoundsChecks(cfunc, cname, out, false,
                                           emitExceptionCheck,
                                           offset, remaining, "    ");
                            emitExceptionCheck, offset, remaining,
                            nullAllowedIndent + indent);

                    out.println(indent +
                    out.println(nullAllowedIndent + indent +
                                cname +
                                "_base = (" +
                                cfunc.getArgType(cIndex).getDeclaration() +
                                ")");
                    String arrayGetter = jfunc.getArgType(idx).getArrayGetterForPrimitiveArray();
                    out.println(indent + "    " +
                    out.println(nullAllowedIndent + indent + "    " +
                                (mUseCPlusPlus ? "_env" : "(*_env)") +
                                "->" + arrayGetter + "(" +
                                (mUseCPlusPlus ? "" : "_env, ") +
                                jfunc.getArgName(idx) +
                                "_ref, (jboolean *)0);");
                    out.println(indent +
                    out.println(nullAllowedIndent + indent +
                                cname + " = " + cname + "_base + " + offset + ";");

                    emitSentinelCheck(cfunc, cname, out, false,
                                      emitExceptionCheck, offset,
                                      remaining, indent);
                            emitExceptionCheck, offset, remaining,
                            nullAllowedIndent + indent);

                    if (nullAllowed) {
                        out.println(indent + "}");
                    }

                    out.println();
                } else if (jfunc.getArgType(idx).isArray()
                              && jfunc.getArgType(idx).isEGLHandle()) {
                    needsExit = true;

                    if (nullAllowed) {
                        out.println(indent + "if (" + cname + "_ref) {");
                    }
                    else
                    {
                        out.println(indent + "if (!" + cname + "_ref) {");
                        out.println(indent + indent + "_exception = 1;");
                    out.println(indent + indent +
                                "_exceptionType = \"java/lang/IllegalArgumentException\";");
                    out.println(indent + indent + "_exceptionMessage = \"" + cname +" == null\";");
                    out.println(indent + indent + "goto exit;");
                    out.println(indent + "}");
                    out.println(indent + "if (" + offset + " < 0) {");
                    out.println(indent + indent + "_exception = 1;");
                    out.println(indent + indent +
                                "_exceptionType = \"java/lang/IllegalArgumentException\";");
                    out.println(indent + indent + "_exceptionMessage = \"" + offset +" < 0\";");
                        out.println(indent + indent + "_exceptionType = " +
                                "\"java/lang/IllegalArgumentException\";");
                        out.println(indent + indent + "_exceptionMessage = \"" +
                                cname +" == null\";");
                        out.println(indent + indent + "goto exit;");
                        out.println(indent + "}");
                    }

                    out.println(nullAllowedIndent + indent + "if (" + offset +
                            " < 0) {");
                    out.println(nullAllowedIndent + indent + indent +
                            "_exception = 1;");
                    out.println(nullAllowedIndent + indent + indent +
                            "_exceptionType = " +
                            "\"java/lang/IllegalArgumentException\";");
                    out.println(nullAllowedIndent + indent + indent +
                            "_exceptionMessage = \"" + offset +" < 0\";");
                    out.println(nullAllowedIndent + indent + indent +
                            "goto exit;");
                    out.println(nullAllowedIndent + indent + "}");

                    out.println(indent + remaining + " = " +
                    out.println(nullAllowedIndent + indent + remaining + " = " +
                                    (mUseCPlusPlus ? "_env" : "(*_env)") +
                                    "->GetArrayLength(" +
                                    (mUseCPlusPlus ? "" : "_env, ") +
                                    cname + "_ref) - " + offset + ";");
                    emitNativeBoundsChecks(cfunc, cname, out, false,
                                           emitExceptionCheck,
                                           offset, remaining, "    ");
                    out.println(indent +
                            emitExceptionCheck, offset, remaining,
                            nullAllowedIndent + indent);
                    out.println(nullAllowedIndent + indent +
                                jfunc.getArgName(idx) + " = new " +
                                cfunc.getArgType(cIndex).getBaseType() +
                               "["+ remaining + "];");

                    if (nullAllowed) {
                        out.println(indent + "}");
                    }

                    out.println();
                } else if (jfunc.getArgType(idx).isBuffer()) {
                    String array = numBufferArgs <= 1 ? "_array" :
@@ -1201,7 +1313,7 @@ public class JniCodeEmitter {
                    String bufferOffset = numBufferArgs <= 1 ? "_bufferOffset" :
                        "_" + cfunc.getArgName(cIndex) + "BufferOffset";

                    boolean nullAllowed = isNullAllowed(cfunc) || isPointerFunc;
                    nullAllowed = nullAllowed || isPointerFunc;
                    if (nullAllowed) {
                        out.println(indent + "if (" + cname + "_buf) {");
                        out.print(indent);
@@ -1254,7 +1366,8 @@ public class JniCodeEmitter {
                String array = numBufferArgs <= 1 ? "_array" :
                            "_" + cfunc.getArgName(cIndex) + "Array";

                boolean nullAllowed = isNullAllowed(cfunc) || isPointerFunc;
                boolean nullAllowed = isNullAllowed(cfunc, cname) ||
                        isPointerFunc;
                if (nullAllowed) {
                    out.println(indent + "if (" + cname + "_buf && " + cname +" == NULL) {");
                } else {
+23 −27
Original line number Diff line number Diff line
@@ -13,12 +13,7 @@ android_eglCreatePbufferFromClientBuffer
    jint _remaining;
    EGLint *attrib_list = (EGLint *) 0;

    if (!attrib_list_ref) {
        _exception = 1;
        _exceptionType = "java/lang/IllegalArgumentException";
        _exceptionMessage = "attrib_list == null";
        goto exit;
    }
    if (attrib_list_ref) {
        if (offset < 0) {
            _exception = 1;
            _exceptionType = "java/lang/IllegalArgumentException";
@@ -42,6 +37,7 @@ android_eglCreatePbufferFromClientBuffer
            _exceptionMessage = "attrib_list must contain EGL_NONE!";
            goto exit;
        }
    }

    _returnValue = eglCreatePbufferFromClientBuffer(
        (EGLDisplay)dpy_native,
Loading