Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
676a9948
Commit
676a9948
authored
7 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
Removed wrong automatic DECREF while converting PyObject to string.
parent
ad5bcd11
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Core/Tools/PyEmbeddedUtils.cpp
+3
-6
3 additions, 6 deletions
Core/Tools/PyEmbeddedUtils.cpp
Core/Tools/PyEmbeddedUtils.h
+1
-3
1 addition, 3 deletions
Core/Tools/PyEmbeddedUtils.h
Tests/Functional/Python/PyEmbedded/TestCases.cpp
+3
-0
3 additions, 0 deletions
Tests/Functional/Python/PyEmbedded/TestCases.cpp
with
7 additions
and
9 deletions
Core/Tools/PyEmbeddedUtils.cpp
+
3
−
6
View file @
676a9948
...
...
@@ -21,7 +21,7 @@
#include
<iostream>
std
::
string
PyEmbeddedUtils
::
toString
(
PyObject
*
obj
,
bool
decref
)
std
::
string
PyEmbeddedUtils
::
toString
(
PyObject
*
obj
)
{
std
::
string
result
;
#if PY_MAJOR_VERSION >= 3
...
...
@@ -32,9 +32,6 @@ std::string PyEmbeddedUtils::toString(PyObject* obj, bool decref)
result
=
std
::
string
(
PyString_AsString
(
obj
));
#endif
if
(
decref
)
Py_DECREF
(
obj
);
return
result
;
}
...
...
@@ -45,13 +42,13 @@ std::vector<std::string> PyEmbeddedUtils::toVectorString(PyObject* obj)
if
(
PyTuple_Check
(
obj
))
{
for
(
Py_ssize_t
i
=
0
;
i
<
PyTuple_Size
(
obj
);
i
++
)
{
PyObject
*
value
=
PyTuple_GetItem
(
obj
,
i
);
result
.
push_back
(
toString
(
value
,
false
)
);
result
.
push_back
(
toString
(
value
)
);
}
}
else
if
(
PyList_Check
(
obj
))
{
for
(
Py_ssize_t
i
=
0
;
i
<
PyList_Size
(
obj
);
i
++
)
{
PyObject
*
value
=
PyList_GetItem
(
obj
,
i
);
result
.
push_back
(
toString
(
value
,
false
)
);
result
.
push_back
(
toString
(
value
)
);
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
Core/Tools/PyEmbeddedUtils.h
+
1
−
3
View file @
676a9948
...
...
@@ -28,11 +28,9 @@ class MultiLayer;
namespace
PyEmbeddedUtils
{
//! Converts PyObject into string, if possible, or throws exception.
//! @param decref To automatically decrease reference counter after data is processed.
BA_CORE_API_
std
::
string
toString
(
PyObject
*
obj
,
bool
decref
=
true
);
BA_CORE_API_
std
::
string
toString
(
PyObject
*
obj
);
//! Converts PyObject into vector of strings, if possible, or throws exception.
//! @param decref To automatically decrease reference counter after data is processed.
BA_CORE_API_
std
::
vector
<
std
::
string
>
toVectorString
(
PyObject
*
obj
);
//! Converts char to string. In the case of nullptr will return an empty string.
...
...
This diff is collapsed.
Click to expand it.
Tests/Functional/Python/PyEmbedded/TestCases.cpp
+
3
−
0
View file @
676a9948
...
...
@@ -65,6 +65,7 @@ bool ImportNumpy::runTest()
throw
std
::
runtime_error
(
"Can't get a variable"
);
auto
version_string
=
PyEmbeddedUtils
::
toString
(
pvar
);
Py_DECREF
(
pvar
);
std
::
cout
<<
"numpy_version_string="
<<
version_string
<<
std
::
endl
;
Py_Finalize
();
...
...
@@ -104,6 +105,7 @@ bool FunctionCall::runTest()
throw
std
::
runtime_error
(
"Error while calling function"
);
auto
str
=
PyEmbeddedUtils
::
toString
(
result
);
Py_DECREF
(
result
);
Py_Finalize
();
...
...
@@ -237,6 +239,7 @@ bool CompiledFunction::runTest()
// convert the result to a string
PyObject
*
pResultRepr
=
PyObject_Repr
(
pResult
)
;
std
::
string
result
=
PyEmbeddedUtils
::
toString
(
pResultRepr
);
Py_DECREF
(
pResultRepr
);
Py_Finalize
();
...
...
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