Skip to content

Commit

Permalink
PROTON-2320 Apply first round of autopep8 (whitespace changes, mostly) (
Browse files Browse the repository at this point in the history
  • Loading branch information
jiridanek authored Jan 14, 2021
1 parent ebfe89f commit dd05347
Show file tree
Hide file tree
Showing 74 changed files with 6,258 additions and 5,953 deletions.
17 changes: 10 additions & 7 deletions c/src/encodings.h.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
#

from __future__ import print_function
import mllib, optparse, os, sys
import mllib
import optparse
import os
import sys

xml = os.path.join(os.path.dirname(__file__), "types.xml")
doc = mllib.xml_parse(xml)
Expand All @@ -31,12 +34,12 @@
print("#define PNE_DESCRIPTOR (0x00)")

for enc in doc.query["amqp/section/type/encoding"]:
name = enc["@name"] or enc.parent["@name"]
# XXX: a bit hacky
if name == "ieee-754":
name = enc.parent["@name"]
cname = "PNE_" + name.replace("-", "_").upper()
print("#define %s%s(%s)" % (cname, " "*(20-len(cname)), enc["@code"]))
name = enc["@name"] or enc.parent["@name"]
# XXX: a bit hacky
if name == "ieee-754":
name = enc.parent["@name"]
cname = "PNE_" + name.replace("-", "_").upper()
print("#define %s%s(%s)" % (cname, " "*(20-len(cname)), enc["@code"]))

print()
print("#endif /* encodings.h */")
109 changes: 58 additions & 51 deletions c/src/protocol.h.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,36 @@
fields = {}

for type in TYPES:
fidx = 0
for f in type.query["field"]:
print("#define %s_%s (%s)" % (field_kw(type), field_kw(f), fidx))
fidx += 1
d = f["@default"]
if d:
ft = ftype(f)
# Don't bother to emit a boolean default that is False
if ft=="boolean" and d=="false": continue
# Don't output non numerics unless symbol
# We should really fully resolve to actual restricted value
# this is really true for symbols too which accidentally work
if ft=="symbol": d = '"' + d + '"'
elif d[0] not in '0123456789': continue
print("#define %s_%s_DEFAULT (%s) /* %s */" % (field_kw(type), field_kw(f), d, ft))
fidx = 0
for f in type.query["field"]:
print("#define %s_%s (%s)" % (field_kw(type), field_kw(f), fidx))
fidx += 1
d = f["@default"]
if d:
ft = ftype(f)
# Don't bother to emit a boolean default that is False
if ft == "boolean" and d == "false":
continue
# Don't output non numerics unless symbol
# We should really fully resolve to actual restricted value
# this is really true for symbols too which accidentally work
if ft == "symbol":
d = '"' + d + '"'
elif d[0] not in '0123456789':
continue
print("#define %s_%s_DEFAULT (%s) /* %s */" % (field_kw(type), field_kw(f), d, ft))

idx = 0

for type in TYPES:
desc = type["descriptor"]
name = type["@name"].upper().replace("-", "_")
print("#define %s_SYM (\"%s\")" % (name, desc["@name"]))
hi, lo = [int(x, 0) for x in desc["@code"].split(":")]
code = (hi << 32) + lo
print("#define %s ((uint64_t) %s)" % (name, code))
fields[code] = (type["@name"], [f["@name"] for f in type.query["field"]])
idx += 1
desc = type["descriptor"]
name = type["@name"].upper().replace("-", "_")
print("#define %s_SYM (\"%s\")" % (name, desc["@name"]))
hi, lo = [int(x, 0) for x in desc["@code"].split(":")]
code = (hi << 32) + lo
print("#define %s ((uint64_t) %s)" % (name, code))
fields[code] = (type["@name"], [f["@name"] for f in type.query["field"]])
idx += 1

print("""
#include <stddef.h>
Expand All @@ -79,7 +82,7 @@
strings.add(name)
strings.update(fnames)
for str in strings:
istr = str.replace("-", "_");
istr = str.replace("-", "_")
print(' const char FIELD_STRINGS_%s[sizeof("%s")];' % (istr, str))
print("};")
print()
Expand All @@ -91,33 +94,33 @@
print('const struct FIELD_STRINGS FIELD_STRINGPOOL = {')
print(' "",')
for str in strings:
print(' "%s",'% str)
print(' "%s",' % str)
print("};")
print()
print("/* This is an array of offsets into FIELD_STRINGPOOL */")
print("const uint16_t FIELD_NAME[] = {")
print(" offsetof(struct FIELD_STRINGS, STRING0),")
index = 1
for i in range(256):
if i in fields:
name, fnames = fields[i]
iname = name.replace("-", "_");
print(' offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d */' % (iname, index))
index += 1
if i in fields:
name, fnames = fields[i]
iname = name.replace("-", "_")
print(' offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d */' % (iname, index))
index += 1
print("};")

print("/* This is an array of offsets into FIELD_STRINGPOOL */")
print("const uint16_t FIELD_FIELDS[] = {")
print(" offsetof(struct FIELD_STRINGS, STRING0),")
index = 1
for i in range(256):
if i in fields:
name, fnames = fields[i]
if fnames:
for f in fnames:
ifname = f.replace("-", "_");
print(' offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d (%s) */' % (ifname, index, name))
index += 1
if i in fields:
name, fnames = fields[i]
if fnames:
for f in fnames:
ifname = f.replace("-", "_")
print(' offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d (%s) */' % (ifname, index, name))
index += 1
print("};")

print("const pn_fields_t FIELDS[] = {")
Expand All @@ -127,23 +130,27 @@
field_min = 256
field_max = 0
for i in range(256):
if i in fields:
if i>field_max: field_max = i
if i<field_min: field_min = i
if i in fields:
if i > field_max:
field_max = i
if i < field_min:
field_min = i

for i in range(field_min, field_max+1):
if i in fields:
name, fnames = fields[i]
if fnames:
print(' {%d, %d, %d}, /* %d (%s) */' % (name_count, field_count, len(fnames), i, name))
field_count += len(fnames)
if i in fields:
name, fnames = fields[i]
if fnames:
print(' {%d, %d, %d}, /* %d (%s) */' % (name_count, field_count, len(fnames), i, name))
field_count += len(fnames)
else:
print(' {%d, 0, 0}, /* %d (%s) */' % (name_count, i, name))
name_count += 1
if i > field_max:
field_max = i
if i < field_min:
field_min = i
else:
print(' {%d, 0, 0}, /* %d (%s) */' % (name_count, i, name))
name_count += 1
if i>field_max: field_max = i
if i<field_min: field_min = i
else:
print(' {0, 0, 0}, /* %d */' % i)
print(' {0, 0, 0}, /* %d */' % i)

print("};")
print()
Expand Down
135 changes: 74 additions & 61 deletions c/src/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
# specific language governing permissions and limitations
# under the License.
#
import mllib, os, sys
import mllib
import os
import sys

doc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "transport.xml"))
mdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "messaging.xml"))
tdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "transactions.xml"))
sdoc = mllib.xml_parse(os.path.join(os.path.dirname(__file__), "security.xml"))


def eq(attr, value):
return lambda nd: nd[attr] == value
return lambda nd: nd[attr] == value


TYPEStmp = doc.query["amqp/section/type", eq("@class", "composite")] + \
mdoc.query["amqp/section/type", eq("@class", "composite")] + \
Expand All @@ -33,89 +37,98 @@ def eq(attr, value):
mdoc.query["amqp/section/type", eq("@provides", "section")]
TYPES = []
for ty in TYPEStmp:
if not ty in TYPES:
TYPES.append(ty)
if not ty in TYPES:
TYPES.append(ty)
RESTRICTIONS = {}
COMPOSITES = {}

for type in doc.query["amqp/section/type"] + mdoc.query["amqp/section/type"] + \
sdoc.query["amqp/section/type"] + tdoc.query["amqp/section/type"]:
sdoc.query["amqp/section/type"] + tdoc.query["amqp/section/type"]:

source = type["@source"]
if source:
RESTRICTIONS[type["@name"]] = source
if type["@class"] == "composite":
COMPOSITES[type["@name"]] = type

source = type["@source"]
if source:
RESTRICTIONS[type["@name"]] = source
if type["@class"] == "composite":
COMPOSITES[type["@name"]] = type

def resolve(name):
if name in RESTRICTIONS:
return resolve(RESTRICTIONS[name])
else:
return name
if name in RESTRICTIONS:
return resolve(RESTRICTIONS[name])
else:
return name


TYPEMAP = {
"boolean": ("bool", "", ""),
"binary": ("pn_binary_t", "*", ""),
"string": ("wchar_t", "*", ""),
"symbol": ("char", "*", ""),
"ubyte": ("uint8_t", "", ""),
"ushort": ("uint16_t", "", ""),
"uint": ("uint32_t", "", ""),
"ulong": ("uint64_t", "", ""),
"timestamp": ("uint64_t", "", ""),
"list": ("pn_list_t", "*", ""),
"map": ("pn_map_t", "*", ""),
"box": ("pn_box_t", "*", ""),
"*": ("pn_object_t", "*", "")
}
"boolean": ("bool", "", ""),
"binary": ("pn_binary_t", "*", ""),
"string": ("wchar_t", "*", ""),
"symbol": ("char", "*", ""),
"ubyte": ("uint8_t", "", ""),
"ushort": ("uint16_t", "", ""),
"uint": ("uint32_t", "", ""),
"ulong": ("uint64_t", "", ""),
"timestamp": ("uint64_t", "", ""),
"list": ("pn_list_t", "*", ""),
"map": ("pn_map_t", "*", ""),
"box": ("pn_box_t", "*", ""),
"*": ("pn_object_t", "*", "")
}

CONSTRUCTORS = {
"boolean": "boolean",
"string": "string",
"symbol": "symbol",
"ubyte": "ubyte",
"ushort": "ushort",
"uint": "uint",
"ulong": "ulong",
"timestamp": "ulong"
}
"boolean": "boolean",
"string": "string",
"symbol": "symbol",
"ubyte": "ubyte",
"ushort": "ushort",
"uint": "uint",
"ulong": "ulong",
"timestamp": "ulong"
}

NULLABLE = set(["string", "symbol"])


def fname(field):
return field["@name"].replace("-", "_")
return field["@name"].replace("-", "_")


def tname(t):
return t["@name"].replace("-", "_")
return t["@name"].replace("-", "_")


def multi(f):
return f["@multiple"] == "true"
return f["@multiple"] == "true"


def ftype(field):
if multi(field):
return "list"
elif field["@type"] in COMPOSITES:
return "box"
else:
return resolve(field["@type"]).replace("-", "_")
if multi(field):
return "list"
elif field["@type"] in COMPOSITES:
return "box"
else:
return resolve(field["@type"]).replace("-", "_")


def fconstruct(field, expr):
type = ftype(field)
if type in CONSTRUCTORS:
result = "pn_%s(mem, %s)" % (CONSTRUCTORS[type], expr)
if type in NULLABLE:
result = "%s ? %s : NULL" % (expr, result)
else:
result = expr
if multi(field):
result = "pn_box(mem, pn_boolean(mem, true), %s)" % result
return result
type = ftype(field)
if type in CONSTRUCTORS:
result = "pn_%s(mem, %s)" % (CONSTRUCTORS[type], expr)
if type in NULLABLE:
result = "%s ? %s : NULL" % (expr, result)
else:
result = expr
if multi(field):
result = "pn_box(mem, pn_boolean(mem, true), %s)" % result
return result


def declaration(field):
name = fname(field)
type = ftype(field)
t, pre, post = TYPEMAP.get(type, (type, "", ""))
return t, "%s%s%s" % (pre, name, post)
name = fname(field)
type = ftype(field)
t, pre, post = TYPEMAP.get(type, (type, "", ""))
return t, "%s%s%s" % (pre, name, post)


def field_kw(field):
return fname(field).upper()
return fname(field).upper()
6 changes: 4 additions & 2 deletions c/tests/fdlimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def test_fd_limit_broker(self):
self.assertEqual(sender.wait(), 0)

# Additional send/receive should succeed now
self.assertIn("10 messages sent", test_subprocess.check_output(["send", "", b.port], universal_newlines=True))
self.assertIn("10 messages received", test_subprocess.check_output(["receive", "", b.port], universal_newlines=True))
self.assertIn("10 messages sent", test_subprocess.check_output(
["send", "", b.port], universal_newlines=True))
self.assertIn("10 messages received", test_subprocess.check_output(
["receive", "", b.port], universal_newlines=True))


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit dd05347

Please sign in to comment.