Loading Makefile +17 −8 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ endif # Name of program PROGRAM := binary_c_python_api SRC_DIR := src OBJ_DIR := obj # some commands CC := gcc LD := gcc Loading @@ -20,28 +23,32 @@ LIBS := -lbinary_c $(shell $(BINARY_C)/binary_c-config --libs) # Source files and cflags C_SRC := binary_c_python_api.c CFLAGS := -fPIC $(shell $(BINARY_C)/binary_c-config --flags | sed s/-fvisibility=hidden// ) C_SRC_NEW := src/binary_c_python_api.c # SRC = $(wildcard $(SRC_DIR)/binary_c_python_api.c) # OBJECTS = $(C_SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) # Incdirs INCDIRS := -I$(BINARY_C)/src/ -I$(BINARY_C)/src/API INCDIRS := -I$(BINARY_C)/src/ -I$(BINARY_C)/src/API -Iinclude/ # Object files and flags OBJECTS := $(C_SRC:.c=.o) OBJ_FLAGS := -c OBJ_NEW := $(C_SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) # Shared lib files and flags SO_NAME := libbinary_c_api.so SO_FLAGS := -shared -o SO_FLAGS := -shared # To create python shared library PY_EXEC := python3 PY_SETUP := setup.py PY_OPTIONS := build_ext --inplace all: $(CC) -DBINARY_C=$(BINARY_C) $(CFLAGS) $(INCDIRS) $(C_SRC) $(OBJ_FLAGS) $(LIBS) $(CC) -DBINARY_C=$(BINARY_C) $(SO_FLAGS) $(SO_NAME) $(OBJECTS) $(PY_EXEC) $(PY_SETUP) $(PY_OPTIONS) $(CC) -DBINARY_C=$(BINARY_C) $(CFLAGS) $(INCDIRS) $(C_SRC) -o $(OBJECTS) $(OBJ_FLAGS) $(LIBS) $(CC) -DBINARY_C=$(BINARY_C) $(SO_FLAGS) -o $(SO_NAME) $(OBJECTS) # $(PY_EXEC) $(PY_SETUP) $(PY_OPTIONS) test: @echo Objects: $(OBJECTS) Loading @@ -49,7 +56,9 @@ test: @echo C_SRC: $(C_SRC) @echo CFLAGS: $(CFLAGS) @echo INCDIRS: $(INCDIRS) @echo OBJS_NEW: $(OBJ_NEW) clean: rm -f *.o *.so rm -rf build/ $(RM) -f *.o *.so $(RM) -r build/ No newline at end of file binary_c_python.h→include/binary_c_python.h +0 −0 File moved. View file setup.py +1 −0 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ setup( include_dirs=[ os.environ["BINARY_C"] + "/src", os.environ["BINARY_C"] + "/src/API", 'include', ] + binary_c_incdirs, library_dirs=[os.environ["BINARY_C"] + "/src", "./"] + binary_c_libdirs, Loading src/binary_c_python_api.c 0 → 100644 +242 −0 Original line number Diff line number Diff line #include "binary_c_python.h" #include <time.h> #include <sys/timeb.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> /* * apitest * * Short test programme to throw random binary systems at binary_c's * library via its API. * * Note that it looks more complicated than it is because I have included * code to capture binary_c's stdout stream and output it here. * * This code sends output to stderr : you should use apitest.sh to run it * and hence force output to your terminal's stdout. * * Output lines: * * APITEST .... is information about what this code is doing. * STATUS .... is information about the binary system. * BINARY_C .... is output from binary_c (see iterate_logging.c etc.) * which would have gone to stdout * * If you define the NO_OUTPUT macro, there will be no output except * the memory allocation and test system information. This is useful for speed tests, * but note that you may end up in a race condition where the pipe which replaces * stdout's buffer fills and hence the code stops. * * Note: * I have tested this with gcc 4.7.2 (Ubuntu 12.10) only. */ // #define _CAPTURE #ifdef _CAPTURE static void show_stdout(void); static void capture_stdout(void); #endif /* global variables */ int out_pipe[2]; int stdoutwas; int run_binary(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* memory for N binary systems */ struct libbinary_c_stardata_t *stardata; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, NULL, NULL, &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 = 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,FALSE); binary_c_free_store_contents(store); return 0; } int run_binary_custom_logging(char * argstring, long int func_memaddr, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* memory for N binary systems */ struct libbinary_c_stardata_t *stardata; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, NULL, NULL, &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 = INTERNAL_BUFFERING_STORE; stardata->preferences->batchmode = BATCHMODE_LIBRARY; stardata->preferences->custom_output_function = (void*)(struct stardata_t *)func_memaddr; /* 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,FALSE); binary_c_free_store_contents(store); return 0; } 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; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; char * empty_str = ""; binary_c_new_system(&stardata, NULL, NULL, &store, &empty_str, -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 = INTERNAL_BUFFERING_STORE; stardata->preferences->batchmode = BATCHMODE_LIBRARY; /* List available arguments */ binary_c_list_args(stardata); /* 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,FALSE); binary_c_free_store_contents(store); return 0; } int run_binary_with_logfile(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* memory for N binary systems */ struct libbinary_c_stardata_t *stardata; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, NULL, NULL, &store, &argstring, -1); /* output to strings */ 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,FALSE); binary_c_free_store_contents(store); return 0; } No newline at end of file Loading
Makefile +17 −8 Original line number Diff line number Diff line Loading @@ -9,6 +9,9 @@ endif # Name of program PROGRAM := binary_c_python_api SRC_DIR := src OBJ_DIR := obj # some commands CC := gcc LD := gcc Loading @@ -20,28 +23,32 @@ LIBS := -lbinary_c $(shell $(BINARY_C)/binary_c-config --libs) # Source files and cflags C_SRC := binary_c_python_api.c CFLAGS := -fPIC $(shell $(BINARY_C)/binary_c-config --flags | sed s/-fvisibility=hidden// ) C_SRC_NEW := src/binary_c_python_api.c # SRC = $(wildcard $(SRC_DIR)/binary_c_python_api.c) # OBJECTS = $(C_SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) # Incdirs INCDIRS := -I$(BINARY_C)/src/ -I$(BINARY_C)/src/API INCDIRS := -I$(BINARY_C)/src/ -I$(BINARY_C)/src/API -Iinclude/ # Object files and flags OBJECTS := $(C_SRC:.c=.o) OBJ_FLAGS := -c OBJ_NEW := $(C_SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) # Shared lib files and flags SO_NAME := libbinary_c_api.so SO_FLAGS := -shared -o SO_FLAGS := -shared # To create python shared library PY_EXEC := python3 PY_SETUP := setup.py PY_OPTIONS := build_ext --inplace all: $(CC) -DBINARY_C=$(BINARY_C) $(CFLAGS) $(INCDIRS) $(C_SRC) $(OBJ_FLAGS) $(LIBS) $(CC) -DBINARY_C=$(BINARY_C) $(SO_FLAGS) $(SO_NAME) $(OBJECTS) $(PY_EXEC) $(PY_SETUP) $(PY_OPTIONS) $(CC) -DBINARY_C=$(BINARY_C) $(CFLAGS) $(INCDIRS) $(C_SRC) -o $(OBJECTS) $(OBJ_FLAGS) $(LIBS) $(CC) -DBINARY_C=$(BINARY_C) $(SO_FLAGS) -o $(SO_NAME) $(OBJECTS) # $(PY_EXEC) $(PY_SETUP) $(PY_OPTIONS) test: @echo Objects: $(OBJECTS) Loading @@ -49,7 +56,9 @@ test: @echo C_SRC: $(C_SRC) @echo CFLAGS: $(CFLAGS) @echo INCDIRS: $(INCDIRS) @echo OBJS_NEW: $(OBJ_NEW) clean: rm -f *.o *.so rm -rf build/ $(RM) -f *.o *.so $(RM) -r build/ No newline at end of file
setup.py +1 −0 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ setup( include_dirs=[ os.environ["BINARY_C"] + "/src", os.environ["BINARY_C"] + "/src/API", 'include', ] + binary_c_incdirs, library_dirs=[os.environ["BINARY_C"] + "/src", "./"] + binary_c_libdirs, Loading
src/binary_c_python_api.c 0 → 100644 +242 −0 Original line number Diff line number Diff line #include "binary_c_python.h" #include <time.h> #include <sys/timeb.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> /* * apitest * * Short test programme to throw random binary systems at binary_c's * library via its API. * * Note that it looks more complicated than it is because I have included * code to capture binary_c's stdout stream and output it here. * * This code sends output to stderr : you should use apitest.sh to run it * and hence force output to your terminal's stdout. * * Output lines: * * APITEST .... is information about what this code is doing. * STATUS .... is information about the binary system. * BINARY_C .... is output from binary_c (see iterate_logging.c etc.) * which would have gone to stdout * * If you define the NO_OUTPUT macro, there will be no output except * the memory allocation and test system information. This is useful for speed tests, * but note that you may end up in a race condition where the pipe which replaces * stdout's buffer fills and hence the code stops. * * Note: * I have tested this with gcc 4.7.2 (Ubuntu 12.10) only. */ // #define _CAPTURE #ifdef _CAPTURE static void show_stdout(void); static void capture_stdout(void); #endif /* global variables */ int out_pipe[2]; int stdoutwas; int run_binary(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* memory for N binary systems */ struct libbinary_c_stardata_t *stardata; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, NULL, NULL, &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 = 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,FALSE); binary_c_free_store_contents(store); return 0; } int run_binary_custom_logging(char * argstring, long int func_memaddr, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* memory for N binary systems */ struct libbinary_c_stardata_t *stardata; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, NULL, NULL, &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 = INTERNAL_BUFFERING_STORE; stardata->preferences->batchmode = BATCHMODE_LIBRARY; stardata->preferences->custom_output_function = (void*)(struct stardata_t *)func_memaddr; /* 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,FALSE); binary_c_free_store_contents(store); return 0; } 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; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; char * empty_str = ""; binary_c_new_system(&stardata, NULL, NULL, &store, &empty_str, -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 = INTERNAL_BUFFERING_STORE; stardata->preferences->batchmode = BATCHMODE_LIBRARY; /* List available arguments */ binary_c_list_args(stardata); /* 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,FALSE); binary_c_free_store_contents(store); return 0; } int run_binary_with_logfile(char * argstring, char ** const buffer, char ** const error_buffer, size_t * const nbytes) { /* memory for N binary systems */ struct libbinary_c_stardata_t *stardata; struct libbinary_c_store_t * store = NULL; /* make new stardata */ stardata = NULL; binary_c_new_system(&stardata, NULL, NULL, &store, &argstring, -1); /* output to strings */ 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,FALSE); binary_c_free_store_contents(store); return 0; } No newline at end of file