Skip to content
Snippets Groups Projects
Commit 5cfc1e5d authored by David Hendriks's avatar David Hendriks
Browse files

Synched with master

parent f2793646
No related branches found
No related tags found
No related merge requests found
File deleted
......@@ -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;
}
......@@ -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
......
......@@ -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;
}
......
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