Commit 5e846d51 authored by Stefan Behnel's avatar Stefan Behnel

Prevent VerboseCodeWriter from inserting nul-bytes into the C file by...

Prevent VerboseCodeWriter from inserting nul-bytes into the C file by switching to a more "standard" way of inserting code at a later time.
parent afffee89
...@@ -71,6 +71,7 @@ def embed_position(pos, docstring): ...@@ -71,6 +71,7 @@ def embed_position(pos, docstring):
doc.encoding = encoding doc.encoding = encoding
return doc return doc
def write_func_call(func, codewriter_class): def write_func_call(func, codewriter_class):
def f(*args, **kwds): def f(*args, **kwds):
if len(args) > 1 and isinstance(args[1], codewriter_class): if len(args) > 1 and isinstance(args[1], codewriter_class):
...@@ -81,19 +82,16 @@ def write_func_call(func, codewriter_class): ...@@ -81,19 +82,16 @@ def write_func_call(func, codewriter_class):
' ' * code.call_level, ' ' * code.call_level,
node.__class__.__name__, node.__class__.__name__,
func.__name__, func.__name__,
node.pos[1:]) node.pos[1:],
pristine = code.buffer.stream.tell() )
code.putln(marker) insertion_point = code.insertion_point()
start = code.buffer.stream.tell() start = code.buffer.stream.tell()
code.call_level += 4 code.call_level += 4
res = func(*args, **kwds) res = func(*args, **kwds)
code.call_level -= 4 code.call_level -= 4
if start == code.buffer.stream.tell(): if start != code.buffer.stream.tell():
# no code written => undo writing marker code.putln(marker.replace('->', '<-', 1))
code.buffer.stream.truncate(pristine) insertion_point.putln(marker)
else:
marker = marker.replace('->', '<-', 1)
code.putln(marker)
return res return res
else: else:
return func(*args, **kwds) return func(*args, **kwds)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment