Skip to content

Commit 12f5832

Browse files
authored
Convert more wasi-libc code to //-style comments. (#153)
This is purely a style change, in accordance with #116.
1 parent ec86d4d commit 12f5832

1 file changed

Lines changed: 31 additions & 37 deletions

File tree

dlmalloc/src/dlmalloc.c

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,68 @@
1-
/*
2-
* This file is a wrapper around malloc.c, which is the upstream source file.
3-
* It sets configuration flags and controls which symbols are exported.
4-
*/
1+
// This file is a wrapper around malloc.c, which is the upstream source file.
2+
// It sets configuration flags and controls which symbols are exported.
53

64
#include <stddef.h>
75
#include <malloc.h>
86

9-
/* Define configuration macros for dlmalloc. */
7+
// Define configuration macros for dlmalloc.
108

11-
/* WebAssembly doesn't have mmap-style memory allocation. */
9+
// WebAssembly doesn't have mmap-style memory allocation.
1210
#define HAVE_MMAP 0
1311

14-
/* WebAssembly doesn't support shrinking linear memory. */
12+
// WebAssembly doesn't support shrinking linear memory.
1513
#define MORECORE_CANNOT_TRIM 1
1614

17-
/* Disable sanity checks to reduce code size. */
15+
// Disable sanity checks to reduce code size.
1816
#define ABORT __builtin_unreachable()
1917

20-
/* If threads are enabled, enable support for threads. */
18+
// If threads are enabled, enable support for threads.
2119
#ifdef _REENTRANT
2220
#define USE_LOCKS 1
2321
#endif
2422

25-
/* Make malloc deterministic. */
23+
// Make malloc deterministic.
2624
#define LACKS_TIME_H 1
2725

28-
/* Disable malloc statistics generation to reduce code size. */
26+
// Disable malloc statistics generation to reduce code size.
2927
#define NO_MALLINFO 1
3028
#define NO_MALLOC_STATS 1
3129

32-
/* Align malloc regions to 16, to avoid unaligned SIMD accesses. */
30+
// Align malloc regions to 16, to avoid unaligned SIMD accesses.
3331
#define MALLOC_ALIGNMENT 16
3432

35-
/*
36-
* Declare errno values used by dlmalloc. We define them like this to avoid
37-
* putting specific errno values in the ABI.
38-
*/
33+
// Declare errno values used by dlmalloc. We define them like this to avoid
34+
// putting specific errno values in the ABI.
3935
extern const int __ENOMEM;
4036
#define ENOMEM __ENOMEM
4137
extern const int __EINVAL;
4238
#define EINVAL __EINVAL
4339

44-
/*
45-
* Define USE_DL_PREFIX so that we leave dlmalloc's names prefixed with 'dl'.
46-
* We define them as "static", and we wrap them with public names below. This
47-
* serves two purposes:
48-
*
49-
* One is to make it easy to control which symbols are exported; dlmalloc
50-
* defines several non-standard functions and we wish to explicitly control
51-
* which functions are part of our public-facing interface.
52-
*
53-
* The other is to protect against compilers optimizing based on the assumption
54-
* that they know what functions with names like "malloc" do. Code in the
55-
* implementation will call functions like "dlmalloc" and assume it can use
56-
* the resulting pointers to access the metadata outside of the nominally
57-
* allocated objects. However, if the function were named "malloc", compilers
58-
* might see code like that and assume it has undefined behavior and can be
59-
* optimized away. By using "dlmalloc" in the implementation, we don't need
60-
* -fno-builtin to avoid this problem.
61-
*/
40+
// Define USE_DL_PREFIX so that we leave dlmalloc's names prefixed with 'dl'.
41+
// We define them as "static", and we wrap them with public names below. This
42+
// serves two purposes:
43+
//
44+
// One is to make it easy to control which symbols are exported; dlmalloc
45+
// defines several non-standard functions and we wish to explicitly control
46+
// which functions are part of our public-facing interface.
47+
//
48+
// The other is to protect against compilers optimizing based on the assumption
49+
// that they know what functions with names like "malloc" do. Code in the
50+
// implementation will call functions like "dlmalloc" and assume it can use
51+
// the resulting pointers to access the metadata outside of the nominally
52+
// allocated objects. However, if the function were named "malloc", compilers
53+
// might see code like that and assume it has undefined behavior and can be
54+
// optimized away. By using "dlmalloc" in the implementation, we don't need
55+
// -fno-builtin to avoid this problem.
6256
#define USE_DL_PREFIX 1
6357
#define DLMALLOC_EXPORT static inline
6458

65-
/* This isn't declared with DLMALLOC_EXPORT so make it static explicitly. */
59+
// This isn't declared with DLMALLOC_EXPORT so make it static explicitly.
6660
static size_t dlmalloc_usable_size(void*);
6761

68-
/* Include the upstream dlmalloc's malloc.c. */
62+
// Include the upstream dlmalloc's malloc.c.
6963
#include "malloc.c"
7064

71-
/* Export the public names. */
65+
// Export the public names.
7266

7367
void *malloc(size_t size) {
7468
return dlmalloc(size);

0 commit comments

Comments
 (0)