diff options
author | Kenneth Russel <[email protected]> | 2006-01-03 02:36:17 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2006-01-03 02:36:17 +0000 |
commit | b69f8b201ba3767020d33a7ebe066466f00d4223 (patch) | |
tree | ac4c77e5256026f4c1de771e49d89941645e60e2 /src/classes/com/sun/gluegen/JavaConfiguration.java | |
parent | 6b4308e8b3dc41d588ff9e7519da813705a3cd94 (diff) |
Added checks on number of remaining elements and bytes for Buffers and
arrays passed to certain APIs. Default is to not emit such range
checks. The checks are currently most fully implemented for image- and
texture-related APIs. Verified with debugging code and with demos that
all textures used in demos are properly checked.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@509 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes/com/sun/gluegen/JavaConfiguration.java')
-rw-r--r-- | src/classes/com/sun/gluegen/JavaConfiguration.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/classes/com/sun/gluegen/JavaConfiguration.java b/src/classes/com/sun/gluegen/JavaConfiguration.java index 152d9cf80..ae8c46eaa 100644 --- a/src/classes/com/sun/gluegen/JavaConfiguration.java +++ b/src/classes/com/sun/gluegen/JavaConfiguration.java @@ -116,6 +116,8 @@ public class JavaConfiguration { private Map/*<String,String>*/ javaMethodRenames = new HashMap(); private Map/*<String,List<String>>*/ javaPrologues = new HashMap(); private Map/*<String,List<String>>*/ javaEpilogues = new HashMap(); + private Map/*<String,Map<Integer,String>>*/ rangeChecks = new HashMap(); + private Map/*<String,Map<Integer,String>>*/ byteRangeChecks = new HashMap(); /** Reads the configuration file. @param filename path to file that should be read @@ -569,6 +571,22 @@ public class JavaConfiguration { return res; } + /** Returns a map of Integer argument numbers to expressions to be + used to range check the given arguments to the given function. + Returns null if there were no range check expressions supplied + for this function. */ + public Map/*<Integer, String>*/ rangeCheckExpressions(String functionName) { + return (Map/*<Integer, String>*/) rangeChecks.get(functionName); + } + + /** Returns a map of Integer argument numbers to expressions to be + used to range check (in size of bytes) the given arguments to + the given function. Returns null if there were no range check + expressions supplied for this function. */ + public Map/*<Integer, String>*/ byteRangeCheckExpressions(String functionName) { + return (Map/*<Integer, String>*/) byteRangeChecks.get(functionName); + } + //---------------------------------------------------------------------- // Internals only below this point // @@ -686,6 +704,14 @@ public class JavaConfiguration { readJavaPrologueOrEpilogue(tok, filename, lineNo, false); // Warning: make sure delimiters are reset at the top of this loop // because readJavaPrologueOrEpilogue changes them. + } else if (cmd.equalsIgnoreCase("RangeCheck")) { + readRangeCheck(tok, filename, lineNo, false); + // Warning: make sure delimiters are reset at the top of this loop + // because RangeCheck changes them. + } else if (cmd.equalsIgnoreCase("RangeCheckBytes")) { + readRangeCheck(tok, filename, lineNo, true); + // Warning: make sure delimiters are reset at the top of this loop + // because RangeCheckBytes changes them. } else { throw new RuntimeException("Unknown command \"" + cmd + "\" in command file " + filename + @@ -1131,6 +1157,33 @@ public class JavaConfiguration { } } + protected void readRangeCheck(StringTokenizer tok, String filename, int lineNo, boolean inBytes) { + try { + String functionName = tok.nextToken(); + int argNum = Integer.parseInt(tok.nextToken()); + String restOfLine = tok.nextToken("\n\r\f"); + restOfLine = restOfLine.trim(); + Map/*<Integer, String>*/ checksForFunction = null; + if (inBytes) { + checksForFunction = (Map/*<Integer, String>*/) byteRangeChecks.get(functionName); + } else { + checksForFunction = (Map/*<Integer, String>*/) rangeChecks.get(functionName); + } + if (checksForFunction == null) { + checksForFunction = new HashMap/*<Integer, String>*/(); + if (inBytes) { + byteRangeChecks.put(functionName, checksForFunction); + } else { + rangeChecks.put(functionName, checksForFunction); + } + } + checksForFunction.put(new Integer(argNum), restOfLine); + } catch (Exception e) { + throw new RuntimeException("Error parsing \"RangeCheck" + (inBytes ? "Bytes" : "") + "\" command at line " + lineNo + + " in file \"" + filename + "\"", e); + } + } + protected static TypeInfo parseTypeInfo(String cType, JavaType javaType) { String typeName = null; int pointerDepth = 0; |