Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8244425: primitive typedef names differing only in case mapped to nested classes with names differing only in case #145

Closed
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -110,13 +110,12 @@ public void addStaticFunctionWrapper(String javaName, String nativeName, MethodT
decrAlign();
}

public void emitPrimitiveTypedef(Type.Primitive primType, String name) {
public void emitPrimitiveTypedef(Type.Primitive primType, String className) {
Type.Primitive.Kind kind = primType.kind();
if (primitiveKindSupported(kind)) {
incrAlign();
indent();
sb.append(PUB_MODS);
String className = "C" + name;
sb.append("class ");
sb.append(className);
sb.append(" extends ");
@@ -70,10 +70,19 @@
private final String pkgName;
private StructBuilder structBuilder;
private List<String> structSources = new ArrayList<>();
private Set<String> structClassNames = new HashSet<>();
private int structClassNameCount = 0;
private String uniqueStructClassName(String name) {
return structClassNames.add(name.toLowerCase())? name : (name + "$" + structClassNameCount++);
private Set<String> nestedClassNames = new HashSet<>();
private int nestedClassNameCount = 0;
/*
* We may have case-insensitive name collision! A C program may have
* defined structs/unions/typedefs with the names FooS, fooS, FoOs, fOOs.
* Because we map structs/unions/typedefs to nested classes of header classes,
* such a case-insensitive name collision is problematic. This is because in
* a case-insensitive file system javac will overwrite classes for
* Header$CFooS, Header$CfooS, Header$CFoOs and so on! We solve this by
* generating unique case-insensitive names for nested classes.
*/
private String uniqueNestedClassName(String name) {
return nestedClassNames.add(name.toLowerCase())? name : (name + "$" + nestedClassNameCount++);
}

// have we seen this Variable earlier?
@@ -239,16 +248,7 @@ public Void visitScoped(Declaration.Scoped d, Declaration parent) {
case STRUCT:
case UNION: {
structClass = true;
/*
* We may have case-insensitive name collision! A C program may have
* defined structs with the names FooS, fooS, FoOs, fOOs. Because we
* map structs and unions to nested classes of header classes, such
* a case-insensitive name collision is problematic. This is because in
* a case-insensitive file system javac will overwrite classes for
* Header$CFooS, Header$CfooS, Header$CFoOs and so on! We solve this by
* generating unique case-insensitive names for classes.
*/
String structClassName = uniqueStructClassName("C" + name);
String structClassName = uniqueNestedClassName("C" + name);
this.structBuilder = new StructBuilder(structClassName, pkgName, constantHelper);
structBuilder.incrAlign();
structBuilder.classBegin();
@@ -328,7 +328,7 @@ public Void visitTypedef(Declaration.Typedef tree, Declaration parent) {
return visitScoped(s, tree);
}
} else if (type instanceof Type.Primitive) {
builder.emitPrimitiveTypedef((Type.Primitive)type, tree.name());
builder.emitPrimitiveTypedef((Type.Primitive)type, uniqueNestedClassName("C" + tree.name()));
}
return null;
}
@@ -22,3 +22,4 @@
*/

typedef long mysize_t;
typedef long MYSIZE_T;
@@ -23,3 +23,4 @@

typedef char byte_t;
typedef long size_t;
typedef long SIZE_T;
ProTip! Use n and p to navigate between commits in a pull request.