Fix &raw_output and enable_raw_output interpretation of NUL characters

When using a `print` statement to write to a file that has raw output
enabled, NUL characters in string are no longer interpreted into "\0",
no newline is appended afterwards, and each argument to `print` is
written to the file without any additional separation.

(Re)Assigning to identifiers with the &raw_output attribute should also
now correctly apply the attribute to the file value being assigned.

Note that the write_file BiF should already be capable of raw string
data to a file, expect it bypasses the print_hook event.

Addresses #474
This commit is contained in:
Jon Siwek 2011-08-03 10:51:40 -05:00
parent 6c806b0bce
commit 648e1bda26
12 changed files with 108 additions and 21 deletions

View file

@ -277,16 +277,28 @@ Val* PrintStmt::DoExec(val_list* vals, stmt_flow_type& /* flow */) const
bool ph = print_hook && f->IsPrintHookEnabled();
desc_style style = f->IsRawOutput() ? ALTERNATIVE_STYLE : STANDARD_STYLE;
desc_style style = f->IsRawOutput() ? RAW_STYLE : STANDARD_STYLE;
if ( ! (suppress_local_output && ph) )
{
ODesc d(DESC_READABLE, f);
d.SetFlush(0);
d.SetStyle(style);
if ( f->IsRawOutput() )
{
ODesc d(DESC_READABLE);
d.SetFlush(0);
d.SetStyle(style);
PrintVals(&d, vals, offset);
f->Write("\n", 1);
PrintVals(&d, vals, offset);
f->Write(d.Description(), d.Len());
}
else
{
ODesc d(DESC_READABLE, f);
d.SetFlush(0);
d.SetStyle(style);
PrintVals(&d, vals, offset);
f->Write("\n", 1);
}
}
if ( ph )
@ -300,14 +312,14 @@ Val* PrintStmt::DoExec(val_list* vals, stmt_flow_type& /* flow */) const
val_list* vl = new val_list(2);
::Ref(f);
vl->append(new Val(f));
vl->append(new StringVal(d.Description()));
vl->append(new StringVal(d.Len(), d.Description()));
// Note, this doesn't do remote printing.
mgr.Dispatch(new Event(print_hook, vl), true);
}
if ( remote_serializer )
remote_serializer->SendPrintHookEvent(f, d.Description());
remote_serializer->SendPrintHookEvent(f, d.Description(), d.Len());
}
return 0;