Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 86f7bb2

Browse files
committed
config.d: use enums instead of structs for __c_long, etc.
1 parent b3dbfc2 commit 86f7bb2

File tree

1 file changed

+72
-55
lines changed

1 file changed

+72
-55
lines changed

src/core/stdc/config.d

Lines changed: 72 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
2-
* D header file for C99.
2+
* D compatible types that correspond to various basic types in associated
3+
* C and C++ compilers.
34
*
45
* Copyright: Copyright Sean Kelly 2005 - 2009.
56
* License: Distributed under the
@@ -12,6 +13,53 @@
1213

1314
module core.stdc.config;
1415

16+
version (StdDdoc)
17+
{
18+
/***
19+
* Used for a signed integer type that corresponds in size to the associated
20+
* C compiler's `long` type.
21+
*/
22+
alias c_long = int;
23+
24+
/***
25+
* Used for an unsigned integer type that corresponds in size to the associated
26+
* C compiler's `unsigned long` type.
27+
*/
28+
alias c_ulong = uint;
29+
30+
/***
31+
* Used for a signed integer type that corresponds in size and mangling to the associated
32+
* C++ compiler's `long` type.
33+
*/
34+
alias cpp_long = c_long;
35+
36+
/***
37+
* Used for an unsigned integer type that corresponds in size and mangling to the associated
38+
* C++ compiler's `unsigned long` type.
39+
*/
40+
alias cpp_ulong = c_ulong;
41+
42+
/***
43+
* Used for a floating point type that corresponds in size and mangling to the associated
44+
* C++ compiler's `long double` type.
45+
*/
46+
alias c_long_double = real;
47+
48+
/***
49+
* Used for an unsigned integer type that corresponds in size and mangling to the associated
50+
* C++ compiler's `size_t` type.
51+
*/
52+
alias cpp_size_t = size_t;
53+
54+
/***
55+
* Used for a signed integer type that corresponds in size and mangling to the associated
56+
* C++ compiler's `ptrdiff_t` type.
57+
*/
58+
alias cpp_ptrdiff_t = ptrdiff_t;
59+
}
60+
else
61+
{
62+
1563
version (OSX)
1664
version = Darwin;
1765
else version (iOS)
@@ -21,40 +69,10 @@ else version (TVOS)
2169
else version (WatchOS)
2270
version = Darwin;
2371

24-
extern (C):
25-
@trusted: // Types only.
26-
nothrow:
27-
@nogc:
28-
2972
version( Windows )
3073
{
31-
struct __c_long
32-
{
33-
pure nothrow @nogc @safe:
34-
this(int x) { lng = x; }
35-
int lng;
36-
alias lng this;
37-
}
38-
39-
struct __c_ulong
40-
{
41-
pure nothrow @nogc @safe:
42-
this(uint x) { lng = x; }
43-
uint lng;
44-
alias lng this;
45-
}
46-
47-
/*
48-
* This is cpp_long instead of c_long because:
49-
* 1. Implicit casting of an int to __c_long doesn't happen, because D doesn't
50-
* allow constructor calls in implicit conversions.
51-
* 2. long lng;
52-
* cast(__c_long)lng;
53-
* does not work because lng has to be implicitly cast to an int in the constructor,
54-
* and since that truncates it is not done.
55-
* Both of these break existing code, so until we find a resolution the types are named
56-
* cpp_xxxx.
57-
*/
74+
enum __c_long : int;
75+
enum __c_ulong : uint;
5876

5977
alias __c_long cpp_long;
6078
alias __c_ulong cpp_ulong;
@@ -66,26 +84,19 @@ else version( Posix )
6684
{
6785
static if( (void*).sizeof > int.sizeof )
6886
{
87+
enum __c_long : long;
88+
enum __c_ulong : ulong;
89+
90+
alias __c_long cpp_long;
91+
alias __c_ulong cpp_ulong;
92+
6993
alias long c_long;
7094
alias ulong c_ulong;
7195
}
7296
else
7397
{
74-
struct __c_long
75-
{
76-
pure nothrow @nogc @safe:
77-
this(int x) { lng = x; }
78-
int lng;
79-
alias lng this;
80-
}
81-
82-
struct __c_ulong
83-
{
84-
pure nothrow @nogc @safe:
85-
this(uint x) { lng = x; }
86-
uint lng;
87-
alias lng this;
88-
}
98+
enum __c_long : int;
99+
enum __c_ulong : uint;
89100

90101
alias __c_long cpp_long;
91102
alias __c_ulong cpp_ulong;
@@ -103,13 +114,7 @@ version( CRuntime_Microsoft )
103114
* to generate the correct name mangling and correct function call/return
104115
* ABI conformance.
105116
*/
106-
struct __c_long_double
107-
{
108-
pure nothrow @nogc @safe:
109-
this(double d) { ld = d; }
110-
double ld;
111-
alias ld this;
112-
}
117+
enum __c_long_double : double;
113118

114119
alias __c_long_double c_long_double;
115120
}
@@ -150,3 +155,15 @@ else version( SDC )
150155
}
151156

152157
static assert(is(c_long_double), "c_long_double needs to be declared for this platform/architecture.");
158+
159+
version (Darwin)
160+
{
161+
alias cpp_size_t = cpp_ulong;
162+
alias cpp_ptrdiff_t = cpp_long;
163+
}
164+
else
165+
{
166+
alias cpp_size_t = size_t;
167+
alias cpp_ptrdiff_t = ptrdiff_t;
168+
}
169+
}

0 commit comments

Comments
 (0)