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

Commit 90770d3

Browse files
authored
Merge pull request #2066 from yshui/musl_core_stdc
Add musl libc definitions to core/stdc/* merged-on-behalf-of: Iain Buclaw <ibuclaw@gdcproject.org>
2 parents 5063348 + 98f9e08 commit 90770d3

File tree

5 files changed

+260
-0
lines changed

5 files changed

+260
-0
lines changed

src/core/stdc/assert_.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ else version (CRuntime_Bionic)
6868
{
6969
void __assert(const(char)* __file, int __line, const(char)* __msg);
7070
}
71+
else version (CRuntime_Musl)
72+
{
73+
/***
74+
* Assert failure function in the Musl C library.
75+
*/
76+
void __assert_fail(const(char)* exp, const(char)* file, uint line, const(char)* func);
77+
}
7178
else
7279
{
7380
static assert(0);

src/core/stdc/fenv.d

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,33 @@ else version( Solaris )
309309

310310
alias int fexcept_t;
311311
}
312+
else version( CRuntime_Musl )
313+
{
314+
version (X86_64)
315+
{
316+
struct fenv_t
317+
{
318+
ushort __control_word;
319+
ushort __unused1;
320+
ushort __status_word;
321+
ushort __unused2;
322+
ushort __tags;
323+
ushort __unused3;
324+
uint __eip;
325+
ushort __cs_selector;
326+
ushort __opcode;
327+
uint __data_offset;
328+
ushort __data_selector;
329+
ushort __unused5;
330+
uint __mxcsr;
331+
}
332+
alias ushort fexcept_t;
333+
}
334+
else
335+
{
336+
static assert(false, "Architecture not supported.");
337+
}
338+
}
312339
else
313340
{
314341
static assert( false, "Unsupported platform" );
@@ -634,6 +661,11 @@ else version( Solaris )
634661
///
635662
enum FE_DFL_ENV = &__fenv_def_env;
636663
}
664+
else version( CRuntime_Musl )
665+
{
666+
///
667+
enum FE_DFL_ENV = cast(fenv_t*)(-1);
668+
}
637669
else
638670
{
639671
static assert( false, "Unsupported platform" );

src/core/stdc/locale.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,23 @@ else version(Solaris)
218218
///
219219
enum LC_ALL = 6;
220220
}
221+
else version(CRuntime_Musl)
222+
{
223+
///
224+
enum LC_CTYPE = 0;
225+
///
226+
enum LC_NUMERIC = 1;
227+
///
228+
enum LC_TIME = 2;
229+
///
230+
enum LC_COLLATE = 3;
231+
///
232+
enum LC_MONETARY = 4;
233+
///
234+
enum LC_MESSAGES = 5;
235+
///
236+
enum LC_ALL = 6;
237+
}
221238
else
222239
{
223240
static assert(false, "Unsupported platform");

src/core/stdc/math.d

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,136 @@ else version( CRuntime_Glibc )
601601
}
602602
}
603603
}
604+
else version( CRuntime_Musl )
605+
{
606+
enum
607+
{
608+
///
609+
FP_NAN,
610+
///
611+
FP_INFINITE,
612+
///
613+
FP_ZERO,
614+
///
615+
FP_SUBNORMAL,
616+
///
617+
FP_NORMAL,
618+
}
619+
620+
enum
621+
{
622+
///
623+
FP_FAST_FMA = 0,
624+
///
625+
FP_FAST_FMAF = 0,
626+
///
627+
FP_FAST_FMAL = 0,
628+
}
629+
630+
int __fpclassifyf(float x);
631+
int __fpclassify(double x);
632+
int __fpclassifyl(real x);
633+
634+
int __signbitf(float x);
635+
int __signbit(double x);
636+
int __signbitl(real x);
637+
638+
extern (D)
639+
{
640+
//int fpclassify(real-floating x);
641+
///
642+
int fpclassify(float x) { return __fpclassifyf(x); }
643+
///
644+
int fpclassify(double x) { return __fpclassify(x); }
645+
///
646+
int fpclassify(real x)
647+
{
648+
return (real.sizeof == double.sizeof)
649+
? __fpclassify(x)
650+
: __fpclassifyl(x);
651+
}
652+
private uint __FLOAT_BITS(float __f)
653+
{
654+
union __u_t {
655+
float __f;
656+
uint __i;
657+
}
658+
__u_t __u;
659+
__u.__f = __f;
660+
return __u.__i;
661+
}
662+
private ulong __DOUBLE_BITS(double __f)
663+
{
664+
union __u_t {
665+
double __f;
666+
ulong __i;
667+
}
668+
__u_t __u;
669+
__u.__f = __f;
670+
return __u.__i;
671+
}
672+
673+
//int isfinite(real-floating x);
674+
///
675+
int isfinite(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000; }
676+
///
677+
int isfinite(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) < 0x7ffUL<<52; }
678+
///
679+
int isfinite(real x)
680+
{
681+
return (real.sizeof == double.sizeof)
682+
? isfinite(cast(double)x)
683+
: __fpclassifyl(x) > FP_INFINITE;
684+
}
685+
686+
//int isinf(real-floating x);
687+
///
688+
int isinf(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000; }
689+
///
690+
int isinf(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) == 0x7ffUL<<52; }
691+
///
692+
int isinf(real x)
693+
{
694+
return (real.sizeof == double.sizeof)
695+
? isinf(cast(double)x)
696+
: __fpclassifyl(x) == FP_INFINITE;
697+
}
698+
699+
//int isnan(real-floating x);
700+
///
701+
int isnan(float x) { return (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000; }
702+
///
703+
int isnan(double x) { return (__DOUBLE_BITS(x) & -1UL>>1) > 0x7ffUL<<52; }
704+
///
705+
int isnan(real x)
706+
{
707+
return (real.sizeof == double.sizeof)
708+
? isnan(cast(double)x)
709+
: __fpclassifyl(x) == FP_NAN;
710+
}
711+
712+
//int isnormal(real-floating x);
713+
///
714+
int isnormal(float x) { return fpclassify(x) == FP_NORMAL; }
715+
///
716+
int isnormal(double x) { return fpclassify(x) == FP_NORMAL; }
717+
///
718+
int isnormal(real x) { return fpclassify(x) == FP_NORMAL; }
719+
720+
//int signbit(real-floating x);
721+
///
722+
int signbit(float x) { return __signbitf(x); }
723+
///
724+
int signbit(double x) { return __signbit(x); }
725+
///
726+
int signbit(real x)
727+
{
728+
return (real.sizeof == double.sizeof)
729+
? __signbit(x)
730+
: __signbitl(x);
731+
}
732+
}
733+
}
604734
else version( MinGW )
605735
{
606736
enum

src/core/stdc/stdio.d

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ else version( CRuntime_Glibc )
121121
L_tmpnam = 20
122122
}
123123
}
124+
else version( CRuntime_Musl )
125+
{
126+
enum
127+
{
128+
///
129+
BUFSIZ = 1024,
130+
///
131+
EOF = -1,
132+
///
133+
FOPEN_MAX = 1000,
134+
///
135+
FILENAME_MAX = 4096,
136+
///
137+
TMP_MAX = 10000,
138+
///
139+
L_tmpnam = 20
140+
}
141+
}
124142
else version( Darwin )
125143
{
126144
enum
@@ -383,6 +401,20 @@ else version( CRuntime_Glibc )
383401
///
384402
alias shared(_IO_FILE) FILE;
385403
}
404+
else version( CRuntime_Musl )
405+
{
406+
union fpos_t
407+
{
408+
char[16] __opaque;
409+
double __align;
410+
}
411+
struct _IO_FILE;
412+
413+
///
414+
alias _IO_FILE _iobuf; // needed for phobos
415+
///
416+
alias shared(_IO_FILE) FILE;
417+
}
386418
else version( Darwin )
387419
{
388420
///
@@ -917,6 +949,24 @@ else version( CRuntime_Bionic )
917949
///
918950
shared stderr = &__sF[2];
919951
}
952+
else version( CRuntime_Musl )
953+
{
954+
// needs tail const
955+
extern shared FILE* stdin;
956+
///
957+
extern shared FILE* stdout;
958+
///
959+
extern shared FILE* stderr;
960+
enum
961+
{
962+
///
963+
_IOFBF = 0,
964+
///
965+
_IOLBF = 1,
966+
///
967+
_IONBF = 2,
968+
}
969+
}
920970
else
921971
{
922972
static assert( false, "Unsupported platform" );
@@ -1416,6 +1466,30 @@ else version( CRuntime_Bionic )
14161466
///
14171467
int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
14181468
}
1469+
else version( CRuntime_Musl )
1470+
{
1471+
import core.sys.posix.sys.types : off_t;
1472+
///
1473+
int fseeko(FILE *, off_t, int);
1474+
@trusted
1475+
{
1476+
///
1477+
void rewind(FILE* stream);
1478+
///
1479+
pure void clearerr(FILE* stream);
1480+
///
1481+
pure int feof(FILE* stream);
1482+
///
1483+
pure int ferror(FILE* stream);
1484+
///
1485+
int fileno(FILE *);
1486+
}
1487+
1488+
///
1489+
int snprintf(scope char* s, size_t n, scope const char* format, ...);
1490+
///
1491+
int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg);
1492+
}
14191493
else
14201494
{
14211495
static assert( false, "Unsupported platform" );

0 commit comments

Comments
 (0)