Commit e84ad708 authored by Olivier Lantsoght's avatar Olivier Lantsoght 🏁
Browse files

Merge branch 'Issue243_get_NULL_str_pointer' into 'dev'

Requesting an unset string option does not cause anymore kernel crash

Closes #243

See merge request robotran/mbsysc!394
parents 38f1073d 98cf4921
......@@ -7,11 +7,11 @@ Summary
Defines the functions that are not specific to a MBS analysis.
Modify the C libraries to get a python compatible behavior.
"""
# MBsysC version : 1.13.0
# Author : Robotran Team
# (c) Universite catholique de Louvain, 2019
from __future__ import print_function
import ctypes
import numpy as np
# importing libraries
......@@ -72,6 +72,31 @@ def str_to_bytes(message):
return message
def str_from_c_pointer(address, default_name=None):
"""Read the string at the provided address.
If the address is 'NULL' ('None' in Python), the default name is returned.
Parameters
----------
address : int
Value of the address.
default_name : str, optional
The default name to return if the adress is invalid (None).
The default is None.
Returns
-------
str
The string at the address, or the default name.
"""
if address is not None:
return bytes_to_str(ctypes.string_at(address))
else:
return str(default_name)
def set_output(value, label):
"""Save a value during time integration.
......
......@@ -9,7 +9,6 @@ class has the functions required to manipulate the direct dynamic module. This
includes setting the options, running an(or multiple) analysis and freeing the
memory.
"""
# MBsysC version: 1.13.0
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2019
......@@ -19,6 +18,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_warning
......@@ -733,15 +733,17 @@ class MbsDirdyn(object):
elif key == "save2file":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.save2file)
elif key == "resfilename":
ptr = self.mbs_dirdyn_ptr.contents.options.contents.resfilename
if ptr is not None:
options.append(bytes_to_str(ctypes.string_at(self.mbs_dirdyn_ptr.contents.options.contents.resfilename)))
else:
options.append("dirdyn")
address = self.mbs_dirdyn_ptr.contents.options.contents.resfilename
defaut = "dirdyn"
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_dirdyn_ptr.contents.options.contents.respath)))
address = self.mbs_dirdyn_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_dirdyn_ptr.contents.options.contents.animpath)))
address = self.mbs_dirdyn_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_dirdyn_ptr.contents.options.contents.save_anim)
elif key == "save_visu":
......
......@@ -18,6 +18,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -801,11 +802,17 @@ class MbsEquil(object):
elif key == "lpk_lintol":
options.append(self.mbs_equil_ptr.contents.options.contents.lpk_lintol)
elif key == "resfilename":
options.append(bytes_to_str(ctypes.string_at(self.mbs_equil_ptr.contents.options.contents.resfilename)))
address = self.mbs_equil_ptr.contents.options.contents.resfilename
defaut = 'equil'
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_equil_ptr.contents.options.contents.respath)))
address = self.mbs_equil_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_equil_ptr.contents.options.contents.animpath)))
address = self.mbs_equil_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "mode":
options.append(self.mbs_equil_ptr.contents.options.contents.mode)
elif key == "relax":
......
......@@ -19,6 +19,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -499,11 +500,17 @@ class MbsInvdyn(object):
elif self.mbs_invdyn_ptr.contents.options.contents.motion == 2:
options.append("trajectory")
elif key == "trajectoryqname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.trajectoryqname)))
address = self.mbs_invdyn_ptr.contents.options.contents.trajectoryqname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqdname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.trajectoryqdname)))
address = self.mbs_invdyn_ptr.contents.options.contents.trajectoryqdname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqddname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.trajectoryqddname)))
address = self.mbs_invdyn_ptr.contents.options.contents.trajectoryqddname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "t0":
options.append(self.mbs_invdyn_ptr.contents.options.contents.t0)
elif key == "tf":
......@@ -513,21 +520,17 @@ class MbsInvdyn(object):
elif key == "save2file":
options.append(self.mbs_invdyn_ptr.contents.options.contents.save2file)
elif key == "resfilename":
if self.mbs_invdyn_ptr.contents.options.contents.resfilename is None:
mbs_msg(">>" + self.module_name + ">> The option " + key + " is not assigned")
else:
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.resfilename)))
address = self.mbs_invdyn_ptr.contents.options.contents.resfilename
defaut = 'invdyn'
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
if self.mbs_invdyn_ptr.contents.options.contents.respath is None:
mbs_msg(">>" + self.module_name + ">> The option " + key + " is not assigned")
else:
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.respath)))
address = self.mbs_invdyn_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
if self.mbs_invdyn_ptr.contents.options.contents.animpath is None:
mbs_msg(">>" + self.module_name + ">> The option " + key + " is not assigned")
else:
options.append(bytes_to_str(ctypes.string_at(self.mbs_invdyn_ptr.contents.options.contents.animpath)))
address = self.mbs_invdyn_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_invdyn_ptr.contents.options.contents.save_anim)
elif key == "framerate":
......
......@@ -9,12 +9,14 @@ class has the functions required to manipulate the direct modal analysis module.
This includes setting the options, running an(or multiple) analysis and freeing
the memory.
"""
# Author: Robotran Team
# (c) Universite catholique de Louvain, 2021
import os
import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -419,11 +421,17 @@ class MbsModal(object):
if key == "save2file":
options.append(self.mbs_modal_ptr.contents.options.contents.save2file)
elif key == "resfilename":
options.append(bytes_to_str(ctypes.string_at(self.mbs_modal_ptr.contents.options.contents.resfilename)))
address = self.mbs_modal_ptr.contents.options.contents.resfilename
defaut = "modal"
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_modal_ptr.contents.options.contents.respath)))
address = self.mbs_modal_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_modal_ptr.contents.options.contents.animpath)))
address = self.mbs_modal_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_modal_ptr.contents.options.contents.save_anim)
elif key == "save_mat":
......
......@@ -19,6 +19,7 @@ import ctypes
import numpy as np
# importing MbsysPy functions
from ..mbs_utilities import str_from_c_pointer
from ..mbs_utilities import bytes_to_str
from ..mbs_utilities import str_to_bytes
from ..mbs_utilities import mbs_msg
......@@ -450,11 +451,17 @@ class MbsSolvekin(MbsInvdyn):
elif self.mbs_solvekin_ptr.contents.options.contents.motion == 2:
options.append("trajectory")
elif key == "trajectoryqname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.trajectoryqname)))
address = self.mbs_solvekin_ptr.contents.options.contents.trajectoryqname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqdname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.trajectoryqdname)))
address = self.mbs_solvekin_ptr.contents.options.contents.trajectoryqdname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "trajectoryqddname":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.trajectoryqddname)))
address = self.mbs_solvekin_ptr.contents.options.contents.trajectoryqddname
defaut = None
options.append(str_from_c_pointer(address, defaut))
elif key == "t0":
options.append(self.mbs_solvekin_ptr.contents.options.contents.t0)
elif key == "tf":
......@@ -464,11 +471,17 @@ class MbsSolvekin(MbsInvdyn):
elif key == "save2file":
options.append(self.mbs_solvekin_ptr.contents.options.contents.save2file)
elif key == "resfilename":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.resfilename)))
address = self.mbs_solvekin_ptr.contents.options.contents.resfilename
defaut = 'solvekin'
options.append(str_from_c_pointer(address, defaut))
elif key == "respath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.respath)))
address = self.mbs_solvekin_ptr.contents.options.contents.respath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'resultsR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "animpath":
options.append(bytes_to_str(ctypes.string_at(self.mbs_solvekin_ptr.contents.options.contents.animpath)))
address = self.mbs_solvekin_ptr.contents.options.contents.animpath
defaut = os.path.abspath(os.path.join(self.mbs.project_path, 'animationR'))
options.append(str_from_c_pointer(address, defaut))
elif key == "save_anim":
options.append(self.mbs_solvekin_ptr.contents.options.contents.save_anim)
elif key == "framerate":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment