Skip to content

Commit

Permalink
fixes for sign-extended wire-format
Browse files Browse the repository at this point in the history
  • Loading branch information
maierkomor committed Nov 20, 2022
1 parent bc7a804 commit d301ea4
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 37 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Release R2211:
==============
- fixes for sign-extended wire-format
- support setByName array element addition with argument
- fix regressions/bugs in ASCII output
- reduce cases of defined but not used warnings
- testsuite updates

Release R2206:
==============
Expand Down
3 changes: 1 addition & 2 deletions share/read_varint.cct
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017-2018, Thomas Maier-Komor
* Copyright (C) 2017-2022, Thomas Maier-Komor
*
* This source file belongs to Wire-Format-Compiler.
*
Expand Down Expand Up @@ -38,7 +38,6 @@ unsigned read_varint_default(const uint8_t *wire, ssize_t wl, varint_t *r)
if (($varintbits != 64) && (u8 & 0x80)) {
while (*wire++ & 0x80)
++n;
++n;
}
return n;
}
Expand Down
10 changes: 3 additions & 7 deletions share/xvarint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void send_xvarint_16($putparam, varint_t v)
if (fill64) {
for (int i = 0; i < 6; ++i)
$wireput(0xff);
$wireput(0x1);
}
}

Expand All @@ -60,9 +59,8 @@ void send_xvarint_32($putparam, varint_t v)
$wireput(u8);
} while (v);
if (fill64) {
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 5; ++i)
$wireput(0xff);
$wireput(0x1);
}
}

Expand All @@ -86,9 +84,8 @@ int write_xvarint_16(uint8_t *wire, ssize_t wl, varint_t v)
} while (v);
if (fill64) {
w[-1] |= 0xfc;
for (int i = 0; i < 6; ++i)
for (int i = 0; i < 7; ++i)
*w++ = 0xff;
*w++ = 0x1;
}
return w-wire;
}
Expand All @@ -113,9 +110,8 @@ int write_xvarint_32(uint8_t *wire, ssize_t wl, varint_t v)
} while (v);
if (fill64) {
w[-1] |= 0xf0;
for (int i = 0; i < 4; ++i)
for (int i = 0; i < 5; ++i)
*w++ = 0xff;
*w++ = 0x1;
}
return w-wire;
}
Expand Down
5 changes: 3 additions & 2 deletions src/CppGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4167,7 +4167,7 @@ void CppGenerator::writePrint(Generator &G, Field *f)
} else
G << "o << $(field_value) << ';';\n";
} else if (!asciifun.empty()) {
G << "ascii_indent(o, indent, $elename);\n";
G << "$ascii_indent(o, indent, $elename);\n";
G << asciifun << "(o,$(field_value));\n";
G << "o << ';';\n";
} else switch (type) {
Expand Down Expand Up @@ -4211,7 +4211,7 @@ void CppGenerator::writePrint(Generator &G, Field *f)
if (!filter.empty()) {
G << filter << "(o,indent,$field_value.data(),$field_value.size(),$elename);\n";
} else {
G << "o << ascii_indent(o,indent,$elename);\n"
G << "$ascii_indent(o,indent,$elename);\n"
"o << $field_value.c_str() << ';';\n";
}
}
Expand All @@ -4238,6 +4238,7 @@ void CppGenerator::writePrint(Generator &G, Field *f)
Enum *e = Enum::id2enum(type);
assert(e);
const string &strfun = e->getStringFunction();
G << "$ascii_indent(o,indent,$elename);\n";
if (strfun.empty())
G << "o << $(field_value) << ';';\n";
else
Expand Down
2 changes: 1 addition & 1 deletion testsuite/genwfc.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2019-2021, Thomas Maier-Komor
# Copyright (C) 2019-2022, Thomas Maier-Komor
#
# This file belongs to Wire-Format-Compiler.
#
Expand Down
21 changes: 16 additions & 5 deletions testsuite/runtests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ CXXOBJS = $(CXXSRCS:%.cpp=%.o) $(WFCOBJS)
LIBS = -L/usr/pkg/lib -ljson-c -Wl,-R/usr/pkg/lib


TESTCASES = \
corruption enumtest empty_test tttest vbittest xvarint \
cstrtest stringtest recursion json_hs lt1 skiptest reftest \
vbittest2 tttest fixed_test novi_test pack_test comp_test \
ref_byname byname_test inv_def_test arraycheck reftestv2
#TESTCASES = \
# corruption enumtest empty_test tttest vbittest xvarint \
# cstrtest stringtest recursion json_hs lt1 skiptest reftest \
# vbittest2 tttest fixed_test novi_test pack_test comp_test \
# ref_byname byname_test inv_def_test arraycheck reftestv2 \
# enumtest_map bitsets

COMPILETESTS = \
unused
Expand Down Expand Up @@ -58,6 +59,9 @@ $(ODIR)/corruption: $(ODIR)/corruption.o $(ODIR)/hostscope.o $(WFCOBJS)
$(ODIR)/enumtest: $(ODIR)/enumtest.o $(ODIR)/enumtest1.o $(WFCOBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

$(ODIR)/enumtest_map: $(ODIR)/enumtest_map.o $(ODIR)/enumtest1.o $(WFCOBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

$(ODIR)/empty_test: $(ODIR)/empty_test.o $(ODIR)/empty_elements.o $(WFCOBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

Expand Down Expand Up @@ -123,3 +127,10 @@ $(ODIR)/inv_def_test: $(ODIR)/inv_def_test.o $(ODIR)/inv_def.o $(WFCOBJS)

$(ODIR)/arraycheck: $(ODIR)/checkarray.o $(ODIR)/arraycheck.o $(WFCOBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

$(ODIR)/bitsets: $(ODIR)/bitsets.o $(ODIR)/bittest1.o $(WFCOBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

$(ODIR)/xint: $(ODIR)/xint.o $(ODIR)/xint_test.o $(WFCOBJS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)

74 changes: 54 additions & 20 deletions testsuite/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ SIZE=`which gsize||which size`
#echo make is $MAKE

declare -A flagsets cxxflags
flagsets[fs_OsLs]="-Os -fwfclib=static -g"
flagsets[fs_OsLi]="-Os -fwfclib=inline -g"
flagsets[fs_OsLe]="-Os -fwfclib=extern -g"
flagsets[fs_O2Ls]="-O2 -fwfclib=static -g"
flagsets[fs_O2Li]="-O2 -fwfclib=inline -g"
flagsets[fs_O2Le]="-O2 -fwfclib=extern -g"
flagsets[fs_OrLs]="-Or -fwfclib=static -g"
flagsets[fs_OrLi]="-Or -fwfclib=inline -g"
flagsets[fs_OrLe]="-Or -fwfclib=extern -g"
flagsets[fs_O2s]="-O2 -s"
flagsets[fs_O2sp]="-O2 -fpadded_message_size"
flagsets[fs_Ors]="-Or -s"
flagsets[fs_Oss]="-Os -s"
flagsets[fs_OsLi]='-Os -fwfclib=inline -g'
flagsets[fs_OsLe]='-Os -fwfclib=extern -g'
flagsets[fs_O2Li]='-O2 -fwfclib=inline -g'
flagsets[fs_O2Le]='-O2 -fwfclib=extern -g'
flagsets[fs_OrLi]='-Or -fwfclib=inline -g'
flagsets[fs_OrLe]='-Or -fwfclib=extern -g'
flagsets[fs_O2s]='-O2 -s'
flagsets[fs_O2sp]='-O2 -fpadded_message_size'
flagsets[fs_Ors]='-Or -s'
flagsets[fs_Oss]='-Os -s'
flagsets[fs_O2B]='-O2 -fwfclib=extern -fBaseClass="Message"'
flagsets[fs_OrB]='-Or -fwfclib=extern -fBaseClass="Message"'
flagsets[fs_OsB]='-Os -fwfclib=extern -fBaseClass="Message"'
flagsets[fs_O2C]='-O2 -fStringType=C -ftoString=""'
flagsets[fs_OsC]='-Os -fStringType=C -ftoString=""'
flagsets[fs_OrC]='-Or -fStringType=C -ftoString=""'
flagsets[fs_O2A]="-O2 -fStringType=AString '-fheader=\"astring.h\"'"
flagsets[fs_OsA]="-O2 -fStringType=AString '-fheader=\"astring.h\"'"
flagsets[fs_OrA]="-O2 -fStringType=AString '-fheader=\"astring.h\"'"
flagsets[fs_O2ALe]="-O2 -fStringType=AString '-fheader=\"astring.h\"'"
flagsets[fs_OsALe]="-O2 -fStringType=AString '-fheader=\"astring.h\"'"
flagsets[fs_OrALe]="-O2 -fStringType=AString '-fheader=\"astring.h\"'"
flagsets[fs_O2A]='-O2 -fStringType=AString -fheader=\"astring.h\"'
flagsets[fs_OsA]='-O2 -fStringType=AString -fheader=\"astring.h\"'
flagsets[fs_OrA]='-O2 -fStringType=AString -fheader=\"astring.h\"'
flagsets[fs_O2ALe]='-O2 -fStringType=AString -fheader=\"astring.h\"'
flagsets[fs_OsALe]='-O2 -fStringType=AString -fheader=\"astring.h\"'
flagsets[fs_OrALe]='-O2 -fStringType=AString -fheader=\"astring.h\"'
if [ `uname -m` != "armv7l" ]; then
flagsets[fs_O2le]="-O2 -fendian=little -g"
fi
Expand Down Expand Up @@ -73,6 +73,38 @@ cxxflags[fs_OsALe]="-Dstringtype=AString"
cxxflags[fs_OrALe]="-Dstringtype=AString"
cxxflags[fs_O2le]="-Dstringtype=string"

defaulttests="corruption enumtest empty_test tttest vbittest \
stringtest recursion json_hs lt1 skiptest reftest \
vbittest2 tttest fixed_test novi_test pack_test comp_test \
ref_byname byname_test inv_def_test arraycheck reftestv2"

# tests that need special settings
# TODO: cstrtest
extratests="cstrtest xvarint xint"

testcases[fs_OsLs]="$defaulttests xvarint xint"
testcases[fs_OsLi]="$defaulttests xint"
testcases[fs_OsLe]="$defaulttests"
testcases[fs_O2Ls]="$defaulttests xvarint xint"
testcases[fs_O2Li]="$defaulttests xint"
testcases[fs_O2Le]="$defaulttests"
testcases[fs_OrLs]="$defaulttests xvarint xint"
testcases[fs_OrLi]="$defaulttests xint"
testcases[fs_OrLe]="$defaulttests"
testcases[fs_O2s]="$defaulttests xint"
testcases[fs_Ors]="$defaulttests xint"
testcases[fs_Oss]="$defaulttests xint"
testcases[fs_O2C]="$defaulttests xint"
testcases[fs_OsC]="$defaulttests xint"
testcases[fs_OrC]="$defaulttests xint"
testcases[fs_O2A]="$defaulttests xint"
testcases[fs_OsA]="$defaulttests xint"
testcases[fs_OrA]="$defaulttests xint"
testcases[fs_O2ALe]="$defaulttests"
testcases[fs_OsALe]="$defaulttests"
testcases[fs_OrALe]="$defaulttests"
testcases[fs_O2le]="$defaulttests"


CXXFLAGS0=$CXXFLAGS
if [ "" == "$CXXFLAGS0" ]; then
Expand All @@ -84,10 +116,12 @@ fi
for flagset in "${!flagsets[@]}"; do
echo testing with flagset $flagset
echo CXXFLAGS=${cxxflags[$flagset]}
echo TESTCASES=${testcases[$flagset]}

#ODIR=`pwd`/"$flagset"
ODIR="$flagset"
WFCFLAGS="${flagsets[$flagset]}"
TESTCASES="${testcases[$flagset]}"
CXXFLAGS="$CXXFLAGS0 -I../include -I. -I$ODIR -I/usr/pkg/include ${cxxflags[$flagset]}"
if [ -d "$ODIR" ]; then
rm -r "$ODIR"
Expand All @@ -101,7 +135,7 @@ for flagset in "${!flagsets[@]}"; do
else
WFCOBJS=
fi
export ODIR WFCFLAGS CXXFLAGS WFCOBJS
export ODIR WFCFLAGS CXXFLAGS WFCOBJS TESTCASES
echo compiling wfc files
echo MAKEFLAGS=$MAKEFLAGS
$MAKE -f genwfc.mk -e || exit
Expand Down

0 comments on commit d301ea4

Please sign in to comment.