diff --git a/base/array.jl b/base/array.jl index ad7dc18de5069..8156aa74ac523 100644 --- a/base/array.jl +++ b/base/array.jl @@ -672,7 +672,7 @@ function push!(a::Array{Any,1}, item::ANY) return a end -function append!{T}(a::Array{T,1}, items::Array{T,1}) +function append!{T}(a::Array{T,1}, items::Vector) if is(T,None) error("[] cannot grow. Instead, initialize the array with \"T[]\".") end diff --git a/base/iobuffer.jl b/base/iobuffer.jl index e3fe9b1201d2d..2f6d3d48f4dc5 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -14,6 +14,8 @@ type IOBuffer <: IO new(data,readable,writable,seekable,append,length(data),maxsize,1) end +copy(b::IOBuffer) = (ret=IOBuffer(copy(b.data),b.readable,b.writable,b.seekable,b.append,b.maxsize);ret.size=b.size;ret.ptr = b.ptr;ret) + # PipeBuffers behave like Unix Pipes. They are readable and writable, the act appendable, and not seekable. PipeBuffer(data::Vector{Uint8},maxsize::Int) = IOBuffer(data,true,true,false,true,maxsize) PipeBuffer(data::Vector{Uint8}) = PipeBuffer(data,typemax(Int)) @@ -55,6 +57,14 @@ function read(from::IOBuffer, ::Type{Uint8}) return byte end +function peek(from::IOBuffer) + if !from.readable error("read failed") end + if from.ptr > from.size + throw(EOFError()) + end + return from.data[from.ptr] +end + read{T}(from::IOBuffer, ::Type{Ptr{T}}) = convert(Ptr{T}, read(from, Uint)) # TODO: IOBuffer is not iterable, so doesn't really have a length. diff --git a/base/reflection.jl b/base/reflection.jl index 3b9a96169f882..a77d9a590fd13 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -3,8 +3,8 @@ module_name(m::Module) = ccall(:jl_module_name, Any, (Any,), m)::Symbol module_parent(m::Module) = ccall(:jl_module_parent, Any, (Any,), m)::Module current_module() = ccall(:jl_get_current_module, Any, ())::Module -names(m::Module, all::Bool) = ccall(:jl_module_names, Array{Symbol,1}, (Any,Int32), m, all) -names(m::Module) = names(m,false) +names(m::Module, all::Bool, imported::Bool) = ccall(:jl_module_names, Array{Symbol,1}, (Any,Int32,Int32), m, all, imported) +names(m::Module) = names(m,false,false) names(t::DataType) = t.names function names(v) diff --git a/src/alloc.c b/src/alloc.c index dded6c40a1176..de87f6f713787 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -28,6 +28,7 @@ jl_typename_t *jl_array_typename; jl_value_t *jl_array_uint8_type; jl_value_t *jl_array_any_type=NULL; jl_value_t *jl_array_symbol_type; +jl_value_t *jl_array_module_type; jl_function_t *jl_bottom_func; jl_datatype_t *jl_weakref_type; jl_datatype_t *jl_ascii_string_type; diff --git a/src/dump.c b/src/dump.c index 54bf97cd8f82a..c9f2d8ce0d181 100644 --- a/src/dump.c +++ b/src/dump.c @@ -985,7 +985,7 @@ void jl_init_serializer(void) jl_typename_type, jl_task_type, jl_uniontype_type, jl_typetype_type, jl_typetype_tvar, jl_ANY_flag, jl_array_any_type, jl_intrinsic_type, jl_method_type, - jl_methtable_type, jl_voidpointer_type, + jl_methtable_type, jl_voidpointer_type, jl_array_module_type, jl_array_symbol_type, jl_tupleref(jl_tuple_type,0), jl_symbol_type->name, jl_pointer_type->name, diff --git a/src/jltypes.c b/src/jltypes.c index 866ceb09cff4a..7ad660a35a170 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -2645,6 +2645,11 @@ void jl_init_types(void) jl_tupleset(jl_typename_type->types, 1, jl_module_type); + jl_array_module_type = + (jl_value_t*)jl_apply_type((jl_value_t*)jl_array_type, + jl_tuple(2, jl_module_type, + jl_box_long(1))); + jl_lambda_info_type = jl_new_datatype(jl_symbol("LambdaStaticData"), jl_any_type, jl_null, diff --git a/src/julia.h b/src/julia.h index fc9e9b12d70e4..b3cf5e5f7a0c6 100644 --- a/src/julia.h +++ b/src/julia.h @@ -402,6 +402,7 @@ extern jl_datatype_t *jl_pointer_type; extern jl_value_t *jl_array_uint8_type; extern jl_value_t *jl_array_any_type; extern jl_value_t *jl_array_symbol_type; +extern jl_value_t *jl_array_module_type; extern DLLEXPORT jl_datatype_t *jl_expr_type; extern jl_datatype_t *jl_symbolnode_type; extern jl_datatype_t *jl_getfieldnode_type; diff --git a/src/module.c b/src/module.c index 2180fa1f57d12..65cba2f0d26c4 100644 --- a/src/module.c +++ b/src/module.c @@ -376,7 +376,20 @@ DLLEXPORT void jl_set_current_module(jl_value_t *m) jl_current_module = (jl_module_t*)m; } -DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all) +DLLEXPORT jl_value_t *jl_module_usings(jl_module_t *m) +{ + jl_array_t *a = jl_alloc_array_1d(jl_array_module_type, 0); + JL_GC_PUSH1(&a); + for(int i=(int)m->usings.len-1; i >= 0; --i) { + jl_array_grow_end(a, 1); + jl_module_t *imp = (jl_module_t*)m->usings.items[i]; + jl_cellset(a,jl_array_dim0(a)-1, (jl_value_t*)imp); + } + JL_GC_POP(); + return (jl_value_t*)a; +} + +DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all, int imported) { jl_array_t *a = jl_alloc_array_1d(jl_array_symbol_type, 0); JL_GC_PUSH1(&a); @@ -385,7 +398,7 @@ DLLEXPORT jl_value_t *jl_module_names(jl_module_t *m, int all) for(i=1; i < m->bindings.size; i+=2) { if (table[i] != HT_NOTFOUND) { jl_binding_t *b = (jl_binding_t*)table[i]; - if (b->exportp || (b->owner == m && (all || m == jl_main_module))) { + if (b->exportp || ((imported || b->owner == m) && (all || m == jl_main_module))) { jl_array_grow_end(a, 1); //XXX: change to jl_arrayset if array storage allocation for Array{Symbols,1} changes: jl_cellset(a, jl_array_dim0(a)-1, (jl_value_t*)b->name);