-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Add nullability marker annotations #344
Conversation
7246c08
to
1df8a28
Compare
1df8a28
to
0b4e712
Compare
3958ee4
to
039d78f
Compare
I just cloned this branch into a fresh environment and realized that the latest commits seem to be missing some changes. I'll quickly rebase and fix this. |
9e237fe
to
c49cffa
Compare
Rebased and updated. Should be good to go now (this time for real)! |
2b947c2
to
e1a7372
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the most part, this is looking good. All I found was one issue and a few nitpicky parts.
I would like to hear your opinions first before I change anything.
@@ -365,6 +367,9 @@ val NativeType.isPointer | |||
val NativeType.isPointerData | |||
get() = this is PointerType && this.mapping !== PointerMapping.OPAQUE_POINTER | |||
|
|||
val NativeType.isPointerObject | |||
get() = this is PointerType && (this.mapping !== PointerMapping.OPAQUE_POINTER || this is ObjectType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This, currently, does not seem to include JObjectType
s which I think I fixed and is something that was lost at some point. IIRC this was also the reason to make JObjectType
a class.
Changing the expression to (this is PointerType && (this.mapping !== PointerMapping.OPAQUE_POINTER || this is ObjectType)) || this is JObjectType
should to the trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I refactored some aspects of the type system a bit and this was simplified to:
this !is ValueType && (this.mapping !== PointerMapping.OPAQUE_POINTER || this is ObjectType)
The property was also renamed to isReference
, which I think is more appropriate.
@@ -531,23 +532,31 @@ public ByteBuffer ASCII(CharSequence text) { | |||
/** | |||
* Encodes the specified text on the stack using ASCII encoding and returns a ByteBuffer that points to the encoded text. | |||
* | |||
* @param text the text to encode. If {@code text} is null, null is returned. | |||
* @param text the text to encode | |||
* @param nullTerminated if true, a null-terminator is included at the end of the encoded text | |||
*/ | |||
public ByteBuffer ASCII(CharSequence text, boolean nullTerminated) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the documentation of "text encoding"-methods does not refer to any "allocation"-method we should probably explicitly document what happens if the operation fails here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's nothing special about the encoding methods, they fail in the same way as other stack allocation methods with an OutOfMemoryError("Out of stack space.")
.
@@ -442,6 +493,19 @@ public static long nmemAlignedAlloc(long alignment, long size) { | |||
return ALLOCATOR.aligned_alloc(alignment, size); | |||
} | |||
|
|||
public static long nmemAlignedAllocChecked(long alignment, long size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is missing documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
doc/notes/3.1.6.md
Outdated
- Added additional nullability information with [JSR-305](https://jcp.org/en/jsr/detail?id=305) annotations. | ||
* Enables null-analysis to be used to improve the code quality of LWJGL applications. | ||
* Improves type-safety for applications using LWJGL in Kotlin | ||
([Read the Kotlin documentation](https://kotlinlang.org/docs/reference/java-interop.html#jsr-305-support) for more info.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should probably be a dot (.
) at the end of the last bullet point.
I'm not quite sure whether I like the current wording. Any objections?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the wording a bit.
e1a7372
to
17976eb
Compare
17976eb
to
82f02e5
Compare
The next snapshot ( Thank you @TheMrMilchmann for the great work! |
As previously discussed in Slack, this PR adds JSR-305 like annotations to support null-analysis and to enhance Kotlin interopertability. (See here for more info.)
@Spasi As suggested I did not add
@Nullable
to most stack allocation methods (the exception being String conversion methods, since they can also benull
when the passedCharSequence
isnull
).I'm open for further suggestions and will implement them ASAP if requested.