From fa874279ec9f22af37b754d1141a17d99fff1229 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 2 Nov 2011 18:02:09 -0400 Subject: [PATCH] making push/enq/insert do the conversion before growing, so you don't ever end up with uninitialized array elements fortunately the compiler is able to eliminate the second conversion making VARIABLES a cell array again. it's a hack to begin with... --- j/array.j | 4 ++++ j/client.j | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/j/array.j b/j/array.j index 2e11921f96aad..a67016a8bd1a9 100644 --- a/j/array.j +++ b/j/array.j @@ -225,6 +225,8 @@ function push{T}(a::Array{T,1}, item::ANY) if is(T,None) error("[] cannot grow. Instead, initialize the array with \"empty(element_type)\".") end + # convert first so we don't grow the array if the assignment won't work + item = convert(T, item) ccall(:jl_array_grow_end, Void, (Any, Ulong), a, ulong(1)) a[end] = item return a @@ -248,6 +250,7 @@ function enq{T}(a::Array{T,1}, item) if is(T,None) error("[] cannot grow. Instead, initialize the array with \"empty(element_type)\".") end + item = convert(T, item) ccall(:jl_array_grow_beg, Void, (Any, Ulong), a, ulong(1)) a[1] = item return a @@ -257,6 +260,7 @@ function insert{T}(a::Array{T,1}, i::Int, item) if i < 1 throw(BoundsError()) end + item = convert(T, item) l = length(a) if i > l ccall(:jl_array_grow_end, Void, (Any, Ulong), a, ulong(i-l)) diff --git a/j/client.j b/j/client.j index 0776a8525d56b..b4b43c15635c2 100644 --- a/j/client.j +++ b/j/client.j @@ -107,7 +107,7 @@ function _start() global const PGRP = ProcessGroup(0, {}, {}) end - global const VARIABLES = empty(Symbol) + global const VARIABLES = {} # Load customized startup try