Permalink
Browse files

No longer segfault on new versions. This fixes #4

  • Loading branch information...
1 parent 5f3d661 commit 51db6c97e0b0d982322875ef4a5eb1d32f359dd2 @mitsuhiko mitsuhiko committed Jan 11, 2011
Showing with 18 additions and 2 deletions.
  1. +7 −0 CHANGES
  2. +11 −2 jinja2/bccache.py
View
7 CHANGES
@@ -17,6 +17,13 @@ Version 2.6
of attributes.
- scoped blocks not properly treat toplevel assignments and imports.
Previously an import suddenly "disappeared" in a scoped block.
+- automatically detect newer Python interpreter versions before loading code
+ from bytecode caches to prevent segfaults on invalid opcodes. The segfault
+ in earlier Jinja2 versions here was not a Jinja2 bug but a limitation in
+ the underlying Python interpreter. If you notice Jinja2 segfaulting in
+ earlier versions after an upgrade of the Python interpreter you don't have
+ to upgrade, it's enough to flush the bytecode cache. This just no longer
+ makes this necessary, Jinja2 will automatically detect these cases now.
Version 2.5.5
-------------
View
13 jinja2/bccache.py
@@ -15,6 +15,7 @@
:license: BSD.
"""
from os import path, listdir
+import sys
import marshal
import tempfile
import cPickle as pickle
@@ -27,8 +28,16 @@
from jinja2.utils import open_if_exists
-bc_version = 1
-bc_magic = 'j2'.encode('ascii') + pickle.dumps(bc_version, 2)
+bc_version = 2
+
+# magic version used to only change with new jinja versions. With 2.6
+# we change this to also take Python version changes into account. The
+# reason for this is that Python tends to segfault if fed earlier bytecode
+# versions because someone thought it would be a good idea to reuse opcodes
+# or make Python incompatible with earlier versions.
+bc_magic = 'j2'.encode('ascii') + \
+ pickle.dumps(bc_version, 2) + \
+ pickle.dumps((sys.version_info[0] << 24) | sys.version_info[1])
class Bucket(object):

0 comments on commit 51db6c9

Please sign in to comment.