Loading include/binary_c_python.h +5 −1 Original line number Diff line number Diff line Loading @@ -45,11 +45,15 @@ int return_version_info(char ** const outstring, /* =================================================================== */ /* Functions to call other functionality */ /* =================================================================== */ long int return_store(char * argstring, // can we do this without argstring? long int return_store_memaddr(char * argstring, // TODO can we do this without argstring? char ** const buffer, char ** const error_buffer, size_t * const nbytes); long int return_persistent_data_memaddr(char * argstring, // TODO can we do this without argstring? char ** const buffer, char ** const error_buffer, size_t * const nbytes); /* C macros */ #define BINARY_C_APITEST_VERSION 0.1 Loading src/binary_c_python.c +55 −10 Original line number Diff line number Diff line Loading @@ -30,8 +30,7 @@ /* Preparing all the functions of the module */ // Docstrings static char module_docstring[] MAYBE_UNUSED = "This module is a python wrapper around binary_c"; "This module is a python3 wrapper around binary_c"; #ifdef __DEPRECATED static char create_binary_docstring[] = Loading @@ -57,13 +56,15 @@ static char return_version_info_docstring[] = "Return the version information of the used binary_c build"; // other functionality static char return_store_docstring[] = static char return_store_memaddr_docstring[] = "Return the store memory adress that will be passed to run_population"; static char return_persistent_data_memaddr_docstring[] = "Return the store memory adress that will be passed to run_population"; static struct libbinary_c_store_t *store = NULL; /* Initialize pyobjects */ // // Old functions. Can be removed I think #ifdef __DEPRECATED static PyObject* binary_c_create_binary(PyObject *self, PyObject *args); #endif Loading @@ -80,7 +81,9 @@ static PyObject* binary_c_return_help_all_info(PyObject *self, PyObject *args); static PyObject* binary_c_return_version_info(PyObject *self, PyObject *args); // Other function headers static PyObject* binary_c_return_store(PyObject *self, PyObject *args); static PyObject* binary_c_return_store_memaddr(PyObject *self, PyObject *args); static PyObject* binary_c_return_persistent_data_memaddr(PyObject *self, PyObject *args); /* Set the module functions */ Loading @@ -103,7 +106,8 @@ static PyMethodDef module_methods[] = { {"return_help_all", binary_c_return_help_all_info, METH_VARARGS, return_help_all_info_docstring}, {"return_version_info", binary_c_return_version_info, METH_VARARGS, return_version_info_docstring}, {"return_store", binary_c_return_store, METH_VARARGS, return_store_docstring}, {"return_store_memaddr", binary_c_return_store_memaddr, METH_VARARGS, return_store_memaddr_docstring}, {"return_persistent_data_memaddr", binary_c_return_persistent_data_memaddr, METH_VARARGS, return_persistent_data_memaddr_docstring}, {NULL, NULL, 0, NULL} }; Loading Loading @@ -388,8 +392,48 @@ static PyObject* binary_c_return_version_info(PyObject *self, PyObject *args) /* Wrappers to functions that call other functionality */ /* ============================================================================== */ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) static PyObject* binary_c_return_store_memaddr(PyObject *self, PyObject *args) { /* Parse the input tuple */ char *argstring; if(!PyArg_ParseTuple(args, "s", &argstring)) { return NULL; } char * buffer; char * error_buffer; size_t nbytes; long int out MAYBE_UNUSED = return_store_memaddr(argstring, &buffer, &error_buffer, &nbytes); /* copy the buffer to a python string */ PyObject * return_string MAYBE_UNUSED = Py_BuildValue("s", buffer); PyObject * return_error_string MAYBE_UNUSED = Py_BuildValue("s", error_buffer); PyObject * store_memaddr = Py_BuildValue("l", out); printf("store_memaddr: %ld\n", out); 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); return store_memaddr; } static PyObject* binary_c_return_persistent_data_memaddr(PyObject *self, PyObject *args) { /* Python binding that wraps the c function which calls the binary_c api endpoint. */ /* Parse the input tuple */ char *argstring; Loading @@ -401,7 +445,7 @@ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) char * buffer; char * error_buffer; size_t nbytes; long int out MAYBE_UNUSED = return_store(argstring, long int out MAYBE_UNUSED = return_persistent_data_memaddr(argstring, &buffer, &error_buffer, &nbytes); Loading @@ -410,7 +454,8 @@ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) PyObject * return_string MAYBE_UNUSED = Py_BuildValue("s", buffer); PyObject * return_error_string MAYBE_UNUSED = Py_BuildValue("s", error_buffer); PyObject * return_store_memaddr = Py_BuildValue("l", out); PyObject * persistent_data_memaddr = Py_BuildValue("l", out); printf("persistent_data_memaddr: %ld\n", out); if(error_buffer != NULL && strlen(error_buffer)>0) { Loading @@ -422,5 +467,5 @@ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) Safe_free(buffer); Safe_free(error_buffer); return return_store_memaddr; return persistent_data_memaddr; } No newline at end of file src/binary_c_python_api.c +63 −19 Original line number Diff line number Diff line Loading @@ -236,13 +236,11 @@ int return_help_info(char * argstring, binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store TRUE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here ); // Ask rob whether this can be replaced with setting the thing above to true binary_c_free_store_contents(store); return 0; } Loading Loading @@ -284,13 +282,11 @@ int return_help_all_info(char ** const buffer, binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store TRUE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here ); binary_c_free_store_contents(store); return 0; } Loading @@ -310,7 +306,7 @@ int return_version_info(char ** const buffer, NULL, // previous_stardatas NULL, // preferences &store, // store NULL, // persistent_data TODO: see if this use is correct NULL, // persistent_data &empty_str, // argv -1 // argc ); Loading @@ -332,12 +328,11 @@ int return_version_info(char ** const buffer, binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store TRUE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here TRUE // free_persistent ); binary_c_free_store_contents(store); return 0; } Loading @@ -345,7 +340,7 @@ int return_version_info(char ** const buffer, /* Functions to call other functionality */ /* =================================================================== */ long int return_store(char * argstring, long int return_store_memaddr(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) Loading Loading @@ -381,13 +376,62 @@ long int return_store(char * argstring, TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here FALSE, // free_raw_buffer: TODO: possibly we have to do this yes TRUE // free_persistent ); /* convert the pointer */ uintptr_t store_memaddr_int = (uintptr_t)store; // C Version converting ptr to int printf("store is at address: %p\n", (void*)&store); printf("store_memaddr_int: %ld\n", store_memaddr_int); /* Return the memaddr as an int */ return store_memaddr_int; } long int return_persistent_data_memaddr(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* Function to allocate the persistent_data_memaddr */ struct libbinary_c_stardata_t *stardata = NULL; struct libbinary_c_store_t * store = NULL; struct libbinary_c_persistent_data_t * persistent_data = NULL; // TODO: change persistent_data_t to libbinary_c_persistent_data_t /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, // stardata NULL, // previous_stardatas NULL, // preferences &store, // store &persistent_data, // persistent_data &argstring, // argv -1 // argc ); /* get buffer pointer */ binary_c_buffer_info(stardata, buffer, nbytes); /* get error buffer pointer */ binary_c_error_buffer(stardata, error_buffer); /* convert the pointer */ uintptr_t persistent_data_memaddr_int = (uintptr_t)persistent_data; // C Version converting ptr to int printf("persistent_data is at address: %p\n", (void*)&persistent_data); printf("persistent_data_memaddr_int: %lu\n", persistent_data_memaddr_int); /* free stardata (except the buffer) */ binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata TRUE, // free_store FALSE, // free_raw_buffer: TODO: possibly we have to do this yes FALSE // free_persistent ); /* Return the memaddr as an int */ return persistent_data_memaddr_int; } No newline at end of file tests/python_API_test.py +1 −1 Original line number Diff line number Diff line Loading @@ -157,7 +157,7 @@ def test_return_version_info(): # Testing other functions def test_return_store(): output = binary_c_python_api.return_store("") output = binary_c_python_api.return_store_memaddr("") print("function: test_return_store") print("store memory adress:") Loading tests/test_return_persistent_data_memaddr.py 0 → 100644 +17 −0 Original line number Diff line number Diff line import binary_c_python_api import textwrap # Evolution functions def test_return_persistent_data_memaddr(): output = binary_c_python_api.return_persistent_data_memaddr("") print("function: test_run_system") print("Binary_c output:") print(textwrap.indent(str(output), "\t")) #### if __name__ == "__main__": test_return_persistent_data_memaddr() Loading
include/binary_c_python.h +5 −1 Original line number Diff line number Diff line Loading @@ -45,11 +45,15 @@ int return_version_info(char ** const outstring, /* =================================================================== */ /* Functions to call other functionality */ /* =================================================================== */ long int return_store(char * argstring, // can we do this without argstring? long int return_store_memaddr(char * argstring, // TODO can we do this without argstring? char ** const buffer, char ** const error_buffer, size_t * const nbytes); long int return_persistent_data_memaddr(char * argstring, // TODO can we do this without argstring? char ** const buffer, char ** const error_buffer, size_t * const nbytes); /* C macros */ #define BINARY_C_APITEST_VERSION 0.1 Loading
src/binary_c_python.c +55 −10 Original line number Diff line number Diff line Loading @@ -30,8 +30,7 @@ /* Preparing all the functions of the module */ // Docstrings static char module_docstring[] MAYBE_UNUSED = "This module is a python wrapper around binary_c"; "This module is a python3 wrapper around binary_c"; #ifdef __DEPRECATED static char create_binary_docstring[] = Loading @@ -57,13 +56,15 @@ static char return_version_info_docstring[] = "Return the version information of the used binary_c build"; // other functionality static char return_store_docstring[] = static char return_store_memaddr_docstring[] = "Return the store memory adress that will be passed to run_population"; static char return_persistent_data_memaddr_docstring[] = "Return the store memory adress that will be passed to run_population"; static struct libbinary_c_store_t *store = NULL; /* Initialize pyobjects */ // // Old functions. Can be removed I think #ifdef __DEPRECATED static PyObject* binary_c_create_binary(PyObject *self, PyObject *args); #endif Loading @@ -80,7 +81,9 @@ static PyObject* binary_c_return_help_all_info(PyObject *self, PyObject *args); static PyObject* binary_c_return_version_info(PyObject *self, PyObject *args); // Other function headers static PyObject* binary_c_return_store(PyObject *self, PyObject *args); static PyObject* binary_c_return_store_memaddr(PyObject *self, PyObject *args); static PyObject* binary_c_return_persistent_data_memaddr(PyObject *self, PyObject *args); /* Set the module functions */ Loading @@ -103,7 +106,8 @@ static PyMethodDef module_methods[] = { {"return_help_all", binary_c_return_help_all_info, METH_VARARGS, return_help_all_info_docstring}, {"return_version_info", binary_c_return_version_info, METH_VARARGS, return_version_info_docstring}, {"return_store", binary_c_return_store, METH_VARARGS, return_store_docstring}, {"return_store_memaddr", binary_c_return_store_memaddr, METH_VARARGS, return_store_memaddr_docstring}, {"return_persistent_data_memaddr", binary_c_return_persistent_data_memaddr, METH_VARARGS, return_persistent_data_memaddr_docstring}, {NULL, NULL, 0, NULL} }; Loading Loading @@ -388,8 +392,48 @@ static PyObject* binary_c_return_version_info(PyObject *self, PyObject *args) /* Wrappers to functions that call other functionality */ /* ============================================================================== */ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) static PyObject* binary_c_return_store_memaddr(PyObject *self, PyObject *args) { /* Parse the input tuple */ char *argstring; if(!PyArg_ParseTuple(args, "s", &argstring)) { return NULL; } char * buffer; char * error_buffer; size_t nbytes; long int out MAYBE_UNUSED = return_store_memaddr(argstring, &buffer, &error_buffer, &nbytes); /* copy the buffer to a python string */ PyObject * return_string MAYBE_UNUSED = Py_BuildValue("s", buffer); PyObject * return_error_string MAYBE_UNUSED = Py_BuildValue("s", error_buffer); PyObject * store_memaddr = Py_BuildValue("l", out); printf("store_memaddr: %ld\n", out); 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); return store_memaddr; } static PyObject* binary_c_return_persistent_data_memaddr(PyObject *self, PyObject *args) { /* Python binding that wraps the c function which calls the binary_c api endpoint. */ /* Parse the input tuple */ char *argstring; Loading @@ -401,7 +445,7 @@ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) char * buffer; char * error_buffer; size_t nbytes; long int out MAYBE_UNUSED = return_store(argstring, long int out MAYBE_UNUSED = return_persistent_data_memaddr(argstring, &buffer, &error_buffer, &nbytes); Loading @@ -410,7 +454,8 @@ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) PyObject * return_string MAYBE_UNUSED = Py_BuildValue("s", buffer); PyObject * return_error_string MAYBE_UNUSED = Py_BuildValue("s", error_buffer); PyObject * return_store_memaddr = Py_BuildValue("l", out); PyObject * persistent_data_memaddr = Py_BuildValue("l", out); printf("persistent_data_memaddr: %ld\n", out); if(error_buffer != NULL && strlen(error_buffer)>0) { Loading @@ -422,5 +467,5 @@ static PyObject* binary_c_return_store(PyObject *self, PyObject *args) Safe_free(buffer); Safe_free(error_buffer); return return_store_memaddr; return persistent_data_memaddr; } No newline at end of file
src/binary_c_python_api.c +63 −19 Original line number Diff line number Diff line Loading @@ -236,13 +236,11 @@ int return_help_info(char * argstring, binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store TRUE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here ); // Ask rob whether this can be replaced with setting the thing above to true binary_c_free_store_contents(store); return 0; } Loading Loading @@ -284,13 +282,11 @@ int return_help_all_info(char ** const buffer, binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store TRUE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here ); binary_c_free_store_contents(store); return 0; } Loading @@ -310,7 +306,7 @@ int return_version_info(char ** const buffer, NULL, // previous_stardatas NULL, // preferences &store, // store NULL, // persistent_data TODO: see if this use is correct NULL, // persistent_data &empty_str, // argv -1 // argc ); Loading @@ -332,12 +328,11 @@ int return_version_info(char ** const buffer, binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store TRUE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here TRUE // free_persistent ); binary_c_free_store_contents(store); return 0; } Loading @@ -345,7 +340,7 @@ int return_version_info(char ** const buffer, /* Functions to call other functionality */ /* =================================================================== */ long int return_store(char * argstring, long int return_store_memaddr(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) Loading Loading @@ -381,13 +376,62 @@ long int return_store(char * argstring, TRUE, // free_preferences TRUE, // free_stardata FALSE, // free_store FALSE, // free_raw_buffer TRUE // free_persistent TODO: check if this is correct here FALSE, // free_raw_buffer: TODO: possibly we have to do this yes TRUE // free_persistent ); /* convert the pointer */ uintptr_t store_memaddr_int = (uintptr_t)store; // C Version converting ptr to int printf("store is at address: %p\n", (void*)&store); printf("store_memaddr_int: %ld\n", store_memaddr_int); /* Return the memaddr as an int */ return store_memaddr_int; } long int return_persistent_data_memaddr(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* Function to allocate the persistent_data_memaddr */ struct libbinary_c_stardata_t *stardata = NULL; struct libbinary_c_store_t * store = NULL; struct libbinary_c_persistent_data_t * persistent_data = NULL; // TODO: change persistent_data_t to libbinary_c_persistent_data_t /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, // stardata NULL, // previous_stardatas NULL, // preferences &store, // store &persistent_data, // persistent_data &argstring, // argv -1 // argc ); /* get buffer pointer */ binary_c_buffer_info(stardata, buffer, nbytes); /* get error buffer pointer */ binary_c_error_buffer(stardata, error_buffer); /* convert the pointer */ uintptr_t persistent_data_memaddr_int = (uintptr_t)persistent_data; // C Version converting ptr to int printf("persistent_data is at address: %p\n", (void*)&persistent_data); printf("persistent_data_memaddr_int: %lu\n", persistent_data_memaddr_int); /* free stardata (except the buffer) */ binary_c_free_memory(&stardata, // Stardata TRUE, // free_preferences TRUE, // free_stardata TRUE, // free_store FALSE, // free_raw_buffer: TODO: possibly we have to do this yes FALSE // free_persistent ); /* Return the memaddr as an int */ return persistent_data_memaddr_int; } No newline at end of file
tests/python_API_test.py +1 −1 Original line number Diff line number Diff line Loading @@ -157,7 +157,7 @@ def test_return_version_info(): # Testing other functions def test_return_store(): output = binary_c_python_api.return_store("") output = binary_c_python_api.return_store_memaddr("") print("function: test_return_store") print("store memory adress:") Loading
tests/test_return_persistent_data_memaddr.py 0 → 100644 +17 −0 Original line number Diff line number Diff line import binary_c_python_api import textwrap # Evolution functions def test_return_persistent_data_memaddr(): output = binary_c_python_api.return_persistent_data_memaddr("") print("function: test_run_system") print("Binary_c output:") print(textwrap.indent(str(output), "\t")) #### if __name__ == "__main__": test_return_persistent_data_memaddr()