Skip to content

Commit

Permalink
* Fix Parser incorrectly translating non-documentation comments as…
Browse files Browse the repository at this point in the history
… part of documentation comments (issue #475)

 * Set `Pointer.maxPhysicalBytes` to `4 * Runtime.maxMemory()` by default as workaround for memory-mapped files, ZGC, etc (issue #468)
  • Loading branch information
saudet committed May 7, 2021
1 parent d788390 commit 343045d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

* Fix `Parser` incorrectly translating non-documentation comments as part of documentation comments ([issue #475](https://github.com/bytedeco/javacpp/issues/475))
* Set `Pointer.maxPhysicalBytes` to `4 * Runtime.maxMemory()` by default as workaround for memory-mapped files, ZGC, etc ([issue #468](https://github.com/bytedeco/javacpp/issues/468))
* Ensure `synchronized` code in `Pointer` gets skipped with "org.bytedeco.javacpp.nopointergc" ([issue tensorflow/java#313](https://github.com/tensorflow/java/issues/313))
* Add `protected Pointer.offsetAddress()` and use it for `getPointer()` instead of `position()`
* Fix potential infinite loop in `Parser` when processing `class`, `struct`, or `union` declarations
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/bytedeco/javacpp/Pointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ static class DeallocatorThread extends Thread {
static final long maxBytes;

/** Maximum amount of memory reported by {@link #physicalBytes()} before forcing call to {@link System#gc()}.
* Set via "org.bytedeco.javacpp.maxPhysicalBytes" system property, defaults to {@code maxBytes > 0 ? maxBytes + Runtime.maxMemory() : 0}.
* If {@link #maxBytes} is also not set, this is equivalent to a default of {@code 2 * Runtime.maxMemory()}.
* Set via "org.bytedeco.javacpp.maxPhysicalBytes" system property, defaults to {@code maxBytes > 0 ? maxBytes + 3 * Runtime.maxMemory() : 0}.
* If {@link #maxBytes} is also not set, this is equivalent to a default of {@code 4 * Runtime.maxMemory()}.
* The value is parsed with {@link #parseBytes(String, long)} where {@code relativeMultiple = Runtime.maxMemory()}.
* We can use a value of 0 or less to prevent any explicit call to the garbage collector. */
static final long maxPhysicalBytes;
Expand Down Expand Up @@ -489,7 +489,7 @@ public static long parseBytes(String string, long relativeMultiple) throws Numbe
}
maxBytes = m;

m = maxBytes > 0 ? maxBytes + maxMemory : 0;
m = maxBytes > 0 ? maxBytes + 3 * maxMemory : 0;
s = System.getProperty("org.bytedeco.javacpp.maxphysicalbytes");
s = System.getProperty("org.bytedeco.javacpp.maxPhysicalBytes", s);
if (s != null && s.length() > 0) {
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/bytedeco/javacpp/tools/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ String commentBefore() throws ParserException {
for (Token token = tokens.get(); token.match(Token.COMMENT); token = tokens.next()) {
String s = token.value;
if (s.startsWith("/**") || s.startsWith("/*!") || s.startsWith("///") || s.startsWith("//!")) {
if (s.startsWith("//") && s.contains("*/") && s.indexOf("*/") < s.length() - 2) {
if (s.startsWith("//") && s.contains("*/") && startDoc >= 0) {
s = s.replace("*/", "* /");
}
if (s.length() > 3 && s.charAt(3) == '<') {
Expand All @@ -1727,6 +1727,10 @@ String commentBefore() throws ParserException {
startDoc = comment.length();
}
comment += token.spacing + s;
if (startDoc >= 0 && comment.endsWith("*/")) {
comment = commentDoc(comment, startDoc);
startDoc = -1;
}
}
if (closeComment && !comment.endsWith("*/")) {
comment += " */";
Expand Down Expand Up @@ -1768,6 +1772,10 @@ String commentAfter() throws ParserException {
startDoc = comment.length();
}
comment += spacing.substring(0, n) + s;
if (startDoc >= 0 && comment.endsWith("*/")) {
comment = commentDoc(comment, startDoc);
startDoc = -1;
}
}
}
if (closeComment && !comment.endsWith("*/")) {
Expand Down Expand Up @@ -3672,7 +3680,7 @@ boolean enumeration(Context context, DeclarationList declList) throws ParserExce
Info info = infoMap.getFirst(cppName);
Info info2 = infoMap.getFirst(null);
boolean enumerate = info != null ? info.enumerate : info2 != null ? info2.enumerate : false;
if (info != null && info.skip) {
if ((info != null && info.skip) || (enumerators.length() == 0 && enumerators2.length() == 0)) {
decl.text = enumSpacing;
} else {
if (info != null && info.cppTypes != null && info.cppTypes.length > 0) {
Expand Down

0 comments on commit 343045d

Please sign in to comment.