Skip to content

Commit 9311008

Browse files
committed
reorganized libcxx headers and replaced __abs_overloads to improve maintainability
1 parent b4b5ab4 commit 9311008

10 files changed

Lines changed: 147 additions & 166 deletions

File tree

src/libc/include/__math_def.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,9 @@ double expm1(double);
139139
float expm1f(float);
140140
long double expm1l(long double);
141141

142-
#ifndef _ABS_FLOAT_DEFINED
143-
#define _ABS_FLOAT_DEFINED
144142
double fabs(double);
145143
float fabsf(float);
146144
long double fabsl(long double);
147-
#endif /* _ABS_FLOAT_DEFINED */
148145

149146
double fdim(double, double);
150147
float fdimf(float, float);

src/libc/include/math.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#ifndef _MATH_H
22
#define _MATH_H
33

4-
#ifdef __cplusplus
5-
6-
#include <cmath>
7-
8-
#else /* __cplusplus */
9-
104
#include <__math_def.h>
115

6+
#ifndef __cplusplus
7+
128
static inline __attribute__((__always_inline__))
139
bool __signbitf(float __x) {
1410
if (__builtin_constant_p(__x)) {

src/libc/include/stdio.h

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -133,49 +133,4 @@ void perror(const char *str);
133133

134134
__END_DECLS
135135

136-
#ifdef __cplusplus
137-
namespace std {
138-
using ::size_t;
139-
using ::FILE;
140-
141-
using ::fopen;
142-
using ::freopen;
143-
using ::fclose;
144-
using ::fflush;
145-
using ::ferror;
146-
using ::feof;
147-
using ::clearerr;
148-
using ::fread;
149-
using ::fwrite;
150-
using ::ftell;
151-
using ::fseek;
152-
using ::rewind;
153-
using ::fgetc;
154-
using ::fgets;
155-
using ::ungetc;
156-
using ::fputc;
157-
using ::fputs;
158-
using ::remove;
159-
using ::rename;
160-
using ::getchar;
161-
using ::putchar;
162-
using ::puts;
163-
using ::getc;
164-
using ::putc;
165-
using ::printf;
166-
using ::vprintf;
167-
using ::sprintf;
168-
using ::vsprintf;
169-
using ::snprintf;
170-
using ::vsnprintf;
171-
using ::fprintf;
172-
using ::vfprintf;
173-
using ::asprintf;
174-
using ::vasprintf;
175-
using ::sscanf;
176-
using ::vsscanf;
177-
using ::perror;
178-
} /* namespace std */
179-
#endif /* __cplusplus */
180-
181136
#endif /* _STDIO_H */

src/libc/include/stdlib.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,6 @@ void quick_exit(int) __NOEXCEPT __attribute__((noreturn));
104104

105105
void _Exit(int) __NOEXCEPT __attribute__((noreturn));
106106

107-
#ifndef _ABS_INT_DEFINED
108-
#define _ABS_INT_DEFINED
109-
110107
int abs(int n);
111108
long labs(long n);
112109
long long llabs(long long n);
@@ -115,8 +112,6 @@ long long llabs(long long n);
115112
signed __int48 i48abs(signed __int48 n) __NOEXCEPT_CONST;
116113
#endif /* __SIZEOF_INT48__ */
117114

118-
#endif /* _ABS_INT_DEFINED */
119-
120115
div_t div(int numer, int denom);
121116

122117
ldiv_t ldiv(long numer, long denom);

src/libcxx/include/__abs_overloads

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/libcxx/include/cmath

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// -*- C++ -*-
2+
#ifndef _EZCXX_CMATH
3+
#define _EZCXX_CMATH
4+
5+
#include <math.h>
6+
7+
#pragma clang system_header
8+
9+
#endif // _EZCXX_CMATH

src/libcxx/include/cstdlib

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,7 @@
33
#define _EZCXX_CSTDLIB
44

55
#include <stdlib.h>
6-
#include <__abs_overloads>
76

87
#pragma clang system_header
98

10-
namespace std {
11-
using ::calloc;
12-
using ::malloc;
13-
using ::realloc;
14-
using ::free;
15-
16-
using ::atof;
17-
using ::atoi;
18-
using ::atol;
19-
using ::atoll;
20-
using ::strtof;
21-
using ::strtod;
22-
using ::strtold;
23-
using ::strtol;
24-
using ::strtoll;
25-
using ::strtoul;
26-
using ::strtoull;
27-
28-
using ::srand;
29-
using ::rand;
30-
31-
using ::bsearch;
32-
using ::qsort;
33-
34-
using ::abort;
35-
using ::atexit;
36-
using ::on_exit;
37-
using ::exit;
38-
using ::at_quick_exit;
39-
using ::quick_exit;
40-
using ::_Exit;
41-
42-
using ::labs;
43-
using ::llabs;
44-
45-
using ::div;
46-
using ::ldiv;
47-
using ::lldiv;
48-
inline constexpr ldiv_t div(long __x, long __y) { return ldiv(__x, __y); }
49-
inline constexpr lldiv_t div(long long __x, long long __y) { return lldiv(__x, __y); }
50-
#ifdef __SIZEOF_INT48__
51-
using ::i48div;
52-
inline i48div_t div(signed __int48 __x, signed __int48 __y) { return i48div(__x, __y); }
53-
#endif // __SIZEOF_INT48__
54-
55-
} // namespace std
56-
579
#endif // _EZCXX_CSTDLIB

src/libcxx/include/math.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// -*- C++ -*-
2-
#ifndef _EZCXX_CMATH
3-
#define _EZCXX_CMATH
2+
#ifndef _EZCXX_MATH_H
3+
#define _EZCXX_MATH_H
44

5-
#include <__math_def.h>
5+
#include <stdlib.h>
6+
#include_next <math.h>
67
#include <type_traits>
7-
#include <__abs_overloads>
88

99
#pragma clang system_header
1010

@@ -830,4 +830,4 @@ using std::islessequal;
830830
using std::islessgreater;
831831
using std::isunordered;
832832

833-
#endif // _EZCXX_CMATH
833+
#endif // _EZCXX_MATH_H

src/libcxx/include/stdio.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// -*- C++ -*-
2+
#ifndef _EZCXX_STDIO_H
3+
#define _EZCXX_STDIO_H
4+
5+
#include_next <stdio.h>
6+
7+
#pragma clang system_header
8+
9+
namespace std {
10+
using ::size_t;
11+
using ::FILE;
12+
13+
using ::fopen;
14+
using ::freopen;
15+
using ::fclose;
16+
using ::fflush;
17+
using ::ferror;
18+
using ::feof;
19+
using ::clearerr;
20+
using ::fread;
21+
using ::fwrite;
22+
using ::ftell;
23+
using ::fseek;
24+
using ::rewind;
25+
using ::fgetc;
26+
using ::fgets;
27+
using ::ungetc;
28+
using ::fputc;
29+
using ::fputs;
30+
using ::remove;
31+
using ::rename;
32+
using ::getchar;
33+
using ::putchar;
34+
using ::puts;
35+
using ::getc;
36+
using ::putc;
37+
using ::printf;
38+
using ::vprintf;
39+
using ::sprintf;
40+
using ::vsprintf;
41+
using ::snprintf;
42+
using ::vsnprintf;
43+
using ::fprintf;
44+
using ::vfprintf;
45+
using ::asprintf;
46+
using ::vasprintf;
47+
using ::sscanf;
48+
using ::vsscanf;
49+
using ::perror;
50+
} // namespace std
51+
52+
#endif // _EZCXX_STDIO_H

src/libcxx/include/stdlib.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// -*- C++ -*-
2+
#ifndef _EZCXX_STDLIB_H
3+
#define _EZCXX_STDLIB_H
4+
5+
#include_next <stdlib.h>
6+
7+
#pragma clang system_header
8+
9+
namespace std {
10+
11+
inline constexpr long abs(long __x) { return __builtin_labs(__x); }
12+
13+
inline constexpr long long abs(long long __x) { return __builtin_llabs(__x); }
14+
15+
#ifdef __SIZEOF_INT48__
16+
inline signed __int48 abs(signed __int48 __x) { return i48abs(__x); }
17+
#endif // __SIZEOF_INT48__
18+
19+
inline constexpr float abs(float __x) { return __builtin_fabsf(__x); }
20+
21+
inline constexpr double abs(double __x) { return __builtin_fabs(__x); }
22+
23+
inline constexpr long double abs(long double __x) { return __builtin_fabsl(__x); }
24+
25+
inline constexpr ldiv_t div(long __x, long __y) { return ::ldiv(__x, __y); }
26+
27+
inline constexpr lldiv_t div(long long __x, long long __y) { return ::lldiv(__x, __y); }
28+
29+
#ifdef __SIZEOF_INT48__
30+
inline i48div_t div(signed __int48 __x, signed __int48 __y) { return ::i48div(__x, __y); }
31+
#endif // __SIZEOF_INT48__
32+
33+
using ::calloc;
34+
using ::malloc;
35+
using ::realloc;
36+
using ::free;
37+
38+
using ::atof;
39+
using ::atoi;
40+
using ::atol;
41+
using ::atoll;
42+
using ::strtof;
43+
using ::strtod;
44+
using ::strtold;
45+
using ::strtol;
46+
using ::strtoll;
47+
using ::strtoul;
48+
using ::strtoull;
49+
50+
using ::srand;
51+
using ::rand;
52+
53+
using ::bsearch;
54+
using ::qsort;
55+
56+
using ::abort;
57+
using ::atexit;
58+
using ::on_exit;
59+
using ::exit;
60+
using ::at_quick_exit;
61+
using ::quick_exit;
62+
using ::_Exit;
63+
64+
using ::abs;
65+
using ::labs;
66+
using ::llabs;
67+
68+
using ::div;
69+
using ::ldiv;
70+
using ::lldiv;
71+
72+
#ifdef __SIZEOF_INT48__
73+
using ::i48abs;
74+
using ::i48div;
75+
#endif // __SIZEOF_INT48__
76+
77+
} // namespace std
78+
79+
#endif // _EZCXX_STDLIB_H

0 commit comments

Comments
 (0)