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

added functinality to write the shared libs to a tempdir and moved stuff into testing

parent 7adea668
No related branches found
No related tags found
No related merge requests found
...@@ -150,7 +150,8 @@ That went very deep haha. alot of memory allocation stuff ...@@ -150,7 +150,8 @@ That went very deep haha. alot of memory allocation stuff
*** DONE Make new c function run_binary_with_custom_logging *** DONE Make new c function run_binary_with_custom_logging
CLOSED: [2019-11-08 Fri 21:19] CLOSED: [2019-11-08 Fri 21:19]
*** TODO Put in some new tests in the python test api *** TODO Put in some new tests in the python test api
*** TODO Make sure the sharedlibs get written to the correct directory *** DONE Make sure the sharedlibs get written to the correct directory
CLOSED: [2019-11-10 Sun 00:21]
** General: ** General:
*** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?) *** DONE Get a more reliable way of loading the default values (running a ./tbse echo or something?)
CLOSED: [2019-10-29 Tue 17:44] CLOSED: [2019-10-29 Tue 17:44]
......
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
import textwrap import textwrap
import subprocess import subprocess
import socket import socket
import tempfile
# Functions for the automatic logging of stuff # Functions for the automatic logging of stuff
def autogen_C_logging_code(logging_dict): def autogen_C_logging_code(logging_dict):
...@@ -228,4 +229,20 @@ def compile_shared_lib(code, sourcefile_name, outfile_name): ...@@ -228,4 +229,20 @@ def compile_shared_lib(code, sourcefile_name, outfile_name):
shell=True) shell=True)
if res: if res:
print('Output of compilation command:\n{}'.format(res)) print('Output of compilation command:\n{}'.format(res))
\ No newline at end of file
def temp_custom_logging_dir():
"""
Function to return the path the custom logging library shared object and script will be written to.
Makes use of os.makedirs exist_ok which requires python 3.2+
"""
tmp_dir = tempfile.gettempdir()
path = os.path.join(tmp_dir, 'binary_c_python')
#
os.makedirs(path, exist_ok=True)
return path
\ No newline at end of file
#pragma push_macro("MAX")
#pragma push_macro("MIN")
#undef MAX
#undef MIN
#include "binary_c.h"
// add visibility __attribute__ ((visibility ("default"))) to it
void binary_c_API_function custom_output_function(struct stardata_t * stardata);
void binary_c_API_function custom_output_function(struct stardata_t * stardata)
{
// struct stardata_t * stardata = (struct stardata_t *)x;
Printf("MY_STELLAR_DATA %g %g\n",((double)stardata->model.time),((double)stardata->star[0].mass));
Printf("my_sss2 %g %g\n",((double)stardata->model.time),((double)stardata->star[1].mass));;
}
#undef MAX
#undef MIN
#pragma pop_macro("MIN")
#pragma pop_macro("MAX")
\ No newline at end of file
import ctypes import ctypes
import tempfile
import os
from binaryc_python_utils.custom_logging_functions import autogen_C_logging_code, binary_c_log_code, compile_shared_lib from binaryc_python_utils.custom_logging_functions import autogen_C_logging_code, binary_c_log_code, compile_shared_lib, temp_custom_logging_dir
import binary_c import binary_c
# generate logging lines # generate logging lines
...@@ -12,20 +14,25 @@ logging_line = autogen_C_logging_code( ...@@ -12,20 +14,25 @@ logging_line = autogen_C_logging_code(
) )
# Generate code around logging lines # Generate code around logging lines
created_code = binary_c_log_code(logging_line) custom_logging_code = binary_c_log_code(logging_line)
# #
compile_shared_lib(created_code, sourcefile_name='custom_logging.c', outfile_name='libcustom_logging.so') compile_shared_lib(created_code,
sourcefile_name=os.path.join(temp_custom_logging_dir(), 'custom_logging.c'),
outfile_name=os.path.join(temp_custom_logging_dir(), 'libcustom_logging.so')
)
# Loading library # Loading library
dll1 = ctypes.CDLL('libgslcblas.so', mode=ctypes.RTLD_GLOBAL) dll1 = ctypes.CDLL('libgslcblas.so', mode=ctypes.RTLD_GLOBAL)
dll2 = ctypes.CDLL('libgsl.so', mode=ctypes.RTLD_GLOBAL) dll2 = ctypes.CDLL('libgsl.so', mode=ctypes.RTLD_GLOBAL)
dll3 = ctypes.CDLL('libbinary_c.so', mode=ctypes.RTLD_GLOBAL) dll3 = ctypes.CDLL('libbinary_c.so', mode=ctypes.RTLD_GLOBAL)
libmean = ctypes.CDLL("libcustom_logging.so", mode=1) # loads the shared library libmean = ctypes.CDLL(os.path.join(temp_custom_logging_dir(), 'libcustom_logging.so'),
mode=ctypes.RTLD_GLOBAL) # loads the shared library
# Get memory adress of function. mimicking a pointer # Get memory adress of function. mimicking a pointer
mem = ctypes.cast(libmean.custom_output_function, ctypes.c_void_p).value mem = ctypes.cast(libmean.custom_output_function, ctypes.c_void_p).value
#
m1 = 15.0 # Msun m1 = 15.0 # Msun
m2 = 14.0 # Msun m2 = 14.0 # Msun
separation = 0 # 0 = ignored, use period separation = 0 # 0 = ignored, use period
...@@ -38,7 +45,5 @@ argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g} ...@@ -38,7 +45,5 @@ argstring = "binary_c M_1 {0:g} M_2 {1:g} separation {2:g} orbital_period {3:g}
output = binary_c.run_binary_custom_logging(argstring, mem) output = binary_c.run_binary_custom_logging(argstring, mem)
# output = binary_c.run_binary(argstring) # output = binary_c.run_binary(argstring)
# print ("\n\nBinary_c output:\n\n")
print (output) print (output)
File moved
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