Skip to content

Commit 90fa269

Browse files
committed
CLJCLR-175: Fix aset throwing an exception when arg is typeArray by inference (say by aclone)
1 parent cd2e4ff commit 90fa269

File tree

2 files changed

+104
-31
lines changed

2 files changed

+104
-31
lines changed

Clojure/Clojure.Source/clojure/gvec.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ Object
454454
System.Collections.ICollection
455455
(CopyTo [this arr offset]
456456
(dotimes [i cnt]
457-
(aset arr (+ i offset) (.nth this i))))
457+
(.SetValue ^Array arr (.nth this i) (int (+ i offset)))))
458458

459459
(get_Count [_] cnt)
460460
(get_IsSynchronized [_] true)

Clojure/Clojure/Lib/RT.cs

Lines changed: 103 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ static Dictionary<Symbol, Type> CreateDefaultImportDictionary()
5252

5353
static IEnumerable<Type> GetAllTypesInNamespace(string nspace)
5454
{
55-
Func<Assembly, IEnumerable<Type>> getTypes = (Assembly a) => {
55+
Func<Assembly, IEnumerable<Type>> getTypes = (Assembly a) =>
56+
{
5657
try { return a.GetTypes(); } catch (Exception) { return new Type[0]; }
5758
};
5859
var q = AppDomain.CurrentDomain.GetAssemblies()
@@ -74,7 +75,7 @@ static IEnumerable<Type> GetAllTypesInNamespace(string nspace)
7475

7576
public static readonly object[] EmptyObjectArray = new Object[] { };
7677

77-
static readonly RTProperties _versionProperties = new RTProperties();
78+
static readonly RTProperties _versionProperties = new();
7879

7980
public static RTProperties GetVersionProperties() { return _versionProperties; }
8081

@@ -83,7 +84,7 @@ static IEnumerable<Type> GetAllTypesInNamespace(string nspace)
8384
// for folks using Cygwin and its ilk.
8485
public const string ClojureLoadPathString = "CLOJURE_LOAD_PATH";
8586

86-
static public readonly Object REQUIRE_LOCK = new Object();
87+
static public readonly Object REQUIRE_LOCK = new();
8788

8889
#endregion
8990

@@ -123,7 +124,7 @@ public static readonly Namespace ClojureNamespace
123124
public static readonly Keyword TagKey
124125
= Keyword.intern(null, "tag");
125126

126-
public static readonly Keyword ParamTagsKey
127+
public static readonly Keyword ParamTagsKey
127128
= Keyword.intern(null, "param-tags");
128129

129130
public static readonly Keyword ConstKey
@@ -336,7 +337,7 @@ public override object invoke(object arg1)
336337

337338
static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
338339
{
339-
AssemblyName asmName = new AssemblyName(args.Name);
340+
AssemblyName asmName = new(args.Name);
340341
var name = asmName.Name;
341342
var stream = GetEmbeddedResourceStream(name, out _);
342343
if (stream == null)
@@ -371,16 +372,16 @@ static RT()
371372

372373
// TODO: Check for existence of ClojureContext.Default before doing this?
373374

374-
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
375-
LanguageSetup lsetup = new LanguageSetup(
375+
ScriptRuntimeSetup setup = new();
376+
LanguageSetup lsetup = new(
376377
typeof(ClojureContext).AssemblyQualifiedName,
377378
ClojureContext.ClojureDisplayName,
378379
ClojureContext.ClojureNames.Split(new Char[] { ';' }),
379380
ClojureContext.ClojureFileExtensions.Split(new Char[] { ';' }));
380381

381382

382383
setup.LanguageSetups.Add(lsetup);
383-
ScriptRuntime env = new ScriptRuntime(setup);
384+
ScriptRuntime env = new(setup);
384385
env.GetEngine("clj");
385386

386387

@@ -2375,7 +2376,7 @@ public static object[] toArray(object coll)
23752376

23762377
private static object[] IEnumToArray(IEnumerable e)
23772378
{
2378-
List<object> list = new List<object>();
2379+
List<object> list = new();
23792380
foreach (object o in e)
23802381
list.Add(o);
23812382

@@ -2503,7 +2504,7 @@ public static bool suppressRead()
25032504

25042505
static public string printString(object x)
25052506
{
2506-
using (StringWriter sw = new StringWriter())
2507+
using (StringWriter sw = new())
25072508
{
25082509
print(x, sw);
25092510
return sw.ToString();
@@ -2519,7 +2520,7 @@ static public Object readString(String s)
25192520

25202521
static public Object readString(String s, Object opts)
25212522
{
2522-
using (PushbackTextReader r = new PushbackTextReader(new StringReader(s)))
2523+
using (PushbackTextReader r = new(new StringReader(s)))
25232524
return LispReader.read(r, opts);
25242525
}
25252526

@@ -2784,7 +2785,7 @@ public static Type classForName(string p)
27842785

27852786
AppDomain domain = AppDomain.CurrentDomain;
27862787
Assembly[] assys = domain.GetAssemblies();
2787-
List<Type> candidateTypes = new List<Type>();
2788+
List<Type> candidateTypes = new();
27882789

27892790
// fast path, will succeed for namespace qualified names (returned by Type.FullName)
27902791
// e.g. "UnityEngine.Transform"
@@ -2864,11 +2865,83 @@ public static int alength(Array a)
28642865
}
28652866

28662867

2867-
public static Array aclone(Array a)
2868+
//public static Array aclone(Array a)
2869+
//{
2870+
// return (Array)a.Clone();
2871+
//}
2872+
2873+
public static object[] aclone(Object[] a)
2874+
{
2875+
return (Object[])a.Clone();
2876+
}
2877+
2878+
public static bool[] aclone(bool[] a)
2879+
{
2880+
return (bool[])a.Clone();
2881+
}
2882+
2883+
public static byte[] aclone(byte[] a)
2884+
{
2885+
return (byte[])a.Clone();
2886+
}
2887+
2888+
public static sbyte[] aclone(sbyte[] a)
2889+
{
2890+
return (sbyte[])a.Clone();
2891+
}
2892+
2893+
public static char[] aclone(char[] a)
28682894
{
2869-
return (Array)a.Clone();
2895+
return (char[])a.Clone();
28702896
}
28712897

2898+
public static short[] aclone(short[] a)
2899+
{
2900+
return (short[])a.Clone();
2901+
}
2902+
2903+
public static ushort[] aclone(ushort[] a)
2904+
{
2905+
return (ushort[])a.Clone();
2906+
}
2907+
2908+
public static int[] aclone(int[] a)
2909+
{
2910+
return (int[])a.Clone();
2911+
}
2912+
2913+
public static uint[] aclone(uint[] a)
2914+
{
2915+
return (uint[])a.Clone();
2916+
}
2917+
2918+
public static long[] aclone(long[] a)
2919+
{
2920+
return (long[])a.Clone();
2921+
}
2922+
2923+
public static ulong[] aclone(ulong[] a)
2924+
{
2925+
return (ulong[])a.Clone();
2926+
}
2927+
2928+
public static float[] aclone(float[] a)
2929+
{
2930+
return (float[])a.Clone();
2931+
}
2932+
2933+
public static double[] aclone(double[] a)
2934+
{
2935+
return (double[])a.Clone();
2936+
}
2937+
2938+
public static decimal[] aclone(decimal[] a)
2939+
{
2940+
return (decimal[])a.Clone();
2941+
}
2942+
2943+
2944+
28722945

28732946
public static object aget(Array a, int idx)
28742947
{
@@ -2883,11 +2956,11 @@ public static object agetOnArray(Array a, int idx)
28832956
return a.GetValue(idx);
28842957
}
28852958

2886-
public static object aset(Array a, int idx, object val)
2887-
{
2888-
a.SetValue(val, idx);
2889-
return val;
2890-
}
2959+
//public static object aset(Array a, int idx, object val)
2960+
//{
2961+
// a.SetValue(val, idx);
2962+
// return val;
2963+
//}
28912964

28922965

28932966

@@ -3141,7 +3214,7 @@ public static long nanoTime()
31413214
return DateTime.Now.Ticks * 100;
31423215
}
31433216

3144-
private static readonly Stopwatch _stopwatch = new Stopwatch();
3217+
private static readonly Stopwatch _stopwatch = new();
31453218

31463219
public static object StartStopwatch()
31473220
{
@@ -3209,7 +3282,7 @@ public static void SortArray(Array a, IFn fn)
32093282

32103283

32113284

3212-
static readonly Random _random = new Random();
3285+
static readonly Random _random = new();
32133286

32143287

32153288
public static double random()
@@ -3363,7 +3436,7 @@ private static bool TryLoadFromEmbeddedResource(string relativePath, string asse
33633436

33643437
var embeddedCljName = relativePath.Replace("/", ".") + ".cljr";
33653438
var stream = GetEmbeddedResourceStream(embeddedCljName, out Assembly containingAssembly);
3366-
if ( stream == null )
3439+
if (stream == null)
33673440
{
33683441
embeddedCljName = relativePath.Replace("/", ".") + ".cljc";
33693442
stream = GetEmbeddedResourceStream(embeddedCljName, out containingAssembly);
@@ -3401,12 +3474,12 @@ public static void LoadCljScript(string cljname, bool failIfNotFound)
34013474
{
34023475
FileInfo cljInfo = FindFile(cljname);
34033476
if (cljInfo != null)
3404-
LoadScript(cljInfo,cljname);
3477+
LoadScript(cljInfo, cljname);
34053478
else if (failIfNotFound)
34063479
throw new FileNotFoundException(String.Format("Could not locate Clojure resource on {0}", ClojureLoadPathString));
34073480
}
34083481

3409-
public static void LoadScript(FileInfo cljInfo, string relativePath)
3482+
public static void LoadScript(FileInfo cljInfo, string relativePath)
34103483
{
34113484
using (TextReader rdr = cljInfo.OpenText())
34123485
LoadScript(cljInfo.FullName, cljInfo.Name, rdr, relativePath);
@@ -3419,7 +3492,7 @@ private static void LoadScript(string fullName, string name, TextReader rdr, str
34193492

34203493
private static void Compile(FileInfo cljInfo, string relativePath)
34213494
{
3422-
using ( TextReader rdr = cljInfo.OpenText() )
3495+
using (TextReader rdr = cljInfo.OpenText())
34233496
Compile(cljInfo.Directory.FullName, cljInfo.Name, rdr, relativePath);
34243497
}
34253498

@@ -3450,7 +3523,7 @@ static IEnumerable<string> GetFindFilePathsRaw()
34503523
yield return Path.GetDirectoryName(typeof(RT).Assembly.Location);
34513524

34523525
Assembly assy = Assembly.GetEntryAssembly();
3453-
if ( assy != null )
3526+
if (assy != null)
34543527
yield return Path.GetDirectoryName(assy.Location);
34553528

34563529
string rawpaths = (string)System.Environment.GetEnvironmentVariable(ClojureLoadPathString);
@@ -3470,7 +3543,7 @@ public static FileInfo FindFile(string fileName)
34703543
foreach (string path in GetFindFilePaths())
34713544
{
34723545
fi = FindFile(path, fileName);
3473-
if (fi is not null ) return fi;
3546+
if (fi is not null) return fi;
34743547
}
34753548

34763549
return FindRemappedFile(fileName);
@@ -3490,11 +3563,11 @@ public static FileInfo FindRemappedFile(string fileName)
34903563
if (!(x is PersistentVector mapping) || mapping.length() < 2) continue;
34913564
if (!(mapping[0] is string nsRoot)) continue;
34923565
nsRoot = nsRoot.Replace('.', '/');
3493-
if(fileName.StartsWith(nsRoot))
3566+
if (fileName.StartsWith(nsRoot))
34943567
{
34953568
var fsRoot = mapping[1] as string;
34963569
var probePath = ConvertPath(fsRoot) + ConvertPath(fileName.Substring(nsRoot.Length));
3497-
if(File.Exists(probePath))
3570+
if (File.Exists(probePath))
34983571
return new FileInfo(probePath);
34993572
}
35003573
}
@@ -3621,7 +3694,7 @@ public static string[] TrimTrailingEmptyStrings(string[] arr)
36213694
break;
36223695
i--;
36233696
}
3624-
Array.Resize(ref arr,i + 1);
3697+
Array.Resize(ref arr, i + 1);
36253698
return arr;
36263699
}
36273700

0 commit comments

Comments
 (0)