Skip to content

Commit

Permalink
handle nonblocking stdout properly for --dump
Browse files Browse the repository at this point in the history
  • Loading branch information
timo committed Mar 14, 2016
1 parent 1e3d2ac commit 4b3baea
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/moar.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,22 @@ void MVM_vm_dump_file(MVMInstance *instance, const char *filename) {
MVMThreadContext *tc = instance->main_thread;
MVMCompUnit *cu = MVM_cu_map_from_file(tc, filename);
char *dump = MVM_bytecode_dump(tc, cu);
size_t dumplen = strlen(dump);
int position = 0;

/* libuv already set up stdout to be nonblocking, but it can very well be
* we encounter EAGAIN (Resource temporarily unavailable), so we need to
* loop over our buffer, which can be quite big.
*
* The CORE.setting.moarvm has - as of writing this - about 32 megs of
* output from dumping.
*/
while (position < dumplen) {
size_t written = write(1, dump + position, dumplen - position);
if (written > 0)
position += written;
}

printf("%s", dump);
MVM_free(dump);
}

Expand Down

0 comments on commit 4b3baea

Please sign in to comment.