Commit 83b41822 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

A train-trip worth of python3 migration and other polishing

parent 3ed8d7db
...@@ -7,50 +7,50 @@ import sys ...@@ -7,50 +7,50 @@ import sys
regex = re.compile("^HPH\((.{4}), (.{10}), +(.{1,3})\)") regex = re.compile("^HPH\((.{4}), (.{10}), +(.{1,3})\)")
if len(sys.argv) != 2: if len(sys.argv) != 2:
print("{} takes one and only one argument".format(sys.argv[0])) print("{} takes one and only one argument".format(sys.argv[0]))
sys.exit(2) sys.exit(2)
class sym: class sym:
def __init__(self, bigval, bigvall, chr = 0, esc = None): def __init__(self, bigval, bigvall, chr=0, esc=None):
self.vall = bigvall % 8 if bigvall % 8 else 8 self.vall = bigvall % 8 if bigvall % 8 else 8
self.val = bigval & ((1 << self.vall) - 1) self.val = bigval & ((1 << self.vall) - 1)
self.pfx = (bigval >> self.vall)# & 0xff self.pfx = (bigval >> self.vall)# & 0xff
self.chr = chr self.chr = chr
self.esc = esc self.esc = esc
tbls = {} tbls = {}
msl = {} # max sym length msl = {} # max sym length
f = open(sys.argv[1]) f = open(sys.argv[1])
for l in f: for l in f:
grp = 1 grp = 1
match = regex.match(l) match = regex.match(l)
if not match: if not match:
continue continue
chr = int(match.group(grp), 16) char = int(match.group(grp), 16)
grp += 1 grp += 1
val = int(match.group(grp), 16) val = int(match.group(grp), 16)
grp += 1 grp += 1
vall = int(match.group(grp)) vall = int(match.group(grp))
s = sym(val, vall, chr) s = sym(val, vall, char)
if s.pfx not in tbls: if s.pfx not in tbls:
tbls[s.pfx] = {} tbls[s.pfx] = {}
if (s.val in tbls[s.pfx]): if s.val in tbls[s.pfx]:
assert(tbls[s.pfx][s.val].e) assert tbls[s.pfx][s.val].e
tbls[s.pfx][s.val] = s tbls[s.pfx][s.val] = s
# add the escape entry in the "previous" table # add the escape entry in the "previous" table
if s.pfx: if s.pfx:
pp = s.pfx >> 8 pp = s.pfx >> 8
pv = s.pfx & 0xff pv = s.pfx & 0xff
if pp not in tbls: if pp not in tbls:
tbls[pp] = {} tbls[pp] = {}
tbls[pp][pv] = sym(pv, 8, 0, "&tbl_{:x}".format(s.pfx)) tbls[pp][pv] = sym(pv, 8, 0, "&tbl_{:x}".format(s.pfx))
f.close() f.close()
# add the EOS case # add the EOS case
...@@ -64,33 +64,33 @@ print('''/* NB: This file is machine generated, DO NOT EDIT! ...@@ -64,33 +64,33 @@ print('''/* NB: This file is machine generated, DO NOT EDIT!
struct stbl; struct stbl;
struct ssym { struct ssym {
uint8_t csm; /* bits consumed */ uint8_t csm; /* bits consumed */
uint8_t chr; /* character */ uint8_t chr; /* character */
struct stbl *nxt; /* next table */ struct stbl *nxt; /* next table */
}; };
struct stbl { struct stbl {
int msk; int msk;
struct ssym *syms; struct ssym *syms;
}; };
''') ''')
for pfx in sorted(tbls.keys(), reverse=True): for pfx in sorted(tbls.keys(), reverse=True):
msl = max([ x.vall for x in tbls[pfx].values() ]) msl = max([x.vall for x in tbls[pfx].values()])
for s in tbls[pfx].values(): for s in tbls[pfx].values():
s.val = s.val << (msl - s.vall) s.val = s.val << (msl - s.vall)
tbl = sorted(tbls[pfx].values(), key= lambda x: x.val) tbl = sorted(tbls[pfx].values(), key=lambda x: x.val)
print("\nstatic struct ssym sym_{:x}_array[] = {{".format(pfx)) print("\nstatic struct ssym sym_{:x}_array[] = {{".format(pfx))
for s in tbl: for s in tbl:
for j in range(2 ** (msl - s.vall)): for j in range(2 ** (msl - s.vall)):
print(" {} {{{}, {:3d}, {}}},".format( print("{} {{{}, {:3d}, {}}},".format(
"\t " if j else "/* idx {:3d} */".format(s.val + j), "\t " if j else "/* idx {:3d} */".format(s.val + j),
s.vall, s.chr % 256, s.vall, s.chr % 256,
s.esc if s.esc else "NULL")) s.esc if s.esc else "NULL"))
print('''}}; print('''}};
static struct stbl tbl_{:x} = {{ static struct stbl tbl_{:x} = {{
{}, {},
sym_{:x}_array sym_{:x}_array
}};'''.format(pfx, msl, pfx)) }};'''.format(pfx, msl, pfx))
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
# This script is in the public domain # This script is in the public domain
# #
# Run instructions: # Run instructions:
# varnishtest -W -iv -j <pick_a_number> > _.w # varnishtest -W -iv -j <pick_a_number> > _.w
# python witness.py # python witness.py
# dot -Tpng /tmp/_.dot > /tmp/_.png # dot -Tpng /tmp/_.dot > /tmp/_.png
from __future__ import print_function from __future__ import print_function
...@@ -16,37 +16,37 @@ fi = open("_.w") ...@@ -16,37 +16,37 @@ fi = open("_.w")
fo = open("/tmp/_.dot", "w") fo = open("/tmp/_.dot", "w")
fo.write('''digraph { fo.write('''digraph {
#rotate="90" #rotate="90"
#page="8.2,11.7" #page="8.2,11.7"
size="8.2,11.7" size="8.2,11.7"
rankdir="LR" rankdir="LR"
node [fontname="Inconsolata", fontsize="10"] node [fontname="Inconsolata", fontsize="10"]
edge [fontname="Inconsolata", fontsize="10"] edge [fontname="Inconsolata", fontsize="10"]
''') ''')
for i in fi: for i in fi:
l = "ROOT" l = "ROOT"
j = i.split() j = i.split()
if len(j) < 8: if len(j) < 8:
continue continue
if j[1][0] != 'v': if j[1][0] != 'v':
continue continue
if j[3] != "vsl|": if j[3] != "vsl|":
continue continue
if j[5] != "Witness": if j[5] != "Witness":
continue continue
t = j[7:] t = j[7:]
tt = str(t) tt = str(t)
if tt in d: if tt in d:
continue continue
d[tt] = True d[tt] = True
for e in t: for e in t:
f = e.split(",") f = e.split(",")
x = '"%s" -> "%s" [label="%s(%s)"]\n' % (l, f[0], f[1], f[2]) x = '"%s" -> "%s" [label="%s(%s)"]\n' % (l, f[0], f[1], f[2])
if not x in a: if not x in a:
a[x] = True a[x] = True
fo.write(x) fo.write(x)
l = f[0] l = f[0]
fo.write("}\n") fo.write("}\n")
...@@ -35,50 +35,49 @@ import re ...@@ -35,50 +35,49 @@ import re
def parse_file(fn, cl, tl, sl): def parse_file(fn, cl, tl, sl):
p = False p = False
section = "" section = ""
resec = re.compile("[ /]\* SECTION: ") resec = re.compile("[ /]\* SECTION: ")
f = open(fn, "r") f = open(fn, "r")
for l in f: for l in f:
if "*/" in l: if "*/" in l:
p = 0 p = 0
if resec.match(l): if resec.match(l):
a = l.split() a = l.split()
section = a[2] section = a[2]
sl.append(section) sl.append(section)
cl[section] = [] cl[section] = []
if len(a) > 3: if len(a) > 3:
tl[section] = re.sub( tl[section] = re.sub(
r"^[\t ]*\/?\* SECTION: [^ ]+ +", r"^[\t ]*\/?\* SECTION: [^ ]+ +",
"", l) "", l)
else: else:
tl[section] = "" tl[section] = ""
p = 1 p = 1
elif p: elif p:
cl[section].append(re.sub(r"^ \* ?", "", l)) cl[section].append(re.sub(r"^ \* ?", "", l))
f.close() f.close()
if __name__ == "__main__": if __name__ == "__main__":
cl = {} cl = {}
tl = {} tl = {}
sl = [] sl = []
for fn in sys.argv[1:]: for fn in sys.argv[1:]:
parse_file(fn, cl, tl, sl) parse_file(fn, cl, tl, sl)
sl.sort() sl.sort()
for section in sl: for section in sl:
print(tl[section], end="") print(tl[section], end="")
a = section a = section
c = section.count(".") c = section.count(".")
if c == 0: if c == 0:
r = "-" r = "-"
elif c == 1: elif c == 1:
r = "~" r = "~"
elif c == 2: elif c == 2:
r = "." r = "."
else: else:
r = "*" r = "*"
print(re.sub(r".", r, tl[section]), end="") print(re.sub(r".", r, tl[section]), end="")
print("".join(cl[section])) print("".join(cl[section]))
...@@ -108,7 +108,7 @@ vcl.h: \ ...@@ -108,7 +108,7 @@ vcl.h: \
$(top_srcdir)/include/vrt.h \ $(top_srcdir)/include/vrt.h \
$(top_srcdir)/doc/sphinx/reference/vcl_var.rst $(top_srcdir)/doc/sphinx/reference/vcl_var.rst
mkdir -p $(top_builddir)/include/tbl mkdir -p $(top_builddir)/include/tbl
@PYTHON@ $(top_srcdir)/lib/libvcc/generate.py \ ${PYTHON} $(top_srcdir)/lib/libvcc/generate.py \
$(top_srcdir) $(top_builddir) $(top_srcdir) $(top_builddir)
GEN_H = \ GEN_H = \
...@@ -128,7 +128,7 @@ vcs_version.h: ...@@ -128,7 +128,7 @@ vcs_version.h:
@if test -e $(top_srcdir)/.git || \ @if test -e $(top_srcdir)/.git || \
! test -f $(srcdir)/vmod_abi.h || \ ! test -f $(srcdir)/vmod_abi.h || \
! test -f $(srcdir)/vcs_version.h ; then \ ! test -f $(srcdir)/vcs_version.h ; then \
@PYTHON@ $(srcdir)/generate.py \ ${PYTHON} $(srcdir)/generate.py \
$(top_srcdir) $(top_builddir) ; \ $(top_srcdir) $(top_builddir) ; \
fi fi
......
...@@ -32,22 +32,21 @@ ...@@ -32,22 +32,21 @@
from __future__ import print_function from __future__ import print_function
import subprocess import subprocess
import collections
import os import os
import sys import sys
srcroot = "../.." srcroot = "../.."
buildroot = "../.." buildroot = "../.."
if len(sys.argv) == 3: if len(sys.argv) == 3:
srcroot = sys.argv[1] srcroot = sys.argv[1]
buildroot = sys.argv[2] buildroot = sys.argv[2]
elif len(sys.argv) != 1: elif len(sys.argv) != 1:
print("Two arguments or none") print("Two arguments or none")
exit(2) exit(2)
####################################################################### #######################################################################
def file_header(fo): def file_header(fo):
fo.write("""/* fo.write("""/*
* NB: This file is machine generated, DO NOT EDIT! * NB: This file is machine generated, DO NOT EDIT!
* *
* Edit and run include/generate.py instead. * Edit and run include/generate.py instead.
...@@ -66,25 +65,25 @@ v = subprocess.check_output([ ...@@ -66,25 +65,25 @@ v = subprocess.check_output([
vcsfn = os.path.join(srcroot, "include", "vcs_version.h") vcsfn = os.path.join(srcroot, "include", "vcs_version.h")
try: try:
i = open(vcsfn).readline() i = open(vcsfn).readline()
except IOError: except IOError:
i = "" i = ""
ident = "/* " + v + " */\n" ident = "/* " + v + " */\n"
if i != ident: if i != ident:
fo = open(vcsfn, "w") fo = open(vcsfn, "w")
fo.write(ident) fo.write(ident)
file_header(fo) file_header(fo)
fo.write('#define VCS_Version "%s"\n' % v) fo.write('#define VCS_Version "%s"\n' % v)
fo.close() fo.close()
for i in open(os.path.join(buildroot, "Makefile")): for i in open(os.path.join(buildroot, "Makefile")):
if i[:14] == "PACKAGE_STRING": if i[:14] == "PACKAGE_STRING":
break break
i = i.split("=")[1].strip() i = i.split("=")[1].strip()
fo = open(os.path.join(srcroot, "include", "vmod_abi.h"), "w") fo = open(os.path.join(srcroot, "include", "vmod_abi.h"), "w")
file_header(fo) file_header(fo)
fo.write('#define VMOD_ABI_Version "%s %s"\n' % (i, v)) fo.write('#define VMOD_ABI_Version "%s %s"\n' % (i, v))
fo.close() fo.close()
...@@ -47,6 +47,7 @@ H2_SETTING( // rfc7540,l,2097,2103 ...@@ -47,6 +47,7 @@ H2_SETTING( // rfc7540,l,2097,2103
0xffffffff, 0xffffffff,
0 0
) )
#ifndef H2_SETTINGS_PARAM_ONLY #ifndef H2_SETTINGS_PARAM_ONLY
H2_SETTING( // rfc7540,l,2105,2114 H2_SETTING( // rfc7540,l,2105,2114
ENABLE_PUSH, ENABLE_PUSH,
...@@ -58,6 +59,7 @@ H2_SETTING( // rfc7540,l,2105,2114 ...@@ -58,6 +59,7 @@ H2_SETTING( // rfc7540,l,2105,2114
H2CE_PROTOCOL_ERROR H2CE_PROTOCOL_ERROR
) )
#endif #endif
H2_SETTING( // rfc7540,l,2116,2121 H2_SETTING( // rfc7540,l,2116,2121
MAX_CONCURRENT_STREAMS, MAX_CONCURRENT_STREAMS,
max_concurrent_streams, max_concurrent_streams,
...@@ -67,6 +69,7 @@ H2_SETTING( // rfc7540,l,2116,2121 ...@@ -67,6 +69,7 @@ H2_SETTING( // rfc7540,l,2116,2121
0xffffffff, 0xffffffff,
0 0
) )
H2_SETTING( // rfc7540,l,2139,2148 H2_SETTING( // rfc7540,l,2139,2148
INITIAL_WINDOW_SIZE, INITIAL_WINDOW_SIZE,
initial_window_size, initial_window_size,
...@@ -76,6 +79,7 @@ H2_SETTING( // rfc7540,l,2139,2148 ...@@ -76,6 +79,7 @@ H2_SETTING( // rfc7540,l,2139,2148
0x7fffffff, 0x7fffffff,
H2CE_FLOW_CONTROL_ERROR H2CE_FLOW_CONTROL_ERROR
) )
H2_SETTING( // rfc7540,l,2150,2157 H2_SETTING( // rfc7540,l,2150,2157
MAX_FRAME_SIZE, MAX_FRAME_SIZE,
max_frame_size, max_frame_size,
...@@ -85,6 +89,7 @@ H2_SETTING( // rfc7540,l,2150,2157 ...@@ -85,6 +89,7 @@ H2_SETTING( // rfc7540,l,2150,2157
0x00ffffff, 0x00ffffff,
H2CE_PROTOCOL_ERROR H2CE_PROTOCOL_ERROR
) )
H2_SETTING( // rfc7540,l,2159,2167 H2_SETTING( // rfc7540,l,2159,2167
MAX_HEADER_LIST_SIZE, MAX_HEADER_LIST_SIZE,
max_header_list_size, max_header_list_size,
......
...@@ -36,10 +36,11 @@ HTC_STATUS(JUNK, -5, "junk", "Received unexpected data") ...@@ -36,10 +36,11 @@ HTC_STATUS(JUNK, -5, "junk", "Received unexpected data")
HTC_STATUS(CLOSE, -4, "close", "Connection closed") // unused? HTC_STATUS(CLOSE, -4, "close", "Connection closed") // unused?
HTC_STATUS(TIMEOUT, -3, "timeout", "Timed out") HTC_STATUS(TIMEOUT, -3, "timeout", "Timed out")
HTC_STATUS(OVERFLOW, -2, "overflow", "Buffer/workspace too small") HTC_STATUS(OVERFLOW, -2, "overflow", "Buffer/workspace too small")
HTC_STATUS(EOF, -1, "eof", "Unexpected end of input") HTC_STATUS(EOF, -1, "eof", "Unexpected end of input")
HTC_STATUS(EMPTY, 0, "empty", "Empty response") HTC_STATUS(EMPTY, 0, "empty", "Empty response")
HTC_STATUS(MORE, 1, "more", "More data required") HTC_STATUS(MORE, 1, "more", "More data required")
HTC_STATUS(COMPLETE, 2, "complete", "Data complete (no error)") HTC_STATUS(COMPLETE, 2, "complete", "Data complete (no error)")
HTC_STATUS(IDLE, 3, "idle", "Connection was closed while idle") HTC_STATUS(IDLE, 3, "idle", "Connection was closed while idle")
#undef HTC_STATUS #undef HTC_STATUS
/*lint -restore */ /*lint -restore */
...@@ -7,66 +7,68 @@ from __future__ import print_function ...@@ -7,66 +7,68 @@ from __future__ import print_function
import glob import glob
def check_file(fn): def check_file(fn):
s = 0 print("Check", fn)
ll = [] ll = []
for l in open(fn): for l in open(fn):
ll.append(l) ll.append(l)
assert ll.pop(0)[:2] == "/*" assert ll.pop(0)[:2] == "/*"
while ll.pop(0) != " */\n": while ll.pop(0) != " */\n":
continue continue
assert len(ll) > 5 assert len(ll) > 5
assert ll.pop(0) == "\n" assert ll.pop(0) == "\n"
assert ll.pop(0) == "/*lint -save -e525 -e539 */\n" i = ll.pop(0)
assert ll.pop(0) == "\n" assert i == "/*lint -save -e525 -e539 */\n" or \
i == "/*lint -save -e525 -e539 -e835 */\n"
assert ll.pop(0) == "\n"
assert ll.pop(-1) == "/*lint -restore */\n" assert ll.pop(-1) == "/*lint -restore */\n"
assert ll.pop(-1) == "\n" assert ll.pop(-1) == "\n"
for i in range(0, len(ll) -1): for i in range(0, len(ll) -1):
assert ll[i] != "\n" or ll[i+1] != "\n" assert ll[i] != "\n" or ll[i+1] != "\n"
assert ll[i] != ")\n" or ll[i+1] == "\n" or ll[i+1][0] == "#" assert ll[i] != ")\n" or ll[i+1] == "\n" or ll[i+1][0] == "#"
m = {} m = {}
while len(ll) > 0: while ll:
i = ll.pop(0) i = ll.pop(0)
if i == "\n": if i == "\n":
continue continue
l = i.lstrip() l = i.lstrip()
if l[0] >= 'A' and l[0] <= 'Z': if l[0] >= 'A' and l[0] <= 'Z':
j = l.split('(') j = l.split('(')
m[j[0]] = "Called" m[j[0]] = "Called"
l = l.split('//')[0] l = l.split('//')[0]
l = l.split('/*')[0] l = l.split('/*')[0]
l = l.rstrip() l = l.rstrip()
if l[-1] != ')': if l[-1] != ')':
while ll.pop(0) != ')\n': while ll.pop(0).strip() != ')':
continue continue
elif l[0] == "#": elif l[0] == "#":
j = l[1:].lstrip().split() j = l[1:].lstrip().split()
# print("#", j[0]) # print("#", j[0])
if j[0] == "define": if j[0] == "define":
m[j[1].split("(")[0].strip()] = "Defined" m[j[1].split("(")[0].strip()] = "Defined"
if j[0] == "undef": if j[0] == "undef":
m[j[1]] = "Undef" m[j[1]] = "Undef"
while l[-2:] == "\\\n": while l[-2:] == "\\\n":
l = ll.pop(0) l = ll.pop(0)
else: else:
pass pass
# print(l) # print(l)
rv = 0 rv = 0
for i in m: for i in m:
if m[i] != "Undef": if m[i] != "Undef":
print("ERROR", fn, i, m[i]) print("ERROR", fn, i, m[i])
rv += 1 rv += 1
return rv return rv
rv = 0 rv = 0
for fn in glob.glob("*.h"): for fn in glob.glob("*.h"):
rv += check_file(fn) rv += check_file(fn)
if rv != 0: if rv != 0:
print(rv, "Errors") print(rv, "Errors")
exit(rv) exit(rv)
...@@ -181,16 +181,17 @@ SLTM(Length, 0, "Size of object body", ...@@ -181,16 +181,17 @@ SLTM(Length, 0, "Size of object body",
"Logs the size of a fetch object body.\n\n" "Logs the size of a fetch object body.\n\n"
) )
/* XXX generate HTC info from tbl include */ /*
#if 0 * XXX generate HTC info below from tbl include
#include <stdio.h> *
int main(void) { * #include <stdio.h>
#define HTC_STATUS(e, n, s, l) \ * int main(void) {
printf("\t\"\\t* %s (%d): %s\\n\"\n", s, n, l); * #define HTC_STATUS(e, n, s, l) \
#include "include/tbl/htc.h" * printf("\t\"\\t* %s (%d): %s\\n\"\n", s, n, l);
return (0); * #include "include/tbl/htc.h"
} * return (0);
#endif * }
*/
SLTM(FetchError, 0, "Error while fetching object", SLTM(FetchError, 0, "Error while fetching object",
"Logs the error message of a failed fetch operation.\n\n" "Logs the error message of a failed fetch operation.\n\n"
......
...@@ -44,3 +44,5 @@ ...@@ -44,3 +44,5 @@
WAITER(poll) WAITER(poll)
#undef WAITER #undef WAITER
/*lint -restore */
...@@ -37,122 +37,121 @@ import copy ...@@ -37,122 +37,121 @@ import copy
srcroot = "../.." srcroot = "../.."
buildroot = "../.." buildroot = "../.."
if len(sys.argv) == 3: if len(sys.argv) == 3:
srcroot = sys.argv[1] srcroot = sys.argv[1]
buildroot = sys.argv[2] buildroot = sys.argv[2]
####################################################################### #######################################################################
# These are our tokens # These are our tokens
tokens = { tokens = {
# Numerical comparisons # Numerical comparisons
"T_EQ": "==", "T_EQ": "==",
"T_NEQ": "!=", "T_NEQ": "!=",
"T_LEQ": "<=", "T_LEQ": "<=",
"T_GEQ": ">=", "T_GEQ": ">=",
# String comparisons # String comparisons
"T_SEQ": "eq", "T_SEQ": "eq",
"T_SNEQ": "ne", "T_SNEQ": "ne",
# Regular expression matching # Regular expression matching
"T_NOMATCH": "!~", "T_NOMATCH": "!~",
# Boolean operators # Boolean operators
"T_AND": "and", "T_AND": "and",
"T_OR": "or", "T_OR": "or",
"T_NOT": "not", "T_NOT": "not",
# Miscellaneous # Miscellaneous
None: "<>~[]{}():,", None: "<>~[]{}():,",
# These have handwritten recognizers # These have handwritten recognizers
"VAL": None, "VAL": None,
"EOI": None, "EOI": None,
# Special # Special
"T_TRUE": None, "T_TRUE": None,
"VXID": "vxid", "VXID": "vxid",
} }
####################################################################### #######################################################################
# Emit a function to recognize tokens in a string # Emit a function to recognize tokens in a string
def emit_vxp_fixed_token(fo, tokens): def emit_vxp_fixed_token(fo, tokens):
recog = list() recog = list()
emit = dict() emit = dict()
for i in tokens: for i in tokens:
j = tokens[i] j = tokens[i]
if (j != None): if j is not None:
recog.append(j) recog.append(j)
emit[j] = i emit[j] = i
recog.sort() recog.sort()
rrecog = copy.copy(recog) rrecog = copy.copy(recog)
rrecog.sort(key = lambda x: -len(x)) rrecog.sort(key=lambda x: -len(x))
fo.write(""" fo.write("""
unsigned unsigned
vxp_fixed_token(const char *p, const char **q) vxp_fixed_token(const char *p, const char **q)
{ {
\tswitch (p[0]) { \tswitch (p[0]) {
""") """)
last_initial = None last_initial = None
for i in recog: for i in recog:
if (i[0] == last_initial): if i[0] == last_initial:
continue continue
last_initial = i[0] last_initial = i[0]
fo.write("\tcase '%s':\n" % last_initial) fo.write("\tcase '%s':\n" % last_initial)
for j in rrecog: for j in rrecog:
if (j[0] != last_initial): if j[0] != last_initial:
continue continue
fo.write("\t\tif (") fo.write("\t\tif (")
k = 1 k = 1
l = len(j) l = len(j)
while (k < l): while k < l:
fo.write("p[%d] == '%s'" % (k, j[k])) fo.write("p[%d] == '%s'" % (k, j[k]))
fo.write(" &&\n\t\t ") fo.write(" &&\n\t\t ")
k += 1 k += 1
fo.write("(isword(p[%d]) ? !isword(p[%d]) : 1)) {\n" % fo.write("(isword(p[%d]) ? !isword(p[%d]) : 1)) {\n" % (l - 1, l))
(l - 1, l)) fo.write("\t\t\t*q = p + %d;\n" % l)
fo.write("\t\t\t*q = p + %d;\n" % l) fo.write("\t\t\treturn (%s);\n" % emit[j])
fo.write("\t\t\treturn (%s);\n" % emit[j]) fo.write("\t\t}\n")
fo.write("\t\t}\n") fo.write("\t\treturn (0);\n")
fo.write("\t\treturn (0);\n")
fo.write("\tdefault:\n\t\treturn (0);\n\t}\n}\n")
fo.write("\tdefault:\n\t\treturn (0);\n\t}\n}\n")
####################################################################### #######################################################################
# Emit the vxp_tnames (token->string) conversion array # Emit the vxp_tnames (token->string) conversion array
def emit_vxp_tnames(fo, tokens): def emit_vxp_tnames(fo, tokens):
fo.write("\nconst char * const vxp_tnames[256] = {\n") fo.write("\nconst char * const vxp_tnames[256] = {\n")
l = list(tokens.keys()) l = list(tokens.keys())
l.sort() l.sort()
for i in l: for i in l:
j = tokens[i] j = tokens[i]
if j == None: if j is None:
j = i j = i
if i[0] == "'": if i[0] == "'":
j = i j = i
fo.write("\t[%s] = \"%s\",\n" % (i, j)) fo.write("\t[%s] = \"%s\",\n" % (i, j))
fo.write("};\n") fo.write("};\n")
####################################################################### #######################################################################
def polish_tokens(tokens): def polish_tokens(tokens):
# Expand single char tokens # Expand single char tokens
st = tokens[None] st = tokens[None]
del tokens[None] del tokens[None]
for i in st: for i in st:
tokens["'" + i + "'"] = i tokens["'" + i + "'"] = i
####################################################################### #######################################################################
def file_header(fo): def file_header(fo):
fo.write("""/* fo.write("""/*
* NB: This file is machine generated, DO NOT EDIT! * NB: This file is machine generated, DO NOT EDIT!
* *
* Edit and run lib/libvarnishapi/generate.py instead * Edit and run lib/libvarnishapi/generate.py instead
...@@ -171,11 +170,11 @@ j = 128 ...@@ -171,11 +170,11 @@ j = 128
l = list(tokens.keys()) l = list(tokens.keys())
l.sort() l.sort()
for i in l: for i in l:
if i[0] == "'": if i[0] == "'":
continue continue
fo.write("#define\t%s %d\n" % (i, j)) fo.write("#define\t%s %d\n" % (i, j))
j += 1 j += 1
assert j < 256 assert j < 256
fo.close() fo.close()
......
This diff is collapsed.
...@@ -41,7 +41,6 @@ import sys ...@@ -41,7 +41,6 @@ import sys
import re import re
import optparse import optparse
import unittest import unittest
import random
import copy import copy
import json import json
import hashlib import hashlib
...@@ -254,7 +253,7 @@ class CType(object): ...@@ -254,7 +253,7 @@ class CType(object):
def json(self, jl): def json(self, jl):
jl.append([self.vt]) jl.append([self.vt])
while jl[-1][-1] is None: while jl[-1][-1] is None:
jl[-1].pop(-1) jl[-1].pop(-1)
####################################################################### #######################################################################
...@@ -290,7 +289,7 @@ class arg(CType): ...@@ -290,7 +289,7 @@ class arg(CType):
def json(self, jl): def json(self, jl):
jl.append([self.vt, self.nm, self.defval, self.spec]) jl.append([self.vt, self.nm, self.defval, self.spec])
if self.opt: if self.opt:
jl[-1].append(True) jl[-1].append(True)
while jl[-1][-1] is None: while jl[-1][-1] is None:
jl[-1].pop(-1) jl[-1].pop(-1)
...@@ -366,7 +365,7 @@ class ProtoType(object): ...@@ -366,7 +365,7 @@ class ProtoType(object):
err("%s(): Illegal C-name\n" % self.cname(), warn=False) err("%s(): Illegal C-name\n" % self.cname(), warn=False)
if len(wl) == 2 and wl[0] == '(' and wl[1] == ')': if len(wl) == 2 and wl[0] == '(' and wl[1] == ')':
return return
if wl[0] != "(": if wl[0] != "(":
err("Syntax error: Expected '(', got '%s'" % wl[0], warn=False) err("Syntax error: Expected '(', got '%s'" % wl[0], warn=False)
...@@ -386,17 +385,17 @@ class ProtoType(object): ...@@ -386,17 +385,17 @@ class ProtoType(object):
if not wl: if not wl:
break break
if wl[0] == '[': if wl[0] == '[':
wl.pop(0) wl.pop(0)
t = arg(wl, names, st.vcc.enums, ']') t = arg(wl, names, st.vcc.enums, ']')
if t.nm is None: if t.nm is None:
err("Optional arguments must have names", warn=False) err("Optional arguments must have names", warn=False)
t.opt = True t.opt = True
x = wl.pop(0) x = wl.pop(0)
if x != ']': if x != ']':
err("Expected ']' found '%s'" % x, warn=False) err("Expected ']' found '%s'" % x, warn=False)
self.argstruct = True self.argstruct = True
else: else:
t = arg(wl, names, st.vcc.enums, ',') t = arg(wl, names, st.vcc.enums, ',')
if t.nm is None: if t.nm is None:
t.nm2 = "arg%d" % n t.nm2 = "arg%d" % n
else: else:
...@@ -466,10 +465,10 @@ class ProtoType(object): ...@@ -466,10 +465,10 @@ class ProtoType(object):
s = self.retval.ct + " " + name + '(' s = self.retval.ct + " " + name + '('
ll = args ll = args
if self.argstruct: if self.argstruct:
ll.append(self.argstructname() + "*") ll.append(self.argstructname() + "*")
else: else:
for i in self.args: for i in self.args:
ll.append(i.ct) ll.append(i.ct)
s += ", ".join(ll) s += ", ".join(ll)
return s + ');' return s + ');'
...@@ -483,31 +482,31 @@ class ProtoType(object): ...@@ -483,31 +482,31 @@ class ProtoType(object):
def argstructure(self): def argstructure(self):
s = "\n" + self.argstructname() + " {\n" s = "\n" + self.argstructname() + " {\n"
for i in self.args: for i in self.args:
if i.opt: if i.opt:
assert i.nm is not None assert i.nm is not None
s += "\tchar\t\t\tvalid_%s;\n" % i.nm s += "\tchar\t\t\tvalid_%s;\n" % i.nm
for i in self.args: for i in self.args:
s += "\t" + i.ct s += "\t" + i.ct
if len(i.ct) < 8: if len(i.ct) < 8:
s += "\t" s += "\t"
if len(i.ct) < 16: if len(i.ct) < 16:
s += "\t" s += "\t"
s += "\t" + i.nm2 + ";\n" s += "\t" + i.nm2 + ";\n"
s += "};\n" s += "};\n"
return s return s
def cstuff(self, args, where): def cstuff(self, args, where):
s = "" s = ""
if where == 'h': if where == 'h':
if self.argstruct: if self.argstruct:
s += self.argstructure() s += self.argstructure()
s += lwrap(self.proto(args, self.cname(True))) s += lwrap(self.proto(args, self.cname(True)))
elif where == 'c': elif where == 'c':
s += lwrap(self.typedef(args)) s += lwrap(self.typedef(args))
elif where == 'o': elif where == 'o':
if self.argstruct: if self.argstruct:
s += self.argstructure() s += self.argstructure()
s += lwrap(self.typedef(args)) s += lwrap(self.typedef(args))
else: else:
assert False assert False
return s return s
...@@ -517,9 +516,9 @@ class ProtoType(object): ...@@ -517,9 +516,9 @@ class ProtoType(object):
self.retval.json(ll) self.retval.json(ll)
ll.append('Vmod_%s_Func.%s' % (self.st.vcc.modname, cfunc)) ll.append('Vmod_%s_Func.%s' % (self.st.vcc.modname, cfunc))
if self.argstruct: if self.argstruct:
ll.append(self.argstructname()) ll.append(self.argstructname())
else: else:
ll.append("") ll.append("")
for i in self.args: for i in self.args:
i.json(ll) i.json(ll)
jl.append(ll) jl.append(ll)
......
This diff is collapsed.
...@@ -32,19 +32,19 @@ found in a subdirectory tree. ...@@ -32,19 +32,19 @@ found in a subdirectory tree.
Options: Options:
-g gcov-program -g gcov-program
default:gcov6 default:gcov6
-o output-filename -o output-filename
default: stdout default: stdout
-x exclude-subdir -x exclude-subdir
default ".git" and ".deps" default ".git" and ".deps"
Arguments: Arguments:
directories to process. directories to process.
default: . default: .
""" """
...@@ -61,141 +61,141 @@ lengths = {} ...@@ -61,141 +61,141 @@ lengths = {}
exclude = [".git", ".deps",] exclude = [".git", ".deps",]
def process_gcov(fn, sn): def process_gcov(fn, sn):
""" Sum .gcov file into counts, then delete it """ """ Sum .gcov file into counts, then delete it """
dd = counts.get(sn) dd = counts.get(sn)
if dd is None: if dd is None:
dd = {} dd = {}
for ln in open(fn): for ln in open(fn):
d = ln.split(":") d = ln.split(":")
cnt = d[0].strip() cnt = d[0].strip()
ll = d[1] ll = d[1]
if cnt == "-": if cnt == "-":
continue continue
if cnt == "#####": if cnt == "#####":
cnt = 0 cnt = 0
else: else:
cnt = int(cnt) cnt = int(cnt)
lno = int(d[1]) lno = int(d[1])
if lno not in dd: if lno not in dd:
dd[lno] = 0 dd[lno] = 0
dd[lno] += cnt dd[lno] += cnt
counts[sn] = dd counts[sn] = dd
pl = lengths.get(sn) pl = lengths.get(sn)
ll = ll.strip() ll = ll.strip()
if d[2] == "/*EOF*/\n": if d[2] == "/*EOF*/\n":
ll = pl ll = pl
elif pl != ll and not pl is None: elif pl != ll and not pl is None:
print("CONFLICT", fn, ll, pl) print("CONFLICT", fn, ll, pl)
ll = "-1" ll = "-1"
lengths[sn] = ll lengths[sn] = ll
os.remove(fn) os.remove(fn)
def run_gcov(prog, subdir): def run_gcov(prog, subdir):
""" Walk tree, run gcov, process output """ """ Walk tree, run gcov, process output """
for root, dirs, files in os.walk(subdir): for root, dirs, files in os.walk(subdir):
for i in exclude: for i in exclude:
if i in dirs: if i in dirs:
dirs.remove(i) dirs.remove(i)
if " ".join(files).find(".gcda") == -1: if " ".join(files).find(".gcda") == -1:
continue continue
for fn in files: for fn in files:
if fn[-2:] != ".o": if fn[-2:] != ".o":
continue continue
# if we find the .o file in a .../.libs the sources # if we find the .o file in a .../.libs the sources
# must be found relative to the parent directory # must be found relative to the parent directory
if root[-6:] == "/.libs": if root[-6:] == "/.libs":
x = subprocess.check_output( x = subprocess.check_output(
["cd " + root + "/.. && " + ["cd " + root + "/.. && " +
"exec " + prog + " -r .libs/" + fn], "exec " + prog + " -r .libs/" + fn],
stderr=subprocess.STDOUT, shell=True, stderr=subprocess.STDOUT, shell=True,
universal_newlines=True) universal_newlines=True)
pf = ".." pf = ".."
else: else:
x = subprocess.check_output( x = subprocess.check_output(
["cd " + root + " && " + ["cd " + root + " && " +
"exec " + prog + " -r " + fn], "exec " + prog + " -r " + fn],
stderr=subprocess.STDOUT, shell=True, stderr=subprocess.STDOUT, shell=True,
universal_newlines=True) universal_newlines=True)
pf = "" pf = ""
for ln in x.split("\n"): for ln in x.split("\n"):
ln = ln.split() ln = ln.split()
if len(ln) == 0: if not ln:
continue continue
if ln[0] == "Creating": if ln[0] == "Creating":
gn = ln[1].strip("'") gn = ln[1].strip("'")
assert gn[-5:] == ".gcov" assert gn[-5:] == ".gcov"
sn = gn[:-5] sn = gn[:-5]
process_gcov( process_gcov(
os.path.join(root, pf, gn), sn) os.path.join(root, pf, gn), sn)
def produce_output(fdo): def produce_output(fdo):
""" """
Produce compact output file Produce compact output file
Format: Format:
linefm [lineto] count linefm [lineto] count
"+" in linefm means "previous line + 1" "+" in linefm means "previous line + 1"
"." in count means "same as previous count" "." in count means "same as previous count"
""" """
for sn, cnt in counts.items(): for sn, cnt in counts.items():
fdo.write("/" + sn + " " + str(lengths[sn]) + "\n") fdo.write("/" + sn + " " + str(lengths[sn]) + "\n")
lnos = list(cnt.items()) lnos = list(cnt.items())
lnos.sort() lnos.sort()
pln = -1 pln = -1
pcn = -1 pcn = -1
while len(lnos) > 0: while lnos:
ln, cn = lnos.pop(0) ln, cn = lnos.pop(0)
lnl = ln lnl = ln
while len(lnos) > 0: while lnos:
lnn, cnn = lnos[0] lnn, cnn = lnos[0]
if lnl + 1 != lnn or cnn != cn: if lnl + 1 != lnn or cnn != cn:
break break
lnos.pop(0) lnos.pop(0)
lnl = lnn lnl = lnn
if ln == pln + 1: if ln == pln + 1:
s = "+ " s = "+ "
else: else:
s = "%d " % ln s = "%d " % ln
if ln != lnl: if ln != lnl:
s += "%d " % lnl s += "%d " % lnl
pln = lnl pln = lnl
else: else:
pln = ln pln = ln
if cn == pcn: if cn == pcn:
s += "." s += "."
else: else:
s += "%d" % cn s += "%d" % cn
pcn = cn pcn = cn
fdo.write(s + "\n") fdo.write(s + "\n")
if __name__ == "__main__": if __name__ == "__main__":
optlist, args = getopt.getopt(sys.argv[1:], "g:o:x:") optlist, args = getopt.getopt(sys.argv[1:], "g:o:x:")
fo = sys.stdout fo = sys.stdout
gcovprog = "gcov6" gcovprog = "gcov6"
for f, v in optlist: for f, v in optlist:
if f == '-o' and v == '-': if f == '-o' and v == '-':
fo = sys.stdout fo = sys.stdout
elif f == '-o': elif f == '-o':
fo = open(v, "w") fo = open(v, "w")
elif f == '-g': elif f == '-g':
gcovprog = v gcovprog = v
elif f == '-x': elif f == '-x':
exclude.append(v) exclude.append(v)
else: else:
assert False assert False
if len(args) == 0: if not args:
args = ["."] args = ["."]
for dn in args: for dn in args:
run_gcov(gcovprog, dn) run_gcov(gcovprog, dn)
produce_output(fo) produce_output(fo)
...@@ -5,41 +5,39 @@ from __future__ import print_function ...@@ -5,41 +5,39 @@ from __future__ import print_function
import os import os
def check(fn): def check(fn):
l = [] l = []
for i in open(fn): for i in open(fn):
i = i.strip() i = i.strip()
if len(i) == 0: if not i:
continue continue
if i[0] != "#": if i[0] != "#":
continue continue
if i.find("include") == -1: if i.find("include") == -1:
continue continue
if i.find('"') == -1: if i.find('"') == -1:
l.append(i.split('<')[1].split('>')[0]) l.append(i.split('<')[1].split('>')[0])
else: else:
l.append(i.split('"')[1]) l.append(i.split('"')[1])
if "vrt.h" in l: if "vrt.h" in l:
vrt = l.index("vrt.h") vrt = l.index("vrt.h")
if not "vdef.h" in l: if "vdef.h" not in l:
print(fn, "vdef.h not included with vrt.h") print(fn, "vdef.h not included with vrt.h")
vdef = l.index("vdef.h") vdef = l.index("vdef.h")
if vdef > vrt: if vdef > vrt:
print(fn, "vdef.h included after vrt.h") print(fn, "vdef.h included after vrt.h")
for i in ("stddef.h", "stdint.h", "cache/cache.h", "cache.h"): for i in ("stddef.h", "stdint.h", "cache/cache.h", "cache.h"):
if i in l: if i in l:
print(fn, i + " included with vrt.h") print(fn, i + " included with vrt.h")
for i in ("cache/cache.h", "cache.h"): for i in ("cache/cache.h", "cache.h"):
if i in l: if i in l:
for i in ( for i in ("stddef.h", "stdint.h", "vrt.h",
"stddef.h", "stdint.h", "vrt.h", "math.h", "pthread.h", "stdarg.h", "sys/types.h",
"math.h", "pthread.h", "stdarg.h", "sys/types.h", "vdef.h", "miniobj.h", "vas.h", "vqueue.h"):
"vdef.h", "miniobj.h", "vas.h", "vqueue.h", if i in l:
): print(fn, i + " included with cache.h")
if i in l:
print(fn, i + " included with cache.h")
for (dir, dns, fns) in os.walk("."): for (dir, dns, fns) in os.walk("."):
for f in fns: for f in fns:
if f[-2:] == ".c": if f[-2:] == ".c":
check(dir + "/" + f) check(dir + "/" + f)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment