Skip to content

Commit d63817d

Browse files
committed
Final tweaks
* note on alloca() * fix zz_mul(u, u, u) * add test for builds with --enable-alloca * use $PREFIX
1 parent 06734bf commit d63817d

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,27 @@ jobs:
1919
- uses: actions/checkout@v5
2020
- run: sudo apt-get update
2121
- run: sudo apt-get install lcov texlive
22+
- name: Cache GNU GMP builds
23+
id: cache-gmp
24+
uses: actions/cache@v4
25+
with:
26+
path: .local
27+
key: ${{ matrix.os }}-${{ hashFiles('scripts/*') }}
2228
- run: sh scripts/cibw_before_all.sh
29+
if: steps.cache-gmp.outputs.cache-hit != 'true'
2330
- run: autoreconf -if
2431
- run: ./configure -q --enable-gcov
32+
env:
33+
PKG_CONFIG_PATH: ${{ github.workspace }}/.local/lib/pkgconfig
2534
- run: make -s
2635
- run: make -s check
36+
env:
37+
LD_LIBRARY_PATH: ${{ github.workspace }}/.local/lib
2738
- run: lcov --capture --directory . --output-file coverage.info
2839
- run: genhtml coverage.info --output-directory coverage
2940
- run: make -s distcheck
41+
env:
42+
LD_LIBRARY_PATH: ${{ github.workspace }}/.local/lib
3043
- uses: actions/upload-artifact@v4
3144
with:
3245
name: coverage

doc/zz.texi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ return codes are supported:
8383
@item @code{ZZ_BUF}: Buffer overflow, supplied buffer too small.
8484
@end itemize
8585

86+
Please note, that the GNU GMP library must be compiled with the
87+
@option{--disable-alloca} configure option to prevent using alloca() for temporary
88+
workspace allocation (and use the heap instead).
89+
8690
@node Functions, References, Introduction, Top
8791
@chapter Functions
8892

@@ -332,11 +336,11 @@ Set @var{w} to the least common multiple of @var{u} and @var{v}.
332336
@section Combinatorics
333337

334338
@deftypefun zz_err zz_fac (uint64_t @var{u}, zz_t *@var{v})
335-
Set @var{v} to @math{u!}.
339+
Set @var{v} to @math{@var{u}!}.
336340
@end deftypefun
337341

338342
@deftypefun zz_err zz_fac2 (uint64_t @var{u}, zz_t *@var{v})
339-
Set @var{v} to @math{u!!}.
343+
Set @var{v} to @math{@var{u}!!}.
340344
@end deftypefun
341345

342346
@deftypefun zz_err zz_fib (uint64_t @var{u}, zz_t *@var{v})

scripts/cibw_before_all.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rm config.guess && mv configfsf.guess config.guess && chmod +x config.guess
2727
--disable-static \
2828
--with-pic \
2929
--disable-alloca \
30+
--prefix=$PREFIX \
3031
--quiet
3132

32-
sudo make --silent all install
33+
make --silent all install

tests/t-fac.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ int main(void)
5858
perror("setrlimit");
5959
return 1;
6060
}
61+
/* to trigger crash for GMP builds with alloca() enabled */
62+
if (getrlimit(RLIMIT_STACK, &old)) {
63+
perror("getrlimit");
64+
return 1;
65+
}
66+
new.rlim_max = old.rlim_max;
67+
new.rlim_cur = 128*1000;
68+
if (setrlimit(RLIMIT_STACK, &new)) {
69+
perror("setrlimit");
70+
return 1;
71+
}
6172
check_fac_outofmem();
73+
zz_finish();
6274
return 0;
6375
}

tests/t-mul.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,6 @@ int main(void)
116116
#if HAVE_PTHREAD_H
117117
check_square_outofmem_pthread();
118118
#endif
119+
zz_finish();
119120
return 0;
120121
}

zz.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ zz_mul(const zz_t *u, const zz_t *v, zz_t *w)
995995
/* LCOV_EXCL_STOP */
996996
}
997997

998-
zz_err ret = zz_mul(&tmp, v, w);
998+
zz_err ret = u == v ? zz_mul(&tmp, &tmp, w) : zz_mul(&tmp, v, w);
999999

10001000
zz_clear(&tmp);
10011001
return ret;

0 commit comments

Comments
 (0)