Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,49 @@ jobs:
- name: Test with pytest
run: |
pytest

c-checks:
# Strict C23 compile, then the C library under AddressSanitizer,
# LeakSanitizer and UBSan, both standalone and as loaded by Python.
runs-on: ubuntu-latest
env:
ORBIT_EPHEMERIS: ${{ github.workspace }}/src/mp_ephem/data/binEphem.405_64
ORBIT_OBSERVATORIES: ${{ github.workspace }}/src/mp_ephem/data/observatories.dat
SANITIZE: -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=undefined

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Compile with strict warnings as C23
run: |
gcc --version
for f in orbfit/*.c test/c/*.c; do
gcc -std=gnu2x -Wall -Wextra -Wno-unused-parameter -Werror -Iorbfit -fsyntax-only "$f"
done
- name: Run the C library standalone under sanitizers
env:
ASAN_OPTIONS: detect_leaks=1
UBSAN_OPTIONS: print_stacktrace=1
run: |
gcc -std=gnu2x -g -O1 $SANITIZE -Iorbfit orbfit/*.c test/c/orbfit_driver.c -lm -o orbfit_driver
./orbfit_driver test/data/o3o08.mpc "$RUNNER_TEMP/o3o08.abg" 3
./orbfit_driver test/data/hst.mpc "$RUNNER_TEMP/hst.abg" 2
- name: Build the extension with sanitizers
run: |
python -m pip install --upgrade pip
pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
CFLAGS="-g -O1 $SANITIZE" LDFLAGS="$SANITIZE" pip install --no-cache-dir .
- name: Test with pytest under sanitizers
env:
# Python itself is not built with LeakSanitizer, so only check for memory errors here.
ASAN_OPTIONS: detect_leaks=0
UBSAN_OPTIONS: print_stacktrace=1
run: |
export LD_PRELOAD="$(gcc -print-file-name=libasan.so):$(gcc -print-file-name=libubsan.so)"
pytest test
3 changes: 0 additions & 3 deletions orbfit/aeiderivs.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/* $Id: aeiderivs.c,v 2.0 2001/09/14 19:05:06 garyb Exp $ */

#ifndef lint
static char vcid[] = "$Id: aeiderivs.c,v 2.0 2001/09/14 19:05:06 garyb Exp $";
#endif /* lint */
/* Subroutine to determine partial derivative matrix of orbital params
* w.r.t. barycentric phase space params. Incredible algebra by Bharat.
*/
Expand Down
76 changes: 9 additions & 67 deletions orbfit/dms.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
/* $Id: dms.c,v 1.1 2006/11/22 20:31:50 observe Exp $ */

#ifndef lint
static char vcid[] = "$Id: dms.c,v 1.1 2006/11/22 20:31:50 observe Exp $";
#endif /* lint */
/* convert a string to decimal degrees */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include "orbfit.h"

double
dmsdeg(char *string)
dmsdeg(const char *string)
{
float args[3];
char substring[10];
double args[3];
char substring[32];
int i,iarg,j,sgn;
for (iarg=0;iarg<3;args[iarg++]=0.);

/*strip off leading whitespace and look for - sign*/
for (i=0; isspace( (int) string[i]); i++);
for (i=0; isspace( (unsigned char) string[i]); i++);
if (string[i]=='-') {
sgn = -1;
i++;
Expand All @@ -30,15 +28,14 @@ dmsdeg(char *string)

for (iarg=0; iarg<3; iarg++) {
substring[0] = 0;
j = sscanf(string+i, "%[ :]",substring);
j = sscanf(string+i, "%31[ :]",substring);
if (j==EOF || *(string+i)==0) break; /*failing to get EOF at end*/
i += strlen(substring);
substring[0] = 0;
j = sscanf(string+i,"%[-+.0-9]",substring);
j = sscanf(string+i,"%31[-+.0-9]",substring);
if (j==EOF || *(string+i)==0) break;
else if (j!=1) {
fprintf(stderr,"Error interpeting dms ->%s<-\n",string);
return(0.);
orbfit_fail("Error interpreting dms ->%s<-",string);
}
args[iarg] = atof(substring);
i += strlen(substring);
Expand All @@ -51,63 +48,8 @@ dmsdeg(char *string)

/* slight variation for hours:*/
double
hmsdeg(char *string)
hmsdeg(const char *string)
{
return(15. * dmsdeg(string));
}

void
degdms(double degr,
char *outbuff)
{
int ideg,imin,sign=1;
double sec;

if (degr<0.) {
sign=-1;
degr *= -1.;
}

ideg = floor(degr);
degr = (degr-ideg)*60.;
imin = floor(degr);
sec = (degr-imin)*60.;

if (sign>0)
if (ideg<100)
sprintf(outbuff," +%02d:%02d:%06.3f",ideg,imin,sec);
else
sprintf(outbuff,"+%03d:%02d:%06.3f",ideg,imin,sec);
else
if (ideg<100)
sprintf(outbuff," -%02d:%02d:%06.3f",ideg,imin,sec);
else
sprintf(outbuff,"-%03d:%02d:%06.3f",ideg,imin,sec);
return;
}
void
deghms(double degr,
char *outbuff)
{
int ideg,imin,sign=1;
double sec;

if (degr<0) {
sign=-1;
degr *= -1.;
}

degr /= 15.;
ideg = floor(degr);
degr = (degr-ideg)*60.;
imin = floor(degr);
sec = (degr-imin)*60.;

if (sign>0)
sprintf(outbuff," %02d:%02d:%07.4f",ideg,imin,sec);
else
sprintf(outbuff,"-%02d:%02d:%07.4f",ideg,imin,sec);

return;
}

Loading
Loading