mbeckerle commented on code in PR #918:
URL: https://github.com/apache/daffodil/pull/918#discussion_r1074049892
##########
daffodil-test/src/test/resources/org/apache/daffodil/section12/length_properties/LengthProperties.tdml:
##########
@@ -911,7 +911,7 @@
<xs:element name="bit26" type="xs:short" dfdl:lengthKind="explicit"
dfdl:length="5" dfdl:byteOrder="bigEndian" />
<xs:element name="bit27" type="xs:int" dfdl:lengthKind="explicit"
dfdl:length="9" dfdl:byteOrder="bigEndian" />
- <xs:element name="bit28" type="xs:integer" dfdl:lengthKind="explicit"
dfdl:length="13" dfdl:byteOrder="bigEndian" />
+ <xs:element name="bit28" type="xs:int" dfdl:lengthKind="explicit"
dfdl:length="13" dfdl:byteOrder="bigEndian" />
Review Comment:
Lots of schemas from 3rd parties may run in to this issue. I have seen
schemas where the author tends to use the more general type xs:integer thinking
it is equivalent to all the smaller types.
I think we need to look beyond just Daffodil's tests to see the impact of
this change.
##########
daffodil-test/src/test/resources/org/apache/daffodil/section12/lengthKind/ExplicitTests.tdml:
##########
@@ -903,4 +903,37 @@
</tdml:infoset>
</tdml:parserTestCase>
+<!--
+ Test Name: invalidLengthUnits_explicit
+ Schema: invalidLengthUnits_explicit
+ Root: r1
+ Purpose: This test checks that a warning is emitted when a bigint is
used when lengthUnits='bits'.
+-->
+ <tdml:defineSchema name="invalidLengthUnits_explicit">
+ <xs:include
schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+ <dfdl:defineFormat name="Binary">
+ <dfdl:format ref="ex:GeneralFormat" representation="binary"/>
+ </dfdl:defineFormat>
+ <dfdl:format ref="ex:Binary" />
+
+ <xs:element name="r1" dfdl:lengthKind="explicit" type="xs:integer"
dfdl:lengthUnits="bits" dfdl:length="8"/>
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase name="invalidLengthUnits_explicit" root="r1"
model="invalidLengthUnits_explicit"
+ description="">
+ <tdml:document>
+ <tdml:documentPart type="byte">
+ 0f
+ </tdml:documentPart>
+ </tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>f
+ <r1>15</r1>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:warnings>
+ <tdml:warning>lengthUnits='bits' will only be supported for integer
types of 64 bits or less</tdml:warning>
Review Comment:
I think the message should not say "integer types of 64 bits or less" but
say lengthUnits bits is not supported for xs:integer nor xs:nonNegativeInteger.
Why.. because this is perfectly legal: <element name="x" type="xs:integer"
dfdl:length="3" dfdl:lengthUnits="bytes"/> which is a 24-bit integer. So is
that an integer of type 64 bits or less?
It's the types that cause the issue, not the 64. The restriction was to make
DFDL easier to implement as a byte-centric big-num library would suffice for
xs:integer and xs:nonNegativeInteger.
##########
daffodil-core/src/main/scala/org/apache/daffodil/grammar/ElementBaseGrammarMixin.scala:
##########
@@ -546,7 +554,13 @@ trait ElementBaseGrammarMixin
private def explicitBinaryLengthInBits() = {
val lengthFromProp: JLong = repElement.lengthEv.optConstant.get
val nbits = repElement.lengthUnits match {
- case LengthUnits.Bits => lengthFromProp.longValue()
+ case LengthUnits.Bits => repElement.primType match {
+ case PrimType.Integer | PrimType.NonNegativeInteger => {
+ SDW(WarnID.DeprecatedTypeUse, "In a future release,
lengthUnits='bits' will only be supported for integer types of 64 bits or less")
Review Comment:
Say lengthUnits 'bits' will not be supported for types xs:integer and
xs:nonNegativeInteger.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]