Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
libhxcpp 6.0.3 (unreleased)
------------------------------------------------------------

* Fixed a String's or a typed Array's indexOf and lastIndexOf not compiling when the start is read from a Dynamic field, as in text.indexOf(" ", o.start): since 6.0.0 an Int start has an overload of its own, and the hx::Val of a field read converts to both an Int and a Dynamic, so the call was ambiguous (C2668 on MSVC, "call to member function 'indexOf' is ambiguous" on clang). Such a start goes to the Dynamic overload again, as every start did before 6.0.0, and an Int start is still not boxed
* Fixed the C++ build tool, built with haxe compile-cpp.hxml in tools/hxcpp, not compiling since 6.0.0: ThreadPool.hx declared the class that ends a compile thread's job before one of its imports, which Haxe refuses with "import and using may not appear after a declaration". The neko build tool, hxcpp.n, was unaffected, and run.n uses a C++ build tool only once one is built, so only rebuilding it failed. CI now type-checks it (libhxcpp #471)
* Fixed a cppia cast to a class or interface whose value goes unused, cast(o, SomeInterface) as a statement, checking nothing under the JIT: a cast that fails ran on, where the interpreter and compiled code throw. Haxe's TestCasts.testInterfaces makes such casts in closures, which the JIT now compiles. The JIT leaves out only the unused casts that cannot fail
* Fixed the collector marking and moving the variables a cppia closure captures in place in the closure: a closure packs its captures at 4-byte offsets, so on 64-bit a String or object captured after an Int, as text in var count = 1; var text = "x"; function() return count + text, sits at an odd multiple of 4, which is undefined behaviour, reported by UBSan, and a fault on a CPU that requires alignment. Each capture is copied out to be marked or visited now, and written back if the moving collector moved it. Interpreted and jitted closures were both affected
Expand Down
6 changes: 6 additions & 0 deletions include/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,10 @@ class Array_obj : public hx::ArrayBase
return indexOf(inValue, fromIndex==null() ? 0 : fromIndex->__ToInt());
}
int indexOf(ELEM_ inValue, const null &) { return indexOf(inValue, 0); }
// Any other class converts to both as well, as the hx::Val of a Dynamic field
// read does, so it takes the Dynamic overload
template<typename T>
typename std::enable_if<std::is_class<T>::value, int>::type indexOf(ELEM_ inValue, const T &fromIndex) { return indexOf(inValue, Dynamic(fromIndex)); }
int indexOf(ELEM_ inValue, int fromIndex)
{
int len = length;
Expand All @@ -948,6 +952,8 @@ class Array_obj : public hx::ArrayBase
return lastIndexOf(inValue, fromIndex==null() ? (int)length-1 : fromIndex->__ToInt());
}
int lastIndexOf(ELEM_ inValue, const null &) { return lastIndexOf(inValue, (int)length-1); }
template<typename T>
typename std::enable_if<std::is_class<T>::value, int>::type lastIndexOf(ELEM_ inValue, const T &fromIndex) { return lastIndexOf(inValue, Dynamic(fromIndex)); }
int lastIndexOf(ELEM_ inValue, int fromIndex)
{
int len = length;
Expand Down
8 changes: 8 additions & 0 deletions include/hxString.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <hx/StringAlloc.h>
#include <atomic>
#include <type_traits>

#ifdef __OBJC__
#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -170,6 +171,13 @@ class HXCPP_EXTERN_CLASS_ATTRIBUTES String
int lastIndexOf(const ::String &inValue, int inStart) const;
inline int indexOf(const ::String &inValue, const null &) const { return indexOf(inValue, 0); }
inline int lastIndexOf(const ::String &inValue, const null &) const { return lastIndexOf(inValue, length); }
// Any other class converts to both as well, as the hx::Val of a Dynamic field
// read does, so it takes the Dynamic overload. D stands for Dynamic, which is
// not complete here, so that the conversion waits for a use
template<typename T, typename D = Dynamic>
inline typename std::enable_if<std::is_class<T>::value, int>::type indexOf(const ::String &inValue, const T &inStart) const { return indexOf(inValue, D(inStart)); }
template<typename T, typename D = Dynamic>
inline typename std::enable_if<std::is_class<T>::value, int>::type lastIndexOf(const ::String &inValue, const T &inStart) const { return lastIndexOf(inValue, D(inStart)); }
Array<String> split(const ::String &inDelimiter) const;
::String substr(int inPos,Dynamic inLen) const;
::String substring(int inStartIndex, Dynamic inEndIndex) const;
Expand Down
12 changes: 10 additions & 2 deletions test/haxe/TestSearch.hx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ class TestSearch extends Test
return -1;
}

// Int starts are taken without boxing them; typed, boxed, omitted, null
// and reflected starts must all give the same result
// Int starts are taken without boxing them; typed, boxed, omitted, null,
// reflected and Dynamic field starts must all give the same result. A
// field read converts to both an Int and a Dynamic, so it needs its own
// overload in C++ or the call does not compile
function checkArray(a:Array<Int>, v:Int, ?pos:haxe.PosInfos)
{
Assert.equals(arrayIndexOf(a, v, 0), a.indexOf(v), pos);
Expand All @@ -79,6 +81,9 @@ class TestSearch extends Test
Assert.equals(a.lastIndexOf(v, s), a.lastIndexOf(v, boxed), pos);
Assert.equals(a.indexOf(v, s), Reflect.callMethod(a, indexOf, [v, s]), pos);
Assert.equals(a.lastIndexOf(v, s), Reflect.callMethod(a, lastIndexOf, [v, s]), pos);
var holder:Dynamic = { start: s };
Assert.equals(a.indexOf(v, s), a.indexOf(v, holder.start), pos);
Assert.equals(a.lastIndexOf(v, s), a.lastIndexOf(v, holder.start), pos);
}
}

Expand All @@ -98,6 +103,9 @@ class TestSearch extends Test
Assert.equals(text.lastIndexOf(needle, s), text.lastIndexOf(needle, boxed), pos);
Assert.equals(text.indexOf(needle, s), dyn.indexOf(needle, s), pos);
Assert.equals(text.lastIndexOf(needle, s), dyn.lastIndexOf(needle, s), pos);
var holder:Dynamic = { start: s };
Assert.equals(text.indexOf(needle, s), text.indexOf(needle, holder.start), pos);
Assert.equals(text.lastIndexOf(needle, s), text.lastIndexOf(needle, holder.start), pos);
}
}

Expand Down
Loading