From 63c41198698928aa0c0d785ebd7820958a36adad Mon Sep 17 00:00:00 2001 From: waTeim Date: Sat, 1 Nov 2014 20:05:55 -0400 Subject: [PATCH] Reorganization of headers to prevent the need for exporting libuv definitions to programs that embed Julia. Femto Lisp include changes required discovered by rebuild. changed comment of ios_buffmode to a deletion Moved decl of jl_spawn inside of extern "C" {} --- src/alloc.c | 1 - src/array.c | 1 - src/ast.c | 1 - src/builtins.c | 2 +- src/codegen.cpp | 1 - src/dlload.c | 1 - src/dump.c | 2 +- src/flisp/flisp.c | 1 + src/flisp/iostream.c | 1 + src/flisp/julia_extensions.c | 1 + src/gc.c | 1 - src/gf.c | 1 - src/init.c | 1 - src/interpreter.c | 1 - src/jl_uv.c | 2 +- src/jlapi.c | 2 +- src/jltypes.c | 1 - src/julia.h | 25 +++++++------ src/julia_internal.h | 16 +++++++++ src/module.c | 1 - src/profile.c | 1 - src/support/ios.c | 2 +- src/support/ios.h | 55 ++--------------------------- src/support/ios_internal.h | 68 ++++++++++++++++++++++++++++++++++++ src/sys.c | 2 +- src/task.c | 1 - src/toplevel.c | 1 - 27 files changed, 108 insertions(+), 85 deletions(-) create mode 100644 src/support/ios_internal.h diff --git a/src/alloc.c b/src/alloc.c index 48d4d12ca333e..0be6baa463ec1 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5,7 +5,6 @@ #include #include #include -#include "julia.h" #include "julia_internal.h" #ifdef __cplusplus diff --git a/src/array.c b/src/array.c index ad661ab80dc15..06023bc911d80 100644 --- a/src/array.c +++ b/src/array.c @@ -7,7 +7,6 @@ #ifdef _OS_WINDOWS_ #include #endif -#include "julia.h" #include "julia_internal.h" #ifdef __cplusplus diff --git a/src/ast.c b/src/ast.c index 773193375d40f..04906b0066054 100644 --- a/src/ast.c +++ b/src/ast.c @@ -9,7 +9,6 @@ #ifdef _OS_WINDOWS_ #include #endif -#include "julia.h" #include "julia_internal.h" #include "flisp.h" diff --git a/src/builtins.c b/src/builtins.c index dd987e1ad1bf6..2440dcc0de969 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -24,8 +24,8 @@ #include #endif #include -#include "julia.h" #include "julia_internal.h" +#include "ios_internal.h" #include "builtin_proto.h" #ifdef __cplusplus diff --git a/src/codegen.cpp b/src/codegen.cpp index 359438894951c..33f5fa58e9584 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -144,7 +144,6 @@ #define NOMINMAX #endif -#include "julia.h" #include "julia_internal.h" #include diff --git a/src/dlload.c b/src/dlload.c index 9d5f4602bbe74..7edf3cf1a11eb 100644 --- a/src/dlload.c +++ b/src/dlload.c @@ -5,7 +5,6 @@ #include #include "platform.h" -#include "julia.h" #include "julia_internal.h" #ifdef _OS_WINDOWS_ #include diff --git a/src/dump.c b/src/dump.c index c63e1cfbe2486..e1bbeecf6de5b 100644 --- a/src/dump.c +++ b/src/dump.c @@ -7,8 +7,8 @@ #ifdef _OS_WINDOWS_ #include #endif -#include "julia.h" #include "julia_internal.h" +#include "ios_internal.h" #include "builtin_proto.h" #ifdef __cplusplus diff --git a/src/flisp/flisp.c b/src/flisp/flisp.c index 0f1077250fe8e..99ffd2c69cf37 100644 --- a/src/flisp/flisp.c +++ b/src/flisp/flisp.c @@ -45,6 +45,7 @@ #include "platform.h" #include "libsupport.h" +#include "ios_internal.h" #include "flisp.h" #include "opcodes.h" diff --git a/src/flisp/iostream.c b/src/flisp/iostream.c index 2afd7b211288a..10266910dfe80 100644 --- a/src/flisp/iostream.c +++ b/src/flisp/iostream.c @@ -6,6 +6,7 @@ #include #include #include "flisp.h" +#include "ios_internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/flisp/julia_extensions.c b/src/flisp/julia_extensions.c index 1b3a4bd751ad7..85ec4542dbe22 100644 --- a/src/flisp/julia_extensions.c +++ b/src/flisp/julia_extensions.c @@ -4,6 +4,7 @@ #include #include "flisp.h" #include "mojibake.h" +#include "ios_internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/gc.c b/src/gc.c index 5661e39f674b5..57b5f6401e551 100644 --- a/src/gc.c +++ b/src/gc.c @@ -18,7 +18,6 @@ # include # include #endif -#include "julia.h" #include "julia_internal.h" #ifdef _P64 diff --git a/src/gf.c b/src/gf.c index ee226d9ef3853..b0e3424a7c541 100644 --- a/src/gf.c +++ b/src/gf.c @@ -12,7 +12,6 @@ #ifdef _OS_WINDOWS_ #include #endif -#include "julia.h" #include "julia_internal.h" #ifdef __cplusplus diff --git a/src/init.c b/src/init.c index 44e0cdd58e0bf..09a0c6e955daf 100644 --- a/src/init.c +++ b/src/init.c @@ -34,7 +34,6 @@ #include #endif -#include "julia.h" #include "julia_internal.h" #include diff --git a/src/interpreter.c b/src/interpreter.c index 94cc0bf074d6f..0d0d10fa76e9f 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -4,7 +4,6 @@ #ifdef _OS_WINDOWS_ #include #endif -#include "julia.h" #include "julia_internal.h" #include "builtin_proto.h" diff --git a/src/jl_uv.c b/src/jl_uv.c index 00531415ffc4f..19547a6be4a41 100644 --- a/src/jl_uv.c +++ b/src/jl_uv.c @@ -24,9 +24,9 @@ #include #endif -#include "julia.h" #include "julia_internal.h" #include "support/ios.h" +#include "support/ios_internal.h" #include "uv.h" #ifdef __cplusplus diff --git a/src/jlapi.c b/src/jlapi.c index 2887b0669afac..e701854b856fd 100644 --- a/src/jlapi.c +++ b/src/jlapi.c @@ -9,7 +9,7 @@ #include #include #include -#include "julia.h" +#include "julia_internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/jltypes.c b/src/jltypes.c index 1a3d0f4866d83..e3b0c1c64d9f0 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -10,7 +10,6 @@ #ifdef _OS_WINDOWS_ #include #endif -#include "julia.h" #include "julia_internal.h" #include "builtin_proto.h" diff --git a/src/julia.h b/src/julia.h index 121bdb9823327..0a83e1867fe25 100644 --- a/src/julia.h +++ b/src/julia.h @@ -5,6 +5,18 @@ extern "C" { #endif +#ifndef UV_H +typedef struct uv_stream_s uv_stream_t; +typedef struct uv_async_s uv_async_t; +typedef struct uv_loop_s uv_loop_t; +typedef struct uv_process_s uv_process_t; +typedef struct uv_pipe_s uv_pipe_t; +typedef struct uv_handle_s uv_handle_t; +typedef struct uv_idle_s uv_idle_t; +typedef struct uv_timer_s uv_timer_t; +typedef struct uv_tcp_s uv_tcp_t; +#endif + #include "options.h" #include "libsupport.h" @@ -1244,12 +1256,6 @@ void jl_longjmp(jmp_buf _Buf,int _Value); #define JL_PUTS jl_puts #define JL_WRITE jl_write -DLLEXPORT int jl_spawn(char *name, char **argv, uv_loop_t *loop, - uv_process_t *proc, jl_value_t *julia_struct, - uv_handle_type stdin_type,uv_pipe_t *stdin_pipe, - uv_handle_type stdout_type,uv_pipe_t *stdout_pipe, - uv_handle_type stderr_type,uv_pipe_t *stderr_pipe, - int detach, char **env, char *cwd); DLLEXPORT void jl_run_event_loop(uv_loop_t *loop); DLLEXPORT int jl_run_once(uv_loop_t *loop); DLLEXPORT int jl_process_events(uv_loop_t *loop); @@ -1291,13 +1297,6 @@ DLLEXPORT void *jl_takebuf_raw(ios_t *s); DLLEXPORT jl_value_t *jl_readuntil(ios_t *s, uint8_t delim); DLLEXPORT void jl_free2(void *p, void *hint); -typedef struct { - void *data; - uv_loop_t *loop; - uv_handle_type type; - uv_file file; -} jl_uv_file_t; - DLLEXPORT size_t jl_write(uv_stream_t *stream, const char *str, size_t n); DLLEXPORT int jl_printf(uv_stream_t *s, const char *format, ...); DLLEXPORT int jl_vprintf(uv_stream_t *s, const char *format, va_list args); diff --git a/src/julia_internal.h b/src/julia_internal.h index 70bf87aee6da0..67377e745b797 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -3,11 +3,20 @@ #include "options.h" #include "uv.h" +#include "julia.h" +#include "ios_internal.h" #ifdef __cplusplus extern "C" { #endif +typedef struct { + void *data; + uv_loop_t *loop; + uv_handle_type type; + uv_file file; +} jl_uv_file_t; + STATIC_INLINE jl_value_t *newobj(jl_value_t *type, size_t nfields) { jl_value_t *jv = (jl_value_t*)allocobj((1+nfields) * sizeof(void*)); @@ -139,8 +148,15 @@ extern uv_lib_t *jl_crtdll_handle; extern uv_lib_t *jl_winsock_handle; #endif +DLLEXPORT int jl_spawn(char *name, char **argv, uv_loop_t *loop, + uv_process_t *proc, jl_value_t *julia_struct, + uv_handle_type stdin_type,uv_pipe_t *stdin_pipe, + uv_handle_type stdout_type,uv_pipe_t *stdout_pipe, + uv_handle_type stderr_type,uv_pipe_t *stderr_pipe, + int detach, char **env, char *cwd); #ifdef __cplusplus } + #endif #endif diff --git a/src/module.c b/src/module.c index 9bbc245de74a3..861a010d23f5d 100644 --- a/src/module.c +++ b/src/module.c @@ -2,7 +2,6 @@ modules and top-level bindings */ #include -#include "julia.h" #include "julia_internal.h" #ifdef __cplusplus diff --git a/src/profile.c b/src/profile.c index 67ffe99a272b1..6dc9916e768d3 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1,7 +1,6 @@ #include #include #include -#include "julia.h" #include "julia_internal.h" #ifdef __cplusplus diff --git a/src/support/ios.c b/src/support/ios.c index e70fe902dec0b..41fd3c33509b0 100644 --- a/src/support/ios.c +++ b/src/support/ios.c @@ -25,7 +25,7 @@ #include "utils.h" #include "utf8.h" -#include "ios.h" +#include "ios_internal.h" #include "timefuncs.h" #define MOST_OF(x) ((x) - ((x)>>4)) diff --git a/src/support/ios.h b/src/support/ios.h index d5a72fcc79da5..f40a653e87f3e 100644 --- a/src/support/ios.h +++ b/src/support/ios.h @@ -1,73 +1,25 @@ #ifndef IOS_H #define IOS_H +#include #include -#include "uv.h" #ifdef __cplusplus extern "C" { #endif +typedef struct ios_t ios_t; + // this flag controls when data actually moves out to the underlying I/O // channel. memory streams are a special case of this where the data // never moves out. //make it compatible with UV Handles -typedef enum { bm_none=UV_HANDLE_TYPE_MAX+1, bm_line, bm_block, bm_mem } bufmode_t; typedef enum { bst_none, bst_rd, bst_wr } bufstate_t; #define IOS_INLSIZE 54 #define IOS_BUFSIZE 131072 -typedef struct { - // the state only indicates where the underlying file position is relative - // to the buffer. reading: at the end. writing: at the beginning. - // in general, you can do any operation in any state. - char *buf; // start of buffer - - int errcode; - -#ifdef _P64 - int _pad_bm; // put bm at same offset as type field of uv_stream_s -#endif - bufmode_t bm; // - bufstate_t state; - - off_t maxsize; // space allocated to buffer - off_t size; // length of valid data in buf, >=ndirty - off_t bpos; // current position in buffer - off_t ndirty; // # bytes at &buf[0] that need to be written - - off_t fpos; // cached file pos - size_t lineno; // current line number - - // pointer-size integer to support platforms where it might have - // to be a pointer - long fd; - - unsigned char readable:1; - unsigned char writable:1; - unsigned char ownbuf:1; - unsigned char ownfd:1; - unsigned char _eof:1; - - // this means you can read, seek back, then read the same data - // again any number of times. usually only true for files and strings. - unsigned char rereadable:1; - - // this enables "stenciled writes". you can alternately write and - // seek without flushing in between. this performs read-before-write - // to populate the buffer, so "rereadable" capability is required. - // this is off by default. - //unsigned char stenciled:1; - - // request durable writes (fsync) - // unsigned char durable:1; - - int64_t userdata; - char local[IOS_INLSIZE]; -} ios_t; - /* low-level interface functions */ DLLEXPORT size_t ios_read(ios_t *s, char *dest, size_t n); DLLEXPORT size_t ios_readall(ios_t *s, char *dest, size_t n); @@ -85,7 +37,6 @@ DLLEXPORT int ios_isopen(ios_t *s); DLLEXPORT char *ios_takebuf(ios_t *s, size_t *psize); // release buffer to caller // set buffer space to use DLLEXPORT int ios_setbuf(ios_t *s, char *buf, size_t size, int own); -DLLEXPORT int ios_bufmode(ios_t *s, bufmode_t mode); DLLEXPORT int ios_get_readable(ios_t *s); DLLEXPORT int ios_get_writable(ios_t *s); DLLEXPORT void ios_set_readonly(ios_t *s); diff --git a/src/support/ios_internal.h b/src/support/ios_internal.h new file mode 100644 index 0000000000000..fb2182dd32c89 --- /dev/null +++ b/src/support/ios_internal.h @@ -0,0 +1,68 @@ +#ifndef IOS_PRIVATE_H +#define IOS_PRIVATE_H + +#include "uv.h" +#include "ios.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { bm_none=UV_HANDLE_TYPE_MAX+1, bm_line, bm_block, bm_mem } bufmode_t; + +struct ios_t { + // the state only indicates where the underlying file position is relative + // to the buffer. reading: at the end. writing: at the beginning. + // in general, you can do any operation in any state. + char *buf; // start of buffer + + int errcode; + +#ifdef _P64 + int _pad_bm; // put bm at same offset as type field of uv_stream_s +#endif + bufmode_t bm; // + bufstate_t state; + + off_t maxsize; // space allocated to buffer + off_t size; // length of valid data in buf, >=ndirty + off_t bpos; // current position in buffer + off_t ndirty; // # bytes at &buf[0] that need to be written + + off_t fpos; // cached file pos + size_t lineno; // current line number + + // pointer-size integer to support platforms where it might have + // to be a pointer + long fd; + + unsigned char readable:1; + unsigned char writable:1; + unsigned char ownbuf:1; + unsigned char ownfd:1; + unsigned char _eof:1; + + // this means you can read, seek back, then read the same data + // again any number of times. usually only true for files and strings. + unsigned char rereadable:1; + + // this enables "stenciled writes". you can alternately write and + // seek without flushing in between. this performs read-before-write + // to populate the buffer, so "rereadable" capability is required. + // this is off by default. + //unsigned char stenciled:1; + + // request durable writes (fsync) + // unsigned char durable:1; + + int64_t userdata; + char local[IOS_INLSIZE]; +}; + +DLLEXPORT int ios_bufmode(ios_t *s, bufmode_t mode); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/sys.c b/src/sys.c index 919a1ce7dfc05..e040130006b10 100644 --- a/src/sys.c +++ b/src/sys.c @@ -2,8 +2,8 @@ sys.c I/O and operating system utility functions */ -#include "julia.h" #include "julia_internal.h" +#include "ios_internal.h" #include #include #include diff --git a/src/task.c b/src/task.c index 025aa0f0218d2..fd28da01c8f53 100644 --- a/src/task.c +++ b/src/task.c @@ -10,7 +10,6 @@ //#include #include #include -#include "julia.h" #include "julia_internal.h" #ifdef __cplusplus diff --git a/src/toplevel.c b/src/toplevel.c index 1551001941751..cd46afe5fad28 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -14,7 +14,6 @@ #else #include #endif -#include "julia.h" #include "julia_internal.h" #include "uv.h"