diff --git a/Makefile b/Makefile index a4d3b7d964abb3a389c60fd9160b71d056b24e48..e3625bb5d1b2058cf8ef8c871cb74bc61c00cea6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/binary_c_api.c b/binary_c_api.c index 48e776882d344d9b2bc34710bcdae48e68b8b0a5..487b3989e388353f0ee705bee5477765a99f4f22 100644 --- a/binary_c_api.c +++ b/binary_c_api.c @@ -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, diff --git a/binary_c_python.c b/binary_c_python.c index 7e122d212c46b0c7a7aa85322556b8020ea0b20f..552ad2225029b14ab13f063f602ba364d3e1b28a 100644 --- a/binary_c_python.c +++ b/binary_c_python.c @@ -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; } } diff --git a/binary_c_python.h b/binary_c_python.h index d208a52b3a8a7a55f1513dfc58467bb1950bafae..914b1d4920d2b11de54d11099a6413447dd7534e 100644 --- a/binary_c_python.h +++ b/binary_c_python.h @@ -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 diff --git a/binary_c_python_api.c b/binary_c_python_api.c index 360a449996eaa0f6c04cbf4489ea2803c3e30335..0b4eff2e2ace0ee4f47c3754abc30da8b0e352b4 100644 --- a/binary_c_python_api.c +++ b/binary_c_python_api.c @@ -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; } diff --git a/build/temp.linux-x86_64-3.6/binary_c_python.o b/build/temp.linux-x86_64-3.6/binary_c_python.o index bba02037bc5f94be740eb94c38cedddff2d45a98..b44b0940a5d7e7e3e50b4be5294dae67ed131aa5 100644 Binary files a/build/temp.linux-x86_64-3.6/binary_c_python.o and b/build/temp.linux-x86_64-3.6/binary_c_python.o differ diff --git a/setup.py b/setup.py index 0969ba532482209705f3a60fe43ad315dc664c22..e5e1062595eb77ca48c98e97833dbbcb8522fea3 100644 --- a/setup.py +++ b/setup.py @@ -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()