Skip to content

Commit

Permalink
Ignore UNIX signal library when compiling on Windows (see #331)
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy committed Feb 16, 2018
1 parent 9fea897 commit 9be405f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
16 changes: 15 additions & 1 deletion galpy/util/bovy_rk.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "signal.h"
#include <bovy_symplecticode.h>
#include <bovy_rk.h>
#ifndef _WIN32
#include "signal.h"
#endif
#define _MAX_STEPCHANGE_POWERTWO 3.
#define _MIN_STEPCHANGE_POWERTWO -3.
#define _MAX_STEPREDUCE 10000.
Expand Down Expand Up @@ -92,10 +94,12 @@ void bovy_rk4(void (*func)(double t, double *q, double *a,
//Integrate the system
double to= *t;
// Handle KeyboardInterrupt gracefully
#ifndef _WIN32
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler= handle_sigint;
sigaction(SIGINT,&action,NULL);
#endif
for (ii=0; ii < (nt-1); ii++){
if ( interrupted ) {
*err= -10;
Expand All @@ -117,8 +121,10 @@ void bovy_rk4(void (*func)(double t, double *q, double *a,
for (kk=0; kk < dim; kk++) *(yn+kk)= *(yn1+kk);
}
// Back to default handler
#ifndef _WIN32
action.sa_handler= SIG_DFL;
sigaction(SIGINT,&action,NULL);
#endif
//Free allocated memory
free(yn);
free(yn1);
Expand Down Expand Up @@ -190,10 +196,12 @@ void bovy_rk6(void (*func)(double t, double *q, double *a,
//Integrate the system
double to= *t;
// Handle KeyboardInterrupt gracefully
#ifndef _WIN32
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler= handle_sigint;
sigaction(SIGINT,&action,NULL);
#endif
for (ii=0; ii < (nt-1); ii++){
if ( interrupted ) {
*err= -10;
Expand All @@ -217,8 +225,10 @@ void bovy_rk6(void (*func)(double t, double *q, double *a,
for (kk=0; kk < dim; kk++) *(yn+kk)= *(yn1+kk);
}
// Back to default handler
#ifndef _WIN32
action.sa_handler= SIG_DFL;
sigaction(SIGINT,&action,NULL);
#endif
//Free allocated memory
free(yn);
free(yn1);
Expand Down Expand Up @@ -510,10 +520,12 @@ void bovy_dopr54(void (*func)(double t, double *q, double *a,
//set up a1
func(to,yn,a1,nargs,potentialArgs);
// Handle KeyboardInterrupt gracefully
#ifndef _WIN32
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler= handle_sigint;
sigaction(SIGINT,&action,NULL);
#endif
for (ii=0; ii < (nt-1); ii++){
if ( interrupted ) {
*err= -10;
Expand All @@ -528,8 +540,10 @@ void bovy_dopr54(void (*func)(double t, double *q, double *a,
result+= dim;
}
// Back to default handler
#ifndef _WIN32
action.sa_handler= SIG_DFL;
sigaction(SIGINT,&action,NULL);
#endif
// Free allocated memory
free(a);
free(a1);
Expand Down
19 changes: 18 additions & 1 deletion galpy/util/bovy_symplecticode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "signal.h"
#include <bovy_symplecticode.h>
#define _MAX_DT_REDUCE 10000.
//CTRL-C only works on UNIX systems with signal library
#ifndef _WIN32
#include "signal.h"
volatile sig_atomic_t interrupted= 0;
void handle_sigint(int signum)
{
interrupted= 1;
}
#else
int interrupted= 0;
#endif
inline void leapfrog_leapq(int dim, double *q,double *p,double dt,double *qn){
int ii;
for (ii=0; ii < dim; ii++) (*qn++)= (*q++) +dt * (*p++);
Expand Down Expand Up @@ -112,10 +117,12 @@ void leapfrog(void (*func)(double t, double *q, double *a,
//Integrate the system
double to= *t;
// Handle KeyboardInterrupt gracefully
#ifndef _WIN32
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler= handle_sigint;
sigaction(SIGINT,&action,NULL);
#endif
for (ii=0; ii < (nt-1); ii++){
if ( interrupted ) {
*err= -10;
Expand Down Expand Up @@ -150,8 +157,10 @@ void leapfrog(void (*func)(double t, double *q, double *a,
result+= 2 * dim;
}
// Back to default handler
#ifndef _WIN32
action.sa_handler= SIG_DFL;
sigaction(SIGINT,&action,NULL);
#endif
//Free allocated memory
free(qo);
free(po);
Expand Down Expand Up @@ -226,10 +235,12 @@ void symplec4(void (*func)(double t, double *q, double *a,
//Integrate the system
double to= *t;
// Handle KeyboardInterrupt gracefully
#ifndef _WIN32
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler= handle_sigint;
sigaction(SIGINT,&action,NULL);
#endif
for (ii=0; ii < (nt-1); ii++){
if ( interrupted ) {
*err= -10;
Expand Down Expand Up @@ -291,8 +302,10 @@ void symplec4(void (*func)(double t, double *q, double *a,
result+= 2 * dim;
}
// Back to default handler
#ifndef _WIN32
action.sa_handler= SIG_DFL;
sigaction(SIGINT,&action,NULL);
#endif
//Free allocated memory
free(qo);
free(po);
Expand Down Expand Up @@ -375,10 +388,12 @@ void symplec6(void (*func)(double t, double *q, double *a,
//Integrate the system
double to= *t;
// Handle KeyboardInterrupt gracefully
#ifndef _WIN32
struct sigaction action;
memset(&action, 0, sizeof(struct sigaction));
action.sa_handler= handle_sigint;
sigaction(SIGINT,&action,NULL);
#endif
for (ii=0; ii < (nt-1); ii++){
if ( interrupted ) {
*err= -10;
Expand Down Expand Up @@ -488,8 +503,10 @@ void symplec6(void (*func)(double t, double *q, double *a,
result+= 2 * dim;
}
// Back to default handler
#ifndef _WIN32
action.sa_handler= SIG_DFL;
sigaction(SIGINT,&action,NULL);
#endif
//Free allocated memory
free(qo);
free(po);
Expand Down
8 changes: 8 additions & 0 deletions galpy/util/bovy_symplecticode.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ POSSIBILITY OF SUCH DAMAGE.
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _WIN32
#include "signal.h"
#endif
#include <galpy_potentials.h>
/*
Global variables
*/
#ifndef _WIN32
extern volatile sig_atomic_t interrupted;
#else
extern int interrupted;
#endif
/*
Function declarations
*/
#ifndef _WIN32
void handle_sigint(int);
#endif
void leapfrog(void (*func)(double, double *, double *,
int, struct potentialArg *),
int,
Expand Down

0 comments on commit 9be405f

Please sign in to comment.