Skip to content

Commit

Permalink
Warn on missing maxlength
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaszm committed Jan 12, 2024
1 parent 30fc35a commit 9d17204
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions JsonGenerator/source/class_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _EmitEnum(enum):
log.Info("Emitting enum {}".format(enum.cpp_class))

if enum.description:
emit.Line("// " + enum.description)
emit.Line("// " + enum.description.split("\n",1)[0])

emit.Line("enum%s %s : uint%i_t {" % (" class" if enum.is_scoped else "", enum.cpp_class, enum.size))
emit.Indent()
Expand Down Expand Up @@ -314,7 +314,7 @@ def _EmitValidator(json_obj):
emit.Indent()

for prop in json_obj.properties:
comment = prop.print_name if isinstance(prop, JsonMethod) else prop.description
comment = prop.print_name if isinstance(prop, JsonMethod) else prop.description.split("\n",1)[0] if prop.description else ""
emit.Line("%s %s;%s" % (prop.short_cpp_type, prop.cpp_name, (" // " + comment) if comment else ""))

if IsObjectRestricted(json_obj):
Expand Down
3 changes: 3 additions & 0 deletions JsonGenerator/source/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __exit__(self, exc_type, exc_value, traceback):
self.file.close()

def Line(self, text = ""):
if "\n" in text:
assert("Invalid characters in the emitted line")

if text != "":
commented = "// " if "//" in text else ""
text = (" " * self.indent) + str(text)
Expand Down
2 changes: 1 addition & 1 deletion JsonGenerator/source/json_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, name, parent, schema, included=None):
self.grand_parent = self.grand_parent.parent

if self.grand_parent:
if not self.description:
if not self.description and isinstance(parent, JsonProperty):
self.description = self.grand_parent.summary

self.iterator = schema.get("iterator")
Expand Down
16 changes: 9 additions & 7 deletions ProxyStubGenerator/StubGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,10 @@ def _FindLength(length_name, variable_name):
self.max_length = _FindLength(self.identifier.meta.maxlength, (name[1:] + "Len"))

if (is_buffer and not self.length and self.is_input):
raise TypenameError(self.identifier, "'%s': an input raw buffer requires a @length tag" % self.trace_proto)
raise TypenameError(self.identifier, "'%s': an outbound buffer requires a @length tag" % self.trace_proto)

if (is_buffer and (not self.length and not self.max_length) and self.is_output):
raise TypenameError(self.identifier, "'%s': an output-only raw buffer requires a @maxlength tag" % self.trace_proto)
raise TypenameError(self.identifier, "'%s': an inbound-only buffer requires a @maxlength tag" % self.trace_proto)

self.is_buffer = ((self.length or self.max_length) and is_buffer)

Expand All @@ -773,16 +773,18 @@ def _FindLength(length_name, variable_name):

if self.is_input and self.is_output:
log.WarnLine(self.identifier, \
"'%s': maximum length of this input/output buffer is assumed to be same as @length, use @maxlength to disambiguate" % \
"'%s': maximum length of this inbound/outbound buffer is assumed to be same as @length, use @maxlength to disambiguate" % \
(self.trace_proto))
else:
log.InfoLine(self.identifier, "'%s': @maxlength not specified, assuming same as @length" % self.trace_proto)
elif self.is_input_only:
log.InfoLine(self.identifier, "'%s': @maxlength not specified for this inbound buffer, assuming same as @length" % self.trace_proto)
elif self.is_output_only and not self.length.is_output:
raise TypenameError(self.identifier, "'%s': @maxlength not specified for this inbound buffer" % self.trace_proto)

if (self.is_buffer and self.is_output and not self.max_length):
raise TypenameError(self.identifier, "'%s': can't deduce maximum length of the buffer, use @maxlength" % self.trace_proto)
raise TypenameError(self.identifier, "'%s': can't deduce maximum length of this inbound buffer, use @maxlength" % self.trace_proto)

if (self.is_buffer and self.max_length and not self.length):
log.WarnLine(self.identifier, "'%s': length of returned buffer is not specified; using @maxlength, but this may be inefficient" % self.trace_proto)
log.WarnLine(self.identifier, "'%s': length of this inbound buffer is not specified; using @maxlength, but this may be inefficient" % self.trace_proto)
self.length = self.max_length

# Is it a hresult?
Expand Down

0 comments on commit 9d17204

Please sign in to comment.