Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created November 6, 2013 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FROGGS/d245bd7f983e0b5c138f to your computer and use it in GitHub Desktop.
Save FROGGS/d245bd7f983e0b5c138f to your computer and use it in GitHub Desktop.
diff --git a/3rdparty/dyncall b/3rdparty/dyncall
--- a/3rdparty/dyncall
+++ b/3rdparty/dyncall
@@ -1 +1 @@
-Subproject commit a9e6eec70785f43f63ef17189fc2733d4ceb8446
+Subproject commit a9e6eec70785f43f63ef17189fc2733d4ceb8446-dirty
diff --git a/src/6model/reprs/MVMOSHandle.c b/src/6model/reprs/MVMOSHandle.c
index 2d31e77..e309365 100644
--- a/src/6model/reprs/MVMOSHandle.c
+++ b/src/6model/reprs/MVMOSHandle.c
@@ -39,15 +39,6 @@ static void gc_free(MVMThreadContext *tc, MVMObject *obj) {
case MVM_OSHANDLE_UNINIT:
break;
case MVM_OSHANDLE_HANDLE:
- if (!uv_is_closing(handle->body.u.handle)) {
- int do_shutdown = handle->body.u.handle->type == UV_NAMED_PIPE &&
- uv_is_writable((uv_stream_t*)(handle->body.u.handle));
-
- if (!do_shutdown) {
- uv_close(handle->body.u.handle, NULL);
- uv_run(tc->loop, UV_RUN_DEFAULT);
- }
- }
break;
case MVM_OSHANDLE_FD:
break;
diff --git a/src/core/instance.h b/src/core/instance.h
index 2f7b426..9f873d8 100644
--- a/src/core/instance.h
+++ b/src/core/instance.h
@@ -180,4 +180,8 @@ struct MVMInstance {
/* Hash of filenames of compunits loaded from disk. */
MVMLoadedCompUnitName *loaded_compunits;
uv_mutex_t mutex_loaded_compunits;
+
+ MVMObject *stdin;
+ MVMObject *stdout;
+ MVMObject *stderr;
};
diff --git a/src/io/fileops.c b/src/io/fileops.c
index d841174..a6e4997 100644
--- a/src/io/fileops.c
+++ b/src/io/fileops.c
@@ -472,11 +472,6 @@ MVMString * MVM_file_slurp(MVMThreadContext *tc, MVMString *filename, MVMString
return result;
}
-static void write_cb(uv_write_t* req, int status) {
- uv_unref((uv_handle_t *)req);
- free(req);
-}
-
/* writes a string to a filehandle. */
MVMint64 MVM_file_write_fhs(MVMThreadContext *tc, MVMObject *oshandle, MVMString *str, MVMint8 addnl) {
MVMOSHandle *handle;
@@ -499,7 +494,7 @@ MVMint64 MVM_file_write_fhs(MVMThreadContext *tc, MVMObject *oshandle, MVMString
uv_buf_t buf = uv_buf_init(output, bytes_written = output_size);
int r;
- if ((r = uv_write(req, (uv_stream_t *)handle->body.u.handle, &buf, 1, write_cb)) < 0) {
+ if ((r = uv_write(req, (uv_stream_t *)handle->body.u.handle, &buf, 1, NULL)) < 0) {
free(req);
free(output);
MVM_exception_throw_adhoc(tc, "Failed to write bytes to filehandle: %s", uv_strerror(r));
@@ -731,15 +726,21 @@ MVMint64 MVM_file_eof(MVMThreadContext *tc, MVMObject *oshandle) {
}
MVMObject * MVM_file_get_stdin(MVMThreadContext *tc) {
- return MVM_file_get_stdstream(tc, 0, 1);
+ return tc->instance->stdin
+ ? tc->instance->stdin
+ : MVM_file_get_stdstream(tc, 0, 1);
}
MVMObject * MVM_file_get_stdout(MVMThreadContext *tc) {
- return MVM_file_get_stdstream(tc, 1, 0);
+ return tc->instance->stdout
+ ? tc->instance->stdout
+ : MVM_file_get_stdstream(tc, 1, 0);
}
MVMObject * MVM_file_get_stderr(MVMThreadContext *tc) {
- return MVM_file_get_stdstream(tc, 2, 0);
+ return tc->instance->stderr
+ ? tc->instance->stderr
+ : MVM_file_get_stdstream(tc, 2, 0);
}
void MVM_file_set_encoding(MVMThreadContext *tc, MVMObject *oshandle, MVMString *encoding_name) {
diff --git a/src/moar.c b/src/moar.c
index 7edf990..c33c091 100644
--- a/src/moar.c
+++ b/src/moar.c
@@ -58,6 +58,10 @@ MVMInstance * MVM_vm_create_instance(void) {
/* Bootstrap 6model. It is assumed the GC will not be called during this. */
MVM_6model_bootstrap(instance->main_thread);
+ instance->stdin = MVM_file_get_stdin(instance->main_thread);
+ instance->stdout = MVM_file_get_stdout(instance->main_thread);
+ instance->stderr = MVM_file_get_stderr(instance->main_thread);
+
/* Fix up main thread's usecapture. */
instance->main_thread->cur_usecapture = MVM_repr_alloc_init(instance->main_thread, instance->CallCapture);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment