annotate tests/test-malloca.c @ 40196:e63f5d3edab5

relocatable-prog: Update documentation. * doc/relocatable-maint.texi (Supporting Relocation): Update to match the recent changes.
author Bruno Haible <bruno@clisp.org>
date Sun, 24 Feb 2019 01:49:15 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of safe automatic memory allocation.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2005, 2007, 2009-2019 Free Software Foundation, Inc.
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8940
diff changeset
4 This program is free software: you can redistribute it and/or modify
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8940
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8940
diff changeset
7 (at your option) any later version.
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005. */
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include "malloca.h"
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <stdlib.h>
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 static void
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 do_allocation (int n)
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 void *ptr = malloca (n);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 freea (ptr);
13610
8cea75815700 tests: silence clang warning
Eric Blake <eblake@redhat.com>
parents: 12559
diff changeset
30 safe_alloca (n);
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 }
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 void (*func) (int) = do_allocation;
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 int
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 main ()
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 int i;
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
14203
13950a70790f test-malloca: unset MALLOC_PERTURB_ to speed up test
Pádraig Brady <P@draigBrady.com>
parents: 14079
diff changeset
40 /* This slows down malloc a lot. */
13950a70790f test-malloca: unset MALLOC_PERTURB_ to speed up test
Pádraig Brady <P@draigBrady.com>
parents: 14079
diff changeset
41 unsetenv ("MALLOC_PERTURB_");
13950a70790f test-malloca: unset MALLOC_PERTURB_ to speed up test
Pádraig Brady <P@draigBrady.com>
parents: 14079
diff changeset
42
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 /* Repeat a lot of times, to make sure there's no memory leak. */
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 for (i = 0; i < 50000; i++)
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 {
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* Try various values.
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 n = 0 gave a crash on Alpha with gcc-2.5.8.
16935
498a2211d839 Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
48 Some versions of Mac OS X have a stack size limit of 512 KB. */
8940
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 func (34);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 func (134);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 func (399);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 func (510823);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 func (129321);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 func (0);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 func (4070);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 func (4095);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 func (1);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 func (16582);
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 }
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 return 0;
4a7efe764fa5 Move to here from test-allocsa.c.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 }