Merge pull request #205 from libtom/travis_check_sources Add travis build-job that checks the source-code format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
diff --git a/.travis.yml b/.travis.yml
index 743d621..047939d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,9 @@
# #
#############################################################################
+# Run the tests based on Ubuntu 16.04
+dist: xenial
+
# Compilation failures are in gcc_errors_*.log
# Failed tests in test_*.log
# Files do not exist in case of success
@@ -57,6 +60,14 @@ matrix:
# We have only one program and the variable $BUILDOPTIONS
# has only the options to that program: testme.sh
+ # Check source code format
+ - env: BUILDOPTIONS='--format'
+ addons:
+ apt:
+ packages:
+ - astyle
+ sudo: required
+
# GCC for the 32-bit architecture (no valgrind yet)
- env: BUILDOPTIONS='--with-cc=gcc --with-m32'
addons:
diff --git a/bn_mp_clear.c b/bn_mp_clear.c
index b8e724c..9b8a233 100644
--- a/bn_mp_clear.c
+++ b/bn_mp_clear.c
@@ -25,7 +25,7 @@ void mp_clear(mp_int *a)
}
/* free ram */
- XFREE(a->dp, sizeof (mp_digit) * (size_t)a->alloc);
+ XFREE(a->dp, sizeof(mp_digit) * (size_t)a->alloc);
/* reset members to make debugging easier */
a->dp = NULL;
diff --git a/bn_mp_decr.c b/bn_mp_decr.c
index b57f5d0..edf65f4 100644
--- a/bn_mp_decr.c
+++ b/bn_mp_decr.c
@@ -40,9 +40,8 @@ int mp_decr(mp_int *a)
}
return mp_sub_d(a, 1uL,a);
}
-
-
#endif
-/* ref: \$Format:\%D$ */
-/* git commit: \$Format:\%H$ */
-/* commit time: \$Format:\%ai$ */
+
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/bn_mp_grow.c b/bn_mp_grow.c
index b120194..db1d06e 100644
--- a/bn_mp_grow.c
+++ b/bn_mp_grow.c
@@ -30,7 +30,7 @@ int mp_grow(mp_int *a, int size)
* to overwrite the dp member of a.
*/
tmp = (mp_digit *) XREALLOC(a->dp,
- (size_t)a->alloc * sizeof (mp_digit),
+ (size_t)a->alloc * sizeof(mp_digit),
(size_t)size * sizeof(mp_digit));
if (tmp == NULL) {
/* reallocation failed but "a" is still valid [can be freed] */
diff --git a/bn_mp_incr.c b/bn_mp_incr.c
index b7cd24a..adecb25 100644
--- a/bn_mp_incr.c
+++ b/bn_mp_incr.c
@@ -35,8 +35,8 @@ int mp_incr(mp_int *a)
}
return mp_add_d(a, 1uL,a);
}
-
#endif
-/* ref: \$Format:\%D$ */
-/* git commit: \$Format:\%H$ */
-/* commit time: \$Format:\%ai$ */
+
+/* ref: $Format:%D$ */
+/* git commit: $Format:%H$ */
+/* commit time: $Format:%ai$ */
diff --git a/bn_mp_iseven.c b/bn_mp_iseven.c
index 4dc72a4..9532fdd 100644
--- a/bn_mp_iseven.c
+++ b/bn_mp_iseven.c
@@ -9,8 +9,7 @@
* Michael Fromberger but has been written from scratch with
* additional optimizations in place.
*
- * The library is free for all purposes without any express
- * guarantee it works.
+ * SPDX-License-Identifier: Unlicense
*/
int mp_iseven(const mp_int *a)
diff --git a/bn_mp_isodd.c b/bn_mp_isodd.c
index 4a3942c..007b6dd 100644
--- a/bn_mp_isodd.c
+++ b/bn_mp_isodd.c
@@ -9,8 +9,7 @@
* Michael Fromberger but has been written from scratch with
* additional optimizations in place.
*
- * The library is free for all purposes without any express
- * guarantee it works.
+ * SPDX-License-Identifier: Unlicense
*/
int mp_isodd(const mp_int *a)
diff --git a/bn_mp_shrink.c b/bn_mp_shrink.c
index fa30184..04c88e3 100644
--- a/bn_mp_shrink.c
+++ b/bn_mp_shrink.c
@@ -24,7 +24,7 @@ int mp_shrink(mp_int *a)
if (a->alloc != used) {
if ((tmp = (mp_digit *) XREALLOC(a->dp,
- (size_t)a->alloc * sizeof (mp_digit),
+ (size_t)a->alloc * sizeof(mp_digit),
(size_t)used * sizeof(mp_digit))) == NULL) {
return MP_MEM;
}
diff --git a/callgraph.txt b/callgraph.txt
index afcfa05..2a9aed0 100644
--- a/callgraph.txt
+++ b/callgraph.txt
@@ -2416,8 +2416,6 @@ BN_MP_INIT_SET_INT_C
+--->BN_MP_INIT_C
+--->BN_MP_SET_INT_C
| +--->BN_MP_SET_LONG_C
-| | +--->BN_MP_GROW_C
-| | +--->BN_MP_ZERO_C
BN_MP_INIT_SIZE_C
@@ -2743,8 +2741,6 @@ BN_MP_IS_SQUARE_C
| +--->BN_MP_INIT_C
| +--->BN_MP_SET_INT_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
+--->BN_MP_MOD_C
| +--->BN_MP_INIT_SIZE_C
| | +--->BN_MP_INIT_C
@@ -5659,8 +5655,6 @@ BN_MP_PRIME_FROBENIUS_UNDERWOOD_C
| | | +--->BN_MP_INIT_C
| | | +--->BN_MP_SET_INT_C
| | | | +--->BN_MP_SET_LONG_C
-| | | | | +--->BN_MP_GROW_C
-| | | | | +--->BN_MP_ZERO_C
| | +--->BN_MP_MOD_C
| | | +--->BN_MP_INIT_SIZE_C
| | | | +--->BN_MP_INIT_C
@@ -7264,8 +7258,6 @@ BN_MP_PRIME_FROBENIUS_UNDERWOOD_C
| | | +--->BN_MP_CLAMP_C
| | +--->BN_MP_INIT_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
| | +--->BN_MP_MUL_C
| | | +--->BN_MP_TOOM_MUL_C
| | | | +--->BN_MP_INIT_MULTI_C
@@ -7616,8 +7608,6 @@ BN_MP_PRIME_FROBENIUS_UNDERWOOD_C
| +--->BN_MP_INIT_C
| +--->BN_MP_CLEAR_C
+--->BN_MP_SET_LONG_C
-| +--->BN_MP_GROW_C
-| +--->BN_MP_ZERO_C
+--->BN_MP_SQR_C
| +--->BN_MP_TOOM_SQR_C
| | +--->BN_MP_MOD_2D_C
@@ -7975,8 +7965,6 @@ BN_MP_PRIME_IS_PRIME_C
| | +--->BN_MP_INIT_C
| | +--->BN_MP_SET_INT_C
| | | +--->BN_MP_SET_LONG_C
-| | | | +--->BN_MP_GROW_C
-| | | | +--->BN_MP_ZERO_C
| +--->BN_MP_MOD_C
| | +--->BN_MP_INIT_SIZE_C
| | | +--->BN_MP_INIT_C
@@ -9579,8 +9567,6 @@ BN_MP_PRIME_IS_PRIME_C
| | +--->BN_MP_INIT_C
| | +--->BN_MP_CLEAR_C
| +--->BN_MP_SET_LONG_C
-| | +--->BN_MP_GROW_C
-| | +--->BN_MP_ZERO_C
| +--->BN_MP_SQR_C
| | +--->BN_MP_TOOM_SQR_C
| | | +--->BN_MP_MOD_2D_C
@@ -9890,8 +9876,6 @@ BN_MP_PRIME_IS_PRIME_C
| | +--->BN_MP_CLAMP_C
| +--->BN_MP_INIT_C
| +--->BN_MP_SET_LONG_C
-| | +--->BN_MP_GROW_C
-| | +--->BN_MP_ZERO_C
| +--->BN_MP_MUL_C
| | +--->BN_MP_TOOM_MUL_C
| | | +--->BN_MP_INIT_MULTI_C
@@ -11371,8 +11355,6 @@ BN_MP_PRIME_NEXT_PRIME_C
| | +--->BN_MP_INIT_SET_INT_C
| | | +--->BN_MP_SET_INT_C
| | | | +--->BN_MP_SET_LONG_C
-| | | | | +--->BN_MP_GROW_C
-| | | | | +--->BN_MP_ZERO_C
| | +--->BN_MP_MOD_C
| | | +--->BN_MP_INIT_SIZE_C
| | | +--->BN_MP_DIV_C
@@ -12909,8 +12891,6 @@ BN_MP_PRIME_NEXT_PRIME_C
| | +--->BN_MP_INIT_MULTI_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
| | +--->BN_MP_SQR_C
| | | +--->BN_MP_TOOM_SQR_C
| | | | +--->BN_MP_MOD_2D_C
@@ -13200,8 +13180,6 @@ BN_MP_PRIME_NEXT_PRIME_C
| | | +--->BN_MP_GROW_C
| | | +--->BN_MP_CLAMP_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
| | +--->BN_MP_MUL_C
| | | +--->BN_MP_TOOM_MUL_C
| | | | +--->BN_MP_INIT_MULTI_C
@@ -13568,8 +13546,6 @@ BN_MP_PRIME_RANDOM_EX_C
| | | +--->BN_MP_INIT_C
| | | +--->BN_MP_SET_INT_C
| | | | +--->BN_MP_SET_LONG_C
-| | | | | +--->BN_MP_GROW_C
-| | | | | +--->BN_MP_ZERO_C
| | +--->BN_MP_MOD_C
| | | +--->BN_MP_INIT_SIZE_C
| | | | +--->BN_MP_INIT_C
@@ -15172,8 +15148,6 @@ BN_MP_PRIME_RANDOM_EX_C
| | | +--->BN_MP_INIT_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
| | +--->BN_MP_SQR_C
| | | +--->BN_MP_TOOM_SQR_C
| | | | +--->BN_MP_MOD_2D_C
@@ -15483,8 +15457,6 @@ BN_MP_PRIME_RANDOM_EX_C
| | | +--->BN_MP_CLAMP_C
| | +--->BN_MP_INIT_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
| | +--->BN_MP_MUL_C
| | | +--->BN_MP_TOOM_MUL_C
| | | | +--->BN_MP_INIT_MULTI_C
@@ -15874,8 +15846,6 @@ BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C
| | | +--->BN_MP_INIT_C
| | | +--->BN_MP_SET_INT_C
| | | | +--->BN_MP_SET_LONG_C
-| | | | | +--->BN_MP_GROW_C
-| | | | | +--->BN_MP_ZERO_C
| | +--->BN_MP_MOD_C
| | | +--->BN_MP_INIT_SIZE_C
| | | | +--->BN_MP_INIT_C
@@ -17478,8 +17448,6 @@ BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C
| | | +--->BN_MP_INIT_C
| | | +--->BN_MP_CLEAR_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
| | +--->BN_MP_SQR_C
| | | +--->BN_MP_TOOM_SQR_C
| | | | +--->BN_MP_MOD_2D_C
@@ -17822,8 +17790,6 @@ BN_MP_PRIME_STRONG_LUCAS_SELFRIDGE_C
| +--->BN_MP_CLAMP_C
+--->BN_MP_INIT_C
+--->BN_MP_SET_LONG_C
-| +--->BN_MP_GROW_C
-| +--->BN_MP_ZERO_C
+--->BN_MP_MUL_C
| +--->BN_MP_TOOM_MUL_C
| | +--->BN_MP_INIT_MULTI_C
@@ -18666,13 +18632,9 @@ BN_MP_SET_DOUBLE_C
BN_MP_SET_INT_C
+--->BN_MP_SET_LONG_C
-| +--->BN_MP_GROW_C
-| +--->BN_MP_ZERO_C
BN_MP_SET_LONG_C
-+--->BN_MP_GROW_C
-+--->BN_MP_ZERO_C
BN_MP_SET_LONG_LONG_C
@@ -19855,7 +19817,6 @@ BN_MP_SQRTMOD_PRIME_C
| +--->BN_MP_CLAMP_C
+--->BN_MP_SET_INT_C
| +--->BN_MP_SET_LONG_C
-| | +--->BN_MP_GROW_C
+--->BN_MP_SQRMOD_C
| +--->BN_MP_INIT_C
| +--->BN_MP_SQR_C
@@ -20593,8 +20554,6 @@ BN_MP_TC_AND_C
| +--->BN_MP_INIT_C
| +--->BN_MP_SET_INT_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
+--->BN_MP_MUL_2D_C
| +--->BN_MP_COPY_C
| | +--->BN_MP_GROW_C
@@ -20655,8 +20614,6 @@ BN_MP_TC_OR_C
| +--->BN_MP_INIT_C
| +--->BN_MP_SET_INT_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
+--->BN_MP_MUL_2D_C
| +--->BN_MP_COPY_C
| | +--->BN_MP_GROW_C
@@ -20698,8 +20655,6 @@ BN_MP_TC_XOR_C
| +--->BN_MP_INIT_C
| +--->BN_MP_SET_INT_C
| | +--->BN_MP_SET_LONG_C
-| | | +--->BN_MP_GROW_C
-| | | +--->BN_MP_ZERO_C
+--->BN_MP_MUL_2D_C
| +--->BN_MP_COPY_C
| | +--->BN_MP_GROW_C
diff --git a/makefile b/makefile
index 484222f..b31cd25 100644
--- a/makefile
+++ b/makefile
@@ -156,4 +156,5 @@ perlcritic:
perlcritic *.pl doc/*.pl
astyle:
- astyle --options=astylerc $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c
+ @echo " * run astyle on all sources"
+ @astyle --options=astylerc --formatted $(OBJECTS:.o=.c) tommath*.h demo/*.c etc/*.c mtest/mtest.c
diff --git a/testme.sh b/testme.sh
index b340df1..40ecb74 100755
--- a/testme.sh
+++ b/testme.sh
@@ -72,6 +72,10 @@ _help()
echo " --all Choose all architectures and gcc and clang"
echo " as compilers but does not run valgrind."
echo
+ echo " --format Runs the various source-code formatters"
+ echo " and generators and checks if the sources"
+ echo " are clean."
+ echo
echo " -h"
echo " --help This message"
echo
@@ -168,6 +172,7 @@ MTEST_RAND=""
VALGRIND_OPTS=" --leak-check=full --show-leak-kinds=all --error-exitcode=1 "
#VALGRIND_OPTS=""
VALGRIND_BIN=""
+CHECK_FORMAT=""
alive_pid=0
@@ -225,6 +230,9 @@ do
--mtest-real-rand)
MTEST_RAND="-DLTM_MTEST_REAL_RAND"
;;
+ --format)
+ CHECK_FORMAT="1"
+ ;;
--all)
COMPILERS="gcc clang"
ARCHFLAGS="-m64 -m32 -mx32"
@@ -243,6 +251,21 @@ do
shift
done
+function _check_git() {
+ git update-index --refresh >/dev/null || true
+ git diff-index --quiet HEAD -- . || ( echo "FAILURE: $*" && exit 1 )
+}
+
+if [[ "$CHECK_FORMAT" == "1" ]]
+then
+ make astyle
+ _check_git "make astyle"
+ make new_file
+ _check_git "make format"
+ perl helper.pl -a
+ exit $?
+fi
+
[[ "$VALGRIND_BIN" == "" ]] && VALGRIND_OPTS=""
# default to CC environment variable if no compiler is defined but some other options
diff --git a/tommath_class.h b/tommath_class.h
index 84fbd53..96b2ba0 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -937,8 +937,6 @@
#endif
#if defined(BN_MP_SET_LONG_C)
-# define BN_MP_GROW_C
-# define BN_MP_ZERO_C
#endif
#if defined(BN_MP_SET_LONG_LONG_C)