Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pinocchio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
pinocchio
Commits
6a7e88f0
Commit
6a7e88f0
authored
6 years ago
by
Guilhem Saurel
Browse files
Options
Downloads
Patches
Plain Diff
Avoid segv in Boost 1.58
Thanks
https://github.com/bchretien/choreonoid/commit/709d7db596f3e9ef4793f944a761fe2a35bca133
parent
75b28a26
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bindings/python/parsers/python/model.cpp
+21
-5
21 additions, 5 deletions
bindings/python/parsers/python/model.cpp
with
21 additions
and
5 deletions
bindings/python/parsers/python/model.cpp
+
21
−
5
View file @
6a7e88f0
...
...
@@ -20,17 +20,23 @@
#include
<iostream>
#include
<Python.h>
#include
<boost/shared_ptr.hpp>
#include
<boost/version.hpp>
// Boost 1.58
#if BOOST_VERSION / 100 % 1000 == 58
#include
<fstream>
#endif
namespace
se3
{
namespace
python
{
namespace
bp
=
boost
::
python
;
Model
buildModel
(
const
std
::
string
&
filename
,
const
std
::
string
&
model_name
,
bool
verbose
)
throw
(
bp
::
error_already_set
)
{
Py_Initialize
();
bp
::
object
main_module
=
bp
::
import
(
"__main__"
);
// Get a dict for the global namespace to exec further python code with
bp
::
dict
globals
=
bp
::
extract
<
bp
::
dict
>
(
main_module
.
attr
(
"__dict__"
));
...
...
@@ -42,13 +48,23 @@ namespace se3
// can update as you want.
try
{
// Boost 1.58
#if BOOST_VERSION / 100 % 1000 == 58
// Avoid a segv with exec_file
// See: https://github.com/boostorg/python/pull/15
std
::
ifstream
t
(
filename
.
c_str
());
std
::
stringstream
buffer
;
buffer
<<
t
.
rdbuf
();
bp
::
exec
(
buffer
.
str
().
c_str
(),
globals
);
#else // default implementation
bp
::
exec_file
((
bp
::
str
)
filename
,
globals
);
#endif
}
catch
(
bp
::
error_already_set
&
e
)
{
PyErr_PrintEx
(
0
);
}
Model
model
;
try
{
...
...
@@ -64,10 +80,10 @@ namespace se3
std
::
cout
<<
"Your model has been built. It has "
<<
model
.
nv
;
std
::
cout
<<
" degrees of freedom."
<<
std
::
endl
;
}
// close interpreter
Py_Finalize
();
return
model
;
}
}
// namespace python
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment