Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
81e0975b
"...composable_kernel_rocm.git" did not exist on "fa9da1a42a2c21403633b958e28da7cb27dfebe9"
Commit
81e0975b
authored
Apr 30, 2016
by
Wenzel Jakob
Browse files
clarified pickle version requirements (fixes #186)
parent
8edfa0c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
docs/advanced.rst
docs/advanced.rst
+9
-7
example/example15.py
example/example15.py
+1
-1
No files found.
docs/advanced.rst
View file @
81e0975b
...
@@ -1340,13 +1340,15 @@ An instance can now be pickled as follows:
...
@@ -1340,13 +1340,15 @@ An instance can now be pickled as follows:
p = Pickleable("test_value")
p = Pickleable("test_value")
p.setExtra(15)
p.setExtra(15)
data = pickle.dumps(p, -1)
data = pickle.dumps(p, 2)
Note that only the cPickle module is supported on Python 2.7. It is also
Note that only the cPickle module is supported on Python 2.7. The second
important to request usage of the highest protocol version using the ``-1``
argument to ``dumps`` is also crucial: it selects the pickle protocol version
argument to ``dumps``. Failure to follow these two steps will lead to important
2, since the older version 1 is not supported. Newer versions are also fine—for
pybind11 memory allocation routines to be skipped during unpickling, which will
instance, specify ``-1`` to always use the latest available version. Beware:
likely cause memory corruption and/or segmentation faults.
failure to follow these instructions will cause important pybind11 memory
allocation routines to be skipped during unpickling, which will likely lead to
memory corruption and/or segmentation faults.
.. seealso::
.. seealso::
...
...
example/example15.py
View file @
81e0975b
...
@@ -14,7 +14,7 @@ p = Pickleable("test_value")
...
@@ -14,7 +14,7 @@ p = Pickleable("test_value")
p
.
setExtra1
(
15
)
p
.
setExtra1
(
15
)
p
.
setExtra2
(
48
)
p
.
setExtra2
(
48
)
data
=
pickle
.
dumps
(
p
,
-
1
)
#
-1 is importan
t
(
use
highest
protocol
version)
data
=
pickle
.
dumps
(
p
,
2
)
#
Mus
t use
pickle
protocol
>= 2
print
(
"%s %i %i"
%
(
p
.
value
(),
p
.
extra1
(),
p
.
extra2
()))
print
(
"%s %i %i"
%
(
p
.
value
(),
p
.
extra1
(),
p
.
extra2
()))
p2
=
pickle
.
loads
(
data
)
p2
=
pickle
.
loads
(
data
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment