aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorGareth Rees2013-05-30 16:21:42 +0100
committerGareth Rees2013-05-30 16:21:42 +0100
commitaa16236b2aca51e71f8f9c122ffff7a5f37a5f78 (patch)
tree4755d3125c196ea188c00c4babb70c517243e124 /mps/code
parentdad0cabdf7fb858d946de657beea01ca1e27527f (diff)
downloademacs-aa16236b2aca51e71f8f9c122ffff7a5f37a5f78.tar.gz
emacs-aa16236b2aca51e71f8f9c122ffff7a5f37a5f78.zip
Ansi i/o module checks its arguments using aver.
Copied from Perforce Change: 182327 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/mpsioan.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/mps/code/mpsioan.c b/mps/code/mpsioan.c
index 966847575fb..77b27ee1712 100644
--- a/mps/code/mpsioan.c
+++ b/mps/code/mpsioan.c
@@ -1,16 +1,27 @@
1/* mpsioan.c: RAVENBROOK MEMORY POOL SYSTEM I/O IMPLEMENTATION (ANSI) 1/* mpsioan.c: RAVENBROOK MEMORY POOL SYSTEM I/O IMPLEMENTATION (ANSI)
2 * 2 *
3 * $Id$ 3 * $Id$
4 * Copyright (c) 2001 Ravenbrook Limited. See end of file for license. 4 * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license.
5 * 5 *
6 * .readership: For MPS client application developers and MPS developers. 6 * .readership: For MPS client application developers and MPS developers.
7 * .sources: <design/io/> 7 * .sources: <design/io/>
8 */ 8 */
9 9
10#include "mpsio.h" 10#include "mpsio.h"
11
12#include "mpstd.h" 11#include "mpstd.h"
13 12
13/* We don't want to use the ANSI assert() to check that the interface
14 * is being used correctly, because it's not controlled by the MPS
15 * variety mechanism: we might end up with assertions being turned on
16 * in the HOT variety or turned off in the COOL variety (depending on
17 * whether or not the client program compiles the MPS with NDEBUG
18 * defined). So we include "check.h" and use AVER() instead. See
19 * job003504. If you are developing your own plinth, you should
20 * consider whether to use your own preferred assertion mechanism
21 * instead.
22 */
23#include "check.h"
24
14#ifdef MPS_OS_XC 25#ifdef MPS_OS_XC
15#include "osxc.h" 26#include "osxc.h"
16#endif 27#endif
@@ -53,15 +64,20 @@ mps_res_t mps_io_create(mps_io_t *mps_io_r)
53void mps_io_destroy(mps_io_t mps_io) 64void mps_io_destroy(mps_io_t mps_io)
54{ 65{
55 FILE *f = (FILE *)mps_io; 66 FILE *f = (FILE *)mps_io;
56 ioFile = NULL; /* Should check f == ioFile */ 67 AVER(f == ioFile);
68 AVER(f != NULL);
69
70 ioFile = NULL;
57 (void)fclose(f); 71 (void)fclose(f);
58} 72}
59 73
60 74
61mps_res_t mps_io_write(mps_io_t mps_io, void *buf, size_t size) 75mps_res_t mps_io_write(mps_io_t mps_io, void *buf, size_t size)
62{ 76{
63 FILE *f = (FILE *)mps_io; /* Should check f == ioFile */ 77 FILE *f = (FILE *)mps_io;
64 size_t n; 78 size_t n;
79 AVER(f == ioFile);
80 AVER(f != NULL);
65 81
66 n = fwrite(buf, size, 1, f); 82 n = fwrite(buf, size, 1, f);
67 if(n != 1) 83 if(n != 1)
@@ -73,8 +89,10 @@ mps_res_t mps_io_write(mps_io_t mps_io, void *buf, size_t size)
73 89
74mps_res_t mps_io_flush(mps_io_t mps_io) 90mps_res_t mps_io_flush(mps_io_t mps_io)
75{ 91{
76 FILE *f = (FILE *)mps_io; /* Should check f == ioFile */ 92 FILE *f = (FILE *)mps_io;
77 int e; 93 int e;
94 AVER(f == ioFile);
95 AVER(f != NULL);
78 96
79 e = fflush(f); 97 e = fflush(f);
80 if(e == EOF) 98 if(e == EOF)
@@ -86,7 +104,7 @@ mps_res_t mps_io_flush(mps_io_t mps_io)
86 104
87/* C. COPYRIGHT AND LICENSE 105/* C. COPYRIGHT AND LICENSE
88 * 106 *
89 * Copyright (C) 2001-2002 Ravenbrook Limited <http://www.ravenbrook.com/>. 107 * Copyright (C) 2001-2013 Ravenbrook Limited <http://www.ravenbrook.com/>.
90 * All rights reserved. This is an open source license. Contact 108 * All rights reserved. This is an open source license. Contact
91 * Ravenbrook for commercial licensing options. 109 * Ravenbrook for commercial licensing options.
92 * 110 *