File tree 2 files changed +10
-8
lines changed
2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -1340,13 +1340,15 @@ An instance can now be pickled as follows:
1340
1340
1341
1341
p = Pickleable(" test_value" )
1342
1342
p.setExtra(15 )
1343
- data = pickle.dumps(p, - 1 )
1344
-
1345
- Note that only the cPickle module is supported on Python 2.7. It is also
1346
- important to request usage of the highest protocol version using the ``-1 ``
1347
- argument to ``dumps ``. Failure to follow these two steps will lead to important
1348
- pybind11 memory allocation routines to be skipped during unpickling, which will
1349
- likely cause memory corruption and/or segmentation faults.
1343
+ data = pickle.dumps(p, 2 )
1344
+
1345
+ Note that only the cPickle module is supported on Python 2.7. The second
1346
+ argument to ``dumps `` is also crucial: it selects the pickle protocol version
1347
+ 2, since the older version 1 is not supported. Newer versions are also fine—for
1348
+ instance, specify ``-1 `` to always use the latest available version. Beware:
1349
+ failure to follow these instructions will cause important pybind11 memory
1350
+ allocation routines to be skipped during unpickling, which will likely lead to
1351
+ memory corruption and/or segmentation faults.
1350
1352
1351
1353
.. seealso ::
1352
1354
Original file line number Diff line number Diff line change 14
14
p .setExtra1 (15 )
15
15
p .setExtra2 (48 )
16
16
17
- data = pickle .dumps (p , - 1 ) # -1 is important ( use highest protocol version)
17
+ data = pickle .dumps (p , 2 ) # Must use pickle protocol >= 2
18
18
print ("%s %i %i" % (p .value (), p .extra1 (), p .extra2 ()))
19
19
20
20
p2 = pickle .loads (data )
You can’t perform that action at this time.
0 commit comments