diff --git a/.binary_c_python_api.c.swp b/.binary_c_python_api.c.swp deleted file mode 100644 index df644636b4141ddb926e3f7ddb6072642942ddfa..0000000000000000000000000000000000000000 Binary files a/.binary_c_python_api.c.swp and /dev/null differ diff --git a/binary_c_python.c b/binary_c_python.c index c5cf65d475530899a6cde21276a8d222e5621fc3..e09c5d3ddac9f0a9336c4d23a98d150a170294d0 100644 --- a/binary_c_python.c +++ b/binary_c_python.c @@ -156,6 +156,9 @@ static PyObject* binary_c_new_binary_system(PyObject *self, PyObject *args) static PyObject* binary_c_function_prototype(PyObject *self, PyObject *args) { + + // This function is an very bare example of how a function would look like. + double var1, var2; /* Parse the input tuple */ @@ -224,27 +227,64 @@ static PyObject* binary_c_run_binary_with_log(PyObject *self, PyObject *args) else { char * buffer; - int nbytes; + char * error_buffer; + size_t nbytes; int out MAYBE_UNUSED = run_binary_with_log(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; } } static PyObject* binary_c_return_arglines(PyObject *self, PyObject *args) { - /* Binary structures */ char * buffer; - int nbytes; + char * error_buffer; + size_t nbytes; int out MAYBE_UNUSED = return_arglines(&buffer, - &nbytes); + &error_buffer, + &nbytes); + /* copy the buffer to a python string */ - PyObject * ret = Py_BuildValue("s", buffer); - free(buffer); - /* Return an object containing the arg list */ - 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 29fbf724745e3165dbb0d1eb08dda734f8601e96..04a1a125755038bff0f7c0ab772956fce87a0c35 100644 --- a/binary_c_python.h +++ b/binary_c_python.h @@ -15,11 +15,13 @@ int run_binary (char * argstring, size_t * const nbytes); int run_binary_with_log (char * argstring, - char ** outstring, - int * nbytes); + char ** const outstring, + char ** const errorstring, + size_t * const nbytes); -int return_arglines(char ** buffer, - int * nbytes); +int return_arglines(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 166aa6ee72d19b08477bf7532b481c66b37378c9..d160ef8574d2f7a982c997bb287e8f7e58f55803 100644 --- a/binary_c_python_api.c +++ b/binary_c_python_api.c @@ -94,7 +94,6 @@ int run_binary(char * argstring, &store, &argstring, -1); - printf("have new stardata %p\n",stardata);fflush(NULL); /* disable logging */ snprintf(stardata->preferences->log_filename, @@ -129,8 +128,9 @@ int run_binary(char * argstring, return 0; } -int return_arglines(char ** buffer, - int * nbytes) +int return_arglines(char ** const buffer, + char ** const error_buffer, + size_t * const nbytes) { /* memory for N binary systems */ struct libbinary_c_stardata_t *stardata; @@ -157,8 +157,7 @@ int return_arglines(char ** buffer, "/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; /* List available arguments */ @@ -166,19 +165,24 @@ int return_arglines(char ** buffer, /* 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; } int run_binary_with_log(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; @@ -192,32 +196,26 @@ int run_binary_with_log(char * argstring, &store, &argstring, -1); - /* disable logging */ - // snprintf(stardata->preferences->log_filename, - // STRING_LENGTH-1, - // "%s", - // "/dev/null"); - // snprintf(stardata->preferences->api_log_filename_prefix, - // STRING_LENGTH-1, - // "%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; }