Skip to content
Snippets Groups Projects
Commit b8342867 authored by Izzard, Robert Dr (Maths & Physics)'s avatar Izzard, Robert Dr (Maths & Physics)
Browse files

update for latest API including error_buffer

parent 5aaa5351
No related branches found
No related tags found
No related merge requests found
......@@ -7,11 +7,12 @@ CC := gcc
LD := gcc
PROGRAM := binary_c_python_api
MAKE := /usr/bin/make
LIBS := -lbinary_c `$(BINARY_C)/binary_c-config --libs`
LIBS := -lbinary_c $(shell $(BINARY_C)/binary_c-config --libs)
#`$(BINARY_C)/binary_c-config --libdirs_list`
C_SRC := binary_c_python_api.c
OBJECTS := $(C_SRC:.c=.o)
OBJ_FLAGS := -c
CFLAGS := -fPIC `$(BINARY_C)/binary_c-config --flags` -I$(BINARY_C)/src/ -I$(BINARY_C)/src/API
CFLAGS := -fPIC $(shell $(BINARY_C)/binary_c-config --flags) -I$(BINARY_C)/src/ -I$(BINARY_C)/src/API
SO_FLAGS := -shared -o
SO_NAME := libbinary_c_api.so
......
......@@ -105,7 +105,6 @@ int run_binary(char * argstring,
"%s",
"/dev/null");
stardata->preferences->internal_buffering = 2;
stardata->preferences->internal_buffering_compression = 0;
stardata->preferences->batchmode = BATCHMODE_LIBRARY;
binary_c_evolve_for_dt(stardata,
......
......@@ -176,13 +176,30 @@ static PyObject* binary_c_run_binary(PyObject *self, PyObject *args)
else
{
char * buffer;
int nbytes;
char * error_buffer;
size_t nbytes;
int out MAYBE_UNUSED = run_binary(argstring,
&buffer,
&error_buffer,
&nbytes);
/* copy the buffer to a python string */
PyObject * ret = Py_BuildValue("s", buffer);
free(buffer);
return ret;
PyObject * return_string = Py_BuildValue("s", buffer);
PyObject * return_error_string MAYBE_UNUSED = Py_BuildValue("s", error_buffer);
if(error_buffer != NULL && strlen(error_buffer)>0)
{
fprintf(stderr,
"Error in binary_c run : %s\n",
error_buffer);
}
Safe_free(buffer);
Safe_free(error_buffer);
/*
* TODO
* return the return_error_string as well!
*/
return return_string;
}
}
......@@ -10,8 +10,9 @@
/* Binary_c's python API prototypes */
int run_binary (char * argstring,
char ** outstring,
int * nbytes);
char ** const outstring,
char ** const errorstring,
size_t * const nbytes);
/* C macros */
#define BINARY_C_APITEST_VERSION 0.1
......
......@@ -50,7 +50,7 @@ int stdoutwas;
int main(int argc,
char * argv[])
{
char * argstring = MALLOC(sizeof(char) * (size_t)STRING_LENGTH);
char * argstring = Malloc(sizeof(char) * (size_t)STRING_LENGTH);
snprintf(argstring,
STRING_LENGTH,
"binary_c M_1 %g M_2 %g separation %g orbital_period %g metallicity %g max_evolution_time %g\n",
......@@ -61,10 +61,12 @@ int main(int argc,
0.02,
15000.0);
char * buffer ;
int nbytes;
char * buffer;
char * error_buffer;
size_t nbytes;
int out = run_binary(argstring,
&buffer,
&error_buffer,
&nbytes);
printf("output (binary_c returned %d)\n%s\n",out,buffer);
......@@ -76,8 +78,9 @@ int main(int argc,
int run_binary(char * argstring,
char ** buffer,
int * nbytes)
char ** const buffer,
char ** const error_buffer,
size_t * const nbytes)
{
/* memory for N binary systems */
struct libbinary_c_stardata_t *stardata;
......@@ -91,6 +94,8 @@ int run_binary(char * argstring,
&store,
&argstring,
-1);
printf("have new stardata %p\n",stardata);fflush(NULL);
/* disable logging */
snprintf(stardata->preferences->log_filename,
STRING_LENGTH-1,
......@@ -101,22 +106,25 @@ int run_binary(char * argstring,
"%s",
"/dev/null");
/* output to strings */
stardata->preferences->internal_buffering = 2;
stardata->preferences->internal_buffering_compression = 0;
stardata->preferences->internal_buffering = INTERNAL_BUFFERING_STORE;
stardata->preferences->batchmode = BATCHMODE_LIBRARY;
/* do binary evolution */
binary_c_evolve_for_dt(stardata,
stardata->model.max_evolution_time);
/* get buffer pointer */
binary_c_buffer_info(stardata,buffer,nbytes);
/* get error buffer pointer */
binary_c_error_buffer(stardata,error_buffer);
/* set raw_buffer_size = -1 to prevent it being freed */
stardata->tmpstore->raw_buffer_size = -1;
/* free stardata (except the buffer) */
binary_c_free_memory(&stardata,TRUE,TRUE,FALSE);
binary_c_free_memory(&stardata,TRUE,TRUE,FALSE,FALSE);
binary_c_free_store_contents(store);
return 0;
}
No preview for this file type
......@@ -9,7 +9,7 @@ import sys
binary_c_config = os.environ['BINARY_C']+'/binary_c-config'
binary_c_incdirs = subprocess.run([binary_c_config,'incdirs_list'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
binary_c_libdirs = subprocess.run([binary_c_config,'libdirs'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
binary_c_libdirs = subprocess.run([binary_c_config,'libdirs_list'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
binary_c_cflags = subprocess.run([binary_c_config,'cflags'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
binary_c_libs = subprocess.run([binary_c_config,'libs_list'],stdout=subprocess.PIPE).stdout.decode('utf-8').split()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment