Skip to content

Commit

Permalink
Do not validate structs passed as output parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Sep 29, 2016
1 parent b854621 commit 7808282
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
*/
package org.lwjgl.generator

import org.lwjgl.generator.GenerationMode.ALTERNATIVE
import org.lwjgl.generator.GenerationMode.NORMAL
import org.lwjgl.generator.GenerationMode.*
import org.lwjgl.generator.ParameterType.*
import java.io.PrintWriter
import java.util.*
Expand Down Expand Up @@ -246,7 +245,7 @@ class NativeClassFunction(
nativeType.isPointerData ->
if ( nativeType is ArrayType )
name
else if ( !isAutoSizeResultOut && (has(nullable) || (has(optional) && mode === GenerationMode.NORMAL)) )
else if ( !isAutoSizeResultOut && (has(nullable) || (has(optional) && mode === NORMAL)) )
"memAddressSafe($name)"
else
"memAddress($name)"
Expand Down Expand Up @@ -447,9 +446,9 @@ class NativeClassFunction(

if ( it has AutoSize ) {
val autoSize = it[AutoSize]
if ( mode === NORMAL || it.paramType === ParameterType.INOUT ) {
if ( mode === NORMAL || it.paramType === INOUT ) {
var expression = it.name
if ( it.paramType === ParameterType.INOUT ) {
if ( it.paramType === INOUT ) {
if ( it.nativeType is ArrayType )
expression += "[0]"
else
Expand Down Expand Up @@ -493,7 +492,7 @@ class NativeClassFunction(
// Second pass
getNativeParams().forEach {
// Do this after the AutoSize check
if ( it.nativeType is StructType && it.nativeType.definition.validations.any() && !hasUnsafeMethod )
if ( it.paramType != OUT && it.nativeType is StructType && it.nativeType.definition.validations.any() && !hasUnsafeMethod )
checks.add(
"${it.nativeType.javaMethodType}.validate(${it.name}.address()${sequenceOf(
if ( it.has(Check) ) it[Check].expression else null,
Expand Down Expand Up @@ -553,7 +552,7 @@ class NativeClassFunction(
if ( hasUnsafeMethod )
writer.generateUnsafeMethod(macro)

if ( returns.nativeType !is CharSequenceType && parameters.none { it has AutoSize && it.paramType == ParameterType.IN } )
if ( returns.nativeType !is CharSequenceType && parameters.none { it has AutoSize && it.paramType == IN } )
writer.generateJavaMethod(macro)

writer.generateAlternativeMethods()
Expand Down Expand Up @@ -629,7 +628,7 @@ class NativeClassFunction(
getNativeParams().forEach {
if ( it.nativeType.mapping === PointerMapping.OPAQUE_POINTER && !it.has(nullable) && it.nativeType !is ObjectType )
checks.add("checkPointer(${it.name});")
else if ( it.nativeType is StructType && it.nativeType.definition.validations.any() )
else if ( it.paramType != OUT && it.nativeType is StructType && it.nativeType.definition.validations.any() )
checks.add(
"${it.nativeType.javaMethodType}.validate(${it.name}${sequenceOf(
if ( it.has(Check) ) it[Check].expression else null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ val BGFXPlatform = "BGFXPlatform".nativeClass(packageName = BGFX_PACKAGE, prefix
This call should be only used on platforms that don't allow creating separate rendering thread. If it is called before to #init(), render thread won't
be created by #init() call.
"""
""",

returnDoc = "current renderer state"
)

void(
Expand Down
13 changes: 2 additions & 11 deletions modules/templates/src/main/kotlin/org/lwjgl/nanovg/NVGTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,7 @@ val NVGpaint = struct(NANOVG_PACKAGE, "NVGPaint", nativeName = "NVGpaint") {

val charptr = "char".p // address, not data

val NVGcompositeOperationState_p = struct_p(NANOVG_PACKAGE, "NVGCompositeOperationState", nativeName = "NVGcompositeOperationState") {
documentation = ""

int.member("srcRGB", "")
int.member("dstRGB", "")
int.member("srcAlpha", "")
int.member("dstAlpha", "")
}

val NVGglyphPosition_p = struct_p(NANOVG_PACKAGE, "NVGGlyphPosition", nativeName = "NVGglyphPosition") {
val NVGglyphPosition_p = struct_p(NANOVG_PACKAGE, "NVGGlyphPosition", nativeName = "NVGglyphPosition", mutable = false) {
documentation = "A glyph position."

charptr.member("str", "position of the glyph in the input string")
Expand All @@ -74,7 +65,7 @@ val NVGglyphPosition_p = struct_p(NANOVG_PACKAGE, "NVGGlyphPosition", nativeName
float.member("maxx", "the right bound of the glyph shape")
}

val NVGtextRow_p = struct_p(NANOVG_PACKAGE, "NVGTextRow", nativeName = "NVGtextRow") {
val NVGtextRow_p = struct_p(NANOVG_PACKAGE, "NVGTextRow", nativeName = "NVGtextRow", mutable = false) {
documentation = "A text row."

charptr.member("start", "pointer to the input text where the row starts")
Expand Down

0 comments on commit 7808282

Please sign in to comment.