aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/sun/gluegen/JavaConfiguration.java11
-rw-r--r--src/java/com/sun/gluegen/cgram/types/Field.java3
-rw-r--r--src/java/com/sun/gluegen/cgram/types/FunctionType.java12
-rw-r--r--src/java/com/sun/gluegen/cgram/types/PointerType.java10
-rw-r--r--src/java/com/sun/gluegen/opengl/GLEmitter.java3
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java7
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java27
-rwxr-xr-xsrc/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java5
8 files changed, 63 insertions, 15 deletions
diff --git a/src/java/com/sun/gluegen/JavaConfiguration.java b/src/java/com/sun/gluegen/JavaConfiguration.java
index e7787fc..8cde267 100644
--- a/src/java/com/sun/gluegen/JavaConfiguration.java
+++ b/src/java/com/sun/gluegen/JavaConfiguration.java
@@ -1018,8 +1018,12 @@ public class JavaConfiguration {
protected void readCustomJavaCode(StringTokenizer tok, String filename, int lineNo) {
try {
String className = tok.nextToken();
- String restOfLine = tok.nextToken("\n\r\f");
- addCustomJavaCode(className, restOfLine);
+ try {
+ String restOfLine = tok.nextToken("\n\r\f");
+ addCustomJavaCode(className, restOfLine);
+ } catch (NoSuchElementException e) {
+ addCustomJavaCode(className, "");
+ }
} catch (NoSuchElementException e) {
throw new RuntimeException("Error parsing \"CustomJavaCode\" command at line " + lineNo +
" in file \"" + filename + "\"", e);
@@ -1036,8 +1040,7 @@ public class JavaConfiguration {
String restOfLine = tok.nextToken("\n\r\f");
customCCode.add(restOfLine);
} catch (NoSuchElementException e) {
- throw new RuntimeException("Error parsing \"CustomCCode\" command at line " + lineNo +
- " in file \"" + filename + "\"", e);
+ customCCode.add("");
}
}
diff --git a/src/java/com/sun/gluegen/cgram/types/Field.java b/src/java/com/sun/gluegen/cgram/types/Field.java
index 996d716..e6ec18d 100644
--- a/src/java/com/sun/gluegen/cgram/types/Field.java
+++ b/src/java/com/sun/gluegen/cgram/types/Field.java
@@ -95,7 +95,8 @@ public class Field {
return "" + getType() + " " + getName() + ";";
} else {
FunctionType ft = getType().asPointer().getTargetType().asFunction();
- return ft.toString(getName(), false, true) + ";";
+ // FIXME: pick up calling convention?
+ return ft.toString(getName(), null, false, true) + ";";
}
}
}
diff --git a/src/java/com/sun/gluegen/cgram/types/FunctionType.java b/src/java/com/sun/gluegen/cgram/types/FunctionType.java
index e109121..7a9c2b5 100644
--- a/src/java/com/sun/gluegen/cgram/types/FunctionType.java
+++ b/src/java/com/sun/gluegen/cgram/types/FunctionType.java
@@ -108,15 +108,19 @@ public class FunctionType extends Type {
}
public String toString(String functionName, boolean emitNativeTag) {
- return toString(functionName, emitNativeTag, false);
+ return toString(functionName, null, emitNativeTag, false);
}
- String toString(String functionName, boolean emitNativeTag, boolean isPointer) {
+ String toString(String functionName, String callingConvention, boolean emitNativeTag, boolean isPointer) {
StringBuffer res = new StringBuffer();
res.append(getReturnType());
res.append(" ");
if (isPointer) {
- res.append("(*");
+ res.append("(");
+ if (callingConvention != null) {
+ res.append(callingConvention);
+ }
+ res.append("*");
}
if (functionName != null) {
if (emitNativeTag) {
@@ -137,7 +141,7 @@ public class FunctionType extends Type {
Type t = getArgumentType(i);
if (t.isFunctionPointer()) {
FunctionType ft = t.asPointer().getTargetType().asFunction();
- res.append(ft.toString(getArgumentName(i), false, true));
+ res.append(ft.toString(getArgumentName(i), callingConvention, false, true));
} else if (t.isArray()) {
res.append(t.asArray().toString(getArgumentName(i)));
} else {
diff --git a/src/java/com/sun/gluegen/cgram/types/PointerType.java b/src/java/com/sun/gluegen/cgram/types/PointerType.java
index 6202505..f95066a 100644
--- a/src/java/com/sun/gluegen/cgram/types/PointerType.java
+++ b/src/java/com/sun/gluegen/cgram/types/PointerType.java
@@ -117,16 +117,18 @@ public class PointerType extends Type {
if (!targetType.isFunction()) {
return targetType.toString() + " * " + getCVAttributesString();
}
- return toString(null); // this is a pointer to an unnamed function
+ return toString(null, null); // this is a pointer to an unnamed function
}
}
- /** For use only when printing function pointers */
- public String toString(String functionName) {
+ /** For use only when printing function pointers. Calling convention
+ string (i.e., "__stdcall") is optional and is generally only
+ needed on Windows. */
+ public String toString(String functionName, String callingConvention) {
if (!targetType.isFunction()) {
throw new RuntimeException("<Internal error or misuse> This method is only for use when printing function pointers");
}
- return ((FunctionType) targetType).toString(functionName, false, true);
+ return ((FunctionType) targetType).toString(functionName, callingConvention, false, true);
}
public void visit(TypeVisitor arg) {
diff --git a/src/java/com/sun/gluegen/opengl/GLEmitter.java b/src/java/com/sun/gluegen/opengl/GLEmitter.java
index b9c4349..ae4d5ec 100644
--- a/src/java/com/sun/gluegen/opengl/GLEmitter.java
+++ b/src/java/com/sun/gluegen/opengl/GLEmitter.java
@@ -360,6 +360,9 @@ public class GLEmitter extends ProcAddressEmitter
iter.remove(); // remove ARB function
// make the function being dynamical fetched, due to it's dynamic naming scheme
((GLConfiguration)cfg).addForceProcAddressGen(uniName.getUni());
+ // Make sure we produce the right calling convention for
+ // the typedefed function pointers on Windows
+ ((GLConfiguration)cfg).addLocalProcAddressCallingConvention(uniName.getUni(), "GL_APIENTRY");
}
}
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
index 41bae10..b7aadc9 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressCMethodBindingEmitter.java
@@ -47,6 +47,7 @@ import com.sun.gluegen.cgram.types.*;
public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
private boolean callThroughProcAddress;
private boolean needsLocalTypedef;
+ private String localTypedefCallingConvention;
private static String procAddressJavaTypeName =
JavaType.createForClass(Long.TYPE).jniTypeName();
private ProcAddressEmitter emitter;
@@ -54,6 +55,7 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
public ProcAddressCMethodBindingEmitter(CMethodBindingEmitter methodToWrap,
final boolean callThroughProcAddress,
boolean needsLocalTypedef,
+ String localTypedefCallingConvention,
ProcAddressEmitter emitter) {
super(
new MethodBinding(methodToWrap.getBinding()) {
@@ -95,6 +97,7 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
setCommentEmitter(defaultCommentEmitter);
this.callThroughProcAddress = callThroughProcAddress;
this.needsLocalTypedef = needsLocalTypedef;
+ this.localTypedefCallingConvention = localTypedefCallingConvention;
this.emitter = emitter;
}
@@ -131,7 +134,7 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
funcPointerTypedefName = "_local_" + funcPointerTypedefName;
writer.print(" typedef ");
- writer.print(funcPtrType.toString(funcPointerTypedefName));
+ writer.print(funcPtrType.toString(funcPointerTypedefName, localTypedefCallingConvention));
writer.println(";");
}
@@ -151,7 +154,7 @@ public class ProcAddressCMethodBindingEmitter extends CMethodBindingEmitter {
if (callThroughProcAddress) {
if (!emittingPrimitiveArrayCritical) {
- // set the function pointer to the value of the passed-in glProcAddress
+ // set the function pointer to the value of the passed-in procAddress
FunctionSymbol cSym = getBinding().getCSymbol();
String funcPointerTypedefName = emitter.getFunctionPointerTypedefName(cSym);
if (needsLocalTypedef) {
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java b/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
index de4000c..7099745 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressConfiguration.java
@@ -55,6 +55,10 @@ public class ProcAddressConfiguration extends JavaConfiguration
private Set/*<String>*/ forceProcAddressGenSet = new HashSet();
private String getProcAddressTableExpr;
private ConvNode procAddressNameConverter;
+ // This is needed only on Windows. Ideally we would modify the
+ // HeaderParser and PCPP to automatically pick up the calling
+ // convention from the headers
+ private Map/*<String,String>*/ localProcAddressCallingConventionMap = new HashMap();
protected void dispatch(String cmd, StringTokenizer tok, File file, String filename, int lineNo) throws IOException {
if (cmd.equalsIgnoreCase("EmitProcAddressTable"))
@@ -87,6 +91,10 @@ public class ProcAddressConfiguration extends JavaConfiguration
{
readProcAddressNameExpr(tok, filename, lineNo);
}
+ else if (cmd.equalsIgnoreCase("LocalProcAddressCallingConvention"))
+ {
+ readLocalProcAddressCallingConvention(tok, filename, lineNo);
+ }
else
{
super.dispatch(cmd,tok,file,filename,lineNo);
@@ -134,6 +142,17 @@ public class ProcAddressConfiguration extends JavaConfiguration
}
}
+ protected void readLocalProcAddressCallingConvention(StringTokenizer tok, String filename, int lineNo) throws IOException {
+ try {
+ String functionName = tok.nextToken();
+ String callingConvention = tok.nextToken();
+ localProcAddressCallingConventionMap.put(functionName, callingConvention);
+ } catch (NoSuchElementException e) {
+ throw new RuntimeException("Error parsing \"LocalProcAddressCallingConvention\" command at line " + lineNo +
+ " in file \"" + filename + "\"", e);
+ }
+ }
+
private static ConvNode makeConverter(Iterator/*<String>*/ iter) {
List/*<ConvNode>*/ result = new ArrayList/*<ConvNode>*/();
while (iter.hasNext()) {
@@ -261,4 +280,12 @@ public class ProcAddressConfiguration extends JavaConfiguration
forceProcAddressGen.add(funcName);
forceProcAddressGenSet.add(funcName);
}
+
+ public void addLocalProcAddressCallingConvention(String funcName, String callingConvention) {
+ localProcAddressCallingConventionMap.put(funcName, callingConvention);
+ }
+
+ public String getLocalProcAddressCallingConvention(String funcName) {
+ return (String) localProcAddressCallingConventionMap.get(funcName);
+ }
}
diff --git a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
index 6b837c1..288ffa9 100755
--- a/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
+++ b/src/java/com/sun/gluegen/procaddress/ProcAddressEmitter.java
@@ -227,6 +227,10 @@ public class ProcAddressEmitter extends JavaEmitter
// See whether we need a proc address entry for this one
boolean callThroughProcAddress = needsProcAddressWrapper(baseCEmitter.getBinding().getCSymbol());
boolean forceProcAddress = getProcAddressConfig().forceProcAddressGen(baseCEmitter.getBinding().getCSymbol().getName());
+ String forcedCallingConvention = null;
+ if (forceProcAddress) {
+ forcedCallingConvention = getProcAddressConfig().getLocalProcAddressCallingConvention(baseCEmitter.getBinding().getCSymbol().getName());
+ }
// Note that we don't care much about the naming of the C argument
// variables so to keep things simple we ignore the buffer object
// property for the binding
@@ -237,6 +241,7 @@ public class ProcAddressEmitter extends JavaEmitter
ProcAddressCMethodBindingEmitter res = new ProcAddressCMethodBindingEmitter(baseCEmitter,
callThroughProcAddress,
forceProcAddress,
+ forcedCallingConvention,
this);
MessageFormat exp = baseCEmitter.getReturnValueCapacityExpression();
if (exp != null) {