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

Commit

Permalink
Merge pull request #1069 from joakim-noah/versions
Browse files Browse the repository at this point in the history
Clean up unnecessary version(Posix) and version(OS) and try to more narrowly scope catch-all else blocks
  • Loading branch information
MartinNowak committed May 14, 2015
2 parents e840f58 + aeecc90 commit e6f98c1
Show file tree
Hide file tree
Showing 22 changed files with 233 additions and 186 deletions.
2 changes: 1 addition & 1 deletion src/core/cpuid.d
Expand Up @@ -843,7 +843,7 @@ bool hasCPUID()
{
version(D_InlineAsm_X86_64)
return true;
else
else version(D_InlineAsm_X86)
{
uint flags;
asm nothrow @nogc {
Expand Down
4 changes: 2 additions & 2 deletions src/core/runtime.d
Expand Up @@ -493,7 +493,7 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
// mangled function names.
static enum FIRSTFRAME = 5;
}
else
else version( Windows )
{
// NOTE: On Windows, the number of frames to exclude is based on
// whether the exception is user or system-generated, so
Expand Down Expand Up @@ -646,7 +646,7 @@ Throwable.TraceInfo defaultTraceHandler( void* ptr = null )
{
static enum FIRSTFRAME = 4;
}
else
else version (Win32)
{
static enum FIRSTFRAME = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/stdc/config.d
Expand Up @@ -53,7 +53,7 @@ version( Windows )
alias int c_long;
alias uint c_ulong;
}
else
else version( Posix )
{
static if( (void*).sizeof > int.sizeof )
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/stdc/signal.d
Expand Up @@ -48,7 +48,7 @@ version( Posix )
///
enum SIGTERM = 15; // Termination
}
else
else version( Windows )
{
///
enum SIG_ERR = cast(sigfn_t) -1;
Expand Down
2 changes: 1 addition & 1 deletion src/core/stdc/stddef.d
Expand Up @@ -26,7 +26,7 @@ version( Windows )
///
alias wchar wchar_t;
}
else
else version( Posix )
{
///
alias dchar wchar_t;
Expand Down
12 changes: 10 additions & 2 deletions src/core/stdc/string.d
Expand Up @@ -67,12 +67,20 @@ pure char* strstr(in char* s1, in char* s2);
char* strtok(char* s1, in char* s2);
///
char* strerror(int errnum);
version (linux)
version (CRuntime_Glibc)
{
///
const(char)* strerror_r(int errnum, char* buf, size_t buflen);
}
else version (Posix)
else version (OSX)
{
int strerror_r(int errnum, char* buf, size_t buflen);
}
else version (FreeBSD)
{
int strerror_r(int errnum, char* buf, size_t buflen);
}
else version (CRuntime_Bionic)
{
///
int strerror_r(int errnum, char* buf, size_t buflen);
Expand Down
4 changes: 2 additions & 2 deletions src/core/stdc/time.d
Expand Up @@ -38,7 +38,7 @@ version( Windows )
int tm_isdst; /// Daylight Saving Time flag
}
}
else
else version( Posix )
{
///
struct tm
Expand All @@ -61,7 +61,7 @@ version ( Posix )
{
public import core.sys.posix.sys.types : time_t, clock_t;
}
else
else version ( Windows )
{
///
alias c_long time_t;
Expand Down
6 changes: 1 addition & 5 deletions src/core/sync/barrier.d
Expand Up @@ -20,11 +20,7 @@ public import core.sync.exception;
private import core.sync.condition;
private import core.sync.mutex;

version( Win32 )
{
private import core.sys.windows.windows;
}
else version( Posix )
version( Posix )
{
private import core.stdc.errno;
private import core.sys.posix.pthread;
Expand Down
6 changes: 1 addition & 5 deletions src/core/sync/rwmutex.d
Expand Up @@ -21,11 +21,7 @@ private import core.sync.condition;
private import core.sync.mutex;
private import core.memory;

version( Win32 )
{
private import core.sys.windows.windows;
}
else version( Posix )
version( Posix )
{
private import core.sys.posix.pthread;
}
Expand Down
27 changes: 11 additions & 16 deletions src/core/sys/posix/pthread.d
Expand Up @@ -261,17 +261,14 @@ else
static assert(false, "Unsupported platform");
}

version( Posix )
{
int pthread_atfork(void function(), void function(), void function());
int pthread_attr_destroy(pthread_attr_t*);
int pthread_attr_getdetachstate(in pthread_attr_t*, int*);
int pthread_attr_getschedparam(in pthread_attr_t*, sched_param*);
int pthread_attr_init(pthread_attr_t*);
int pthread_attr_setdetachstate(pthread_attr_t*, int);
int pthread_attr_setschedparam(in pthread_attr_t*, sched_param*);
int pthread_cancel(pthread_t);
}
int pthread_atfork(void function(), void function(), void function());
int pthread_attr_destroy(pthread_attr_t*);
int pthread_attr_getdetachstate(in pthread_attr_t*, int*);
int pthread_attr_getschedparam(in pthread_attr_t*, sched_param*);
int pthread_attr_init(pthread_attr_t*);
int pthread_attr_setdetachstate(pthread_attr_t*, int);
int pthread_attr_setschedparam(in pthread_attr_t*, sched_param*);
int pthread_cancel(pthread_t);

version( linux )
{
Expand Down Expand Up @@ -424,15 +421,13 @@ else version( Android )
}
}
}
else version( Posix )
else
{
void pthread_cleanup_push(void function(void*), void*);
void pthread_cleanup_pop(int);
static assert(false, "Unsupported platform");
}

version( Posix )
@nogc
{
@nogc:
int pthread_cond_broadcast(pthread_cond_t*);
int pthread_cond_destroy(pthread_cond_t*);
int pthread_cond_init(in pthread_cond_t*, pthread_condattr_t*) @trusted;
Expand Down
11 changes: 4 additions & 7 deletions src/core/sys/posix/sched.d
Expand Up @@ -120,13 +120,10 @@ else
static assert(false, "Unsupported platform");
}

version( Posix )
{
int sched_getparam(pid_t, sched_param*);
int sched_getscheduler(pid_t);
int sched_setparam(pid_t, in sched_param*);
int sched_setscheduler(pid_t, int, in sched_param*);
}
int sched_getparam(pid_t, sched_param*);
int sched_getscheduler(pid_t);
int sched_setparam(pid_t, in sched_param*);
int sched_setscheduler(pid_t, int, in sched_param*);

//
// Thread (THR)
Expand Down
21 changes: 9 additions & 12 deletions src/core/sys/posix/semaphore.d
Expand Up @@ -108,18 +108,15 @@ else
static assert(false, "Unsupported platform");
}

version( Posix )
{
int sem_close(sem_t*);
int sem_destroy(sem_t*);
int sem_getvalue(sem_t*, int*);
int sem_init(sem_t*, int, uint);
sem_t* sem_open(in char*, int, ...);
int sem_post(sem_t*);
int sem_trywait(sem_t*);
int sem_unlink(in char*);
int sem_wait(sem_t*);
}
int sem_close(sem_t*);
int sem_destroy(sem_t*);
int sem_getvalue(sem_t*, int*);
int sem_init(sem_t*, int, uint);
sem_t* sem_open(in char*, int, ...);
int sem_post(sem_t*);
int sem_trywait(sem_t*);
int sem_unlink(in char*);
int sem_wait(sem_t*);

//
// Timeouts (TMO)
Expand Down
103 changes: 59 additions & 44 deletions src/core/sys/posix/signal.d
Expand Up @@ -82,51 +82,48 @@ int raise(int sig); (defined in core.stdc.signal)

//sig_atomic_t (defined in core.stdc.signal)

version( Posix )
private alias void function(int) sigfn_t;
private alias void function(int, siginfo_t*, void*) sigactfn_t;

// nothrow versions
nothrow @nogc
{
private alias void function(int) sigfn_t;
private alias void function(int, siginfo_t*, void*) sigactfn_t;
private alias void function(int) sigfn_t2;
private alias void function(int, siginfo_t*, void*) sigactfn_t2;
}

// nothrow versions
nothrow @nogc
{
private alias void function(int) sigfn_t2;
private alias void function(int, siginfo_t*, void*) sigactfn_t2;
}
enum
{
SIGEV_SIGNAL,
SIGEV_NONE,
SIGEV_THREAD
}

enum
{
SIGEV_SIGNAL,
SIGEV_NONE,
SIGEV_THREAD
}
union sigval
{
int sival_int;
void* sival_ptr;
}

union sigval
{
int sival_int;
void* sival_ptr;
}
version( Solaris )
{
import core.sys.posix.unistd;
private int _sigrtmin() { return cast(int) sysconf(_SC_SIGRT_MIN); }
private int _sigrtmax() { return cast(int) sysconf(_SC_SIGRT_MAX); }

version( Solaris )
alias _sigrtmin SIGRTMIN;
alias _sigrtmax SIGRTMAX;
}
else version( Posix )
{
private extern (C) nothrow @nogc
{
import core.sys.posix.unistd;
private int _sigrtmin() { return cast(int) sysconf(_SC_SIGRT_MIN); }
private int _sigrtmax() { return cast(int) sysconf(_SC_SIGRT_MAX); }

alias _sigrtmin SIGRTMIN;
alias _sigrtmax SIGRTMAX;
int __libc_current_sigrtmin();
int __libc_current_sigrtmax();
}
else
{
private extern (C) nothrow @nogc
{
int __libc_current_sigrtmin();
int __libc_current_sigrtmax();
}

alias __libc_current_sigrtmin SIGRTMIN;
alias __libc_current_sigrtmax SIGRTMAX;
}
alias __libc_current_sigrtmin SIGRTMIN;
alias __libc_current_sigrtmax SIGRTMAX;
}

version( linux )
Expand Down Expand Up @@ -422,7 +419,29 @@ else
static assert(false, "Unsupported platform");
}

version( FreeBSD )
version( CRuntime_Glibc )
{
struct sigaction_t
{
static if( true /* __USE_POSIX199309 */ )
{
union
{
sigfn_t sa_handler;
sigactfn_t sa_sigaction;
}
}
else
{
sigfn_t sa_handler;
}
sigset_t sa_mask;
int sa_flags;

void function() sa_restorer;
}
}
else version( FreeBSD )
{
struct sigaction_t
{
Expand Down Expand Up @@ -453,7 +472,7 @@ else version (Solaris)
int[2] sa_resv;
}
}
else version (Android)
else version (linux)
{
version (X86)
{
Expand All @@ -475,7 +494,7 @@ else version (Android)
static assert(false, "Architecture not supported.");
}
}
else version( Posix )
else version( OSX )
{
struct sigaction_t
{
Expand All @@ -493,10 +512,6 @@ else version( Posix )
}
sigset_t sa_mask;
int sa_flags;

version( OSX ) {} else {
void function() sa_restorer;
}
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/core/sys/posix/stdio.d
Expand Up @@ -181,7 +181,7 @@ version( linux )
off_t ftello(FILE*);
}
}
else
else version( Posix )
{
int fseeko(FILE*, off_t, int);
off_t ftello(FILE*);
Expand Down

0 comments on commit e6f98c1

Please sign in to comment.