Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4aff840
Keep the rest of extraParams.hxml when the release stamps the version
dimensionscape Nov 18, 2026
99b09f7
Link again when a target's flags, libraries or library paths change
dimensionscape Nov 18, 2026
6dc7a9b
Recompile when HXCPP_LINK_NO_EXCEPTIONS changes
dimensionscape Nov 18, 2026
eb6a190
Read the build tool's sources from its own folder in the defines command
dimensionscape Nov 18, 2026
1f5f6e7
Run the ARM64 vcvars script for HXCPP_MSVC_VER on an ARM64 build
dimensionscape Nov 18, 2026
b7d6fde
Link again after a strip or manifest step that failed after the link
dimensionscape Nov 18, 2026
c3a9ee4
Do nothing at a safe point inside a GC-free zone
dimensionscape Nov 18, 2026
4563191
Keep the caller's GC-free zone in Lock, Semaphore and Deque waits
dimensionscape Nov 18, 2026
d4c2b0d
Sleep in parts that fit the native call
dimensionscape Nov 18, 2026
dcb752f
Cap Socket.select's timeout at what a timeval holds
dimensionscape Nov 18, 2026
fac3dc2
Make a thread's scratch buffer only at API level 500
dimensionscape Nov 18, 2026
190b75c
Refuse a cppia super constructor call into a class with no constructor
dimensionscape Nov 18, 2026
a896acf
Refuse a cppia constructor that is not a function
dimensionscape Nov 18, 2026
82f8794
Refuse a new instance of a cppia script interface
dimensionscape Nov 18, 2026
ec165c2
Lower the fuzz ereg target's match limit to 100,000 steps
dimensionscape Nov 18, 2026
a8751c0
Compare Dates past 2^53 ms loosely in the fuzz serializer target
dimensionscape Nov 18, 2026
532668f
Refuse a cppia dynamic function that is not a function
dimensionscape Nov 18, 2026
98f5dd5
Hold a weak map's keys while a walk is on them
dimensionscape Nov 18, 2026
2fb328f
Build the large allocation indexes on one marking thread at a time
dimensionscape Nov 18, 2026
8ec29c9
Read a large nursery allocation's size past the flags in its header
dimensionscape Nov 18, 2026
b67222a
Wrap Int array *= and -= under the cppia JIT
dimensionscape Nov 18, 2026
efe3d7c
Keep a negated Int an Int in cppia
dimensionscape Nov 18, 2026
f2a5530
Box Array<Any> contains and remove as Bool in interpreted cppia
dimensionscape Nov 18, 2026
82f19f1
Bridge exceptions from concat under the cppia JIT
dimensionscape Nov 18, 2026
7fdae8c
Skip a loading cppia module's unmade types when the GC moves objects
dimensionscape Nov 18, 2026
c5f2a2c
Keep the heap at its target under churn of objects bigger than a line
dimensionscape Nov 18, 2026
492c249
Keep x *= y on a Dynamic from losing y in the cppia JIT
dimensionscape Nov 18, 2026
e1f6ac0
Keep what a cpp.Pointer field points into alive
dimensionscape Nov 18, 2026
34c163b
Share the counter and flag atomically in SafePointInGcFreeZone
dimensionscape Nov 18, 2026
72a6c40
Cap Socket.select's timeout at 1e8 seconds for macOS
dimensionscape Nov 19, 2026
155c9a4
Read a lazily compiled cppia function's code with acquire
dimensionscape Nov 19, 2026
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
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ jobs:
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
run: timeout 1200 sh test/emscripten/exceptions/run.sh

- name: Rebuild with HXCPP_LINK_NO_EXCEPTIONS, without the compile cache
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
run: timeout 1200 sh test/emscripten/link_no_exceptions.sh

- name: Run the Embind test
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
run: timeout 600 sh test/emscripten/embind/run.sh
Expand Down Expand Up @@ -324,6 +328,10 @@ jobs:
# Git Bash on Windows
shell: bash

- run: bash test/release_stamp/check.sh
name: What the release stamps into the package
shell: bash


# The test suites on every platform with the stable Haxe; nightly.yml runs
# them with the Haxe nightly build once a day
Expand Down
30 changes: 29 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,34 @@ jobs:
haxelib run hxcpp Build.xml
test "$(tr -d '\r' < out/kept.txt)" = old
test "$(tr -d '\r' < out/replaced.txt)" = new
- name: build tool links again when a link flag changes
continue-on-error: ${{ inputs.warn_only }}
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
working-directory: test/link_flags
run: |
haxelib run hxcpp Build.xml
rm -f prog.map
haxelib run hxcpp Build.xml -DWANT_MAP
test -f prog.map
- name: build tool fails again after a step after the link failed
continue-on-error: ${{ inputs.warn_only }}
if: ${{ !cancelled() && steps.setup.outcome == 'success' && runner.os == 'Windows' }}
working-directory: test/link_flags
run: |
rm -rf obj prog.exe prog.exe.hash
for build in first second; do
if haxelib run hxcpp Build.xml -DmanifestFile=bad.manifest; then
echo "::error::the $build build with a bad manifest should have failed"
exit 1
fi
done
- name: build tool lists the defines it reads
continue-on-error: ${{ inputs.warn_only }}
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
working-directory: test/link_flags
run: |
haxelib run hxcpp defines > defines.txt
grep -qx HXCPP_COMPILE_CACHE defines.txt
- name: build tool rejects file names that differ only in case
continue-on-error: ${{ inputs.warn_only }}
if: ${{ !cancelled() && steps.setup.outcome == 'success' }}
Expand Down Expand Up @@ -467,7 +495,7 @@ jobs:
working-directory: test/regression
run: |
failed=""
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcDequeMoves IncrementalGcPacing IncrementalGcStartSweep IncrementalGcStats IncrementalGcFinishBoundary IncrementalGcVerifier IncrementalWindowsHeaders GcWeakMapChain GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
for test in GcMutationRoots GcContainerMutation IncrementalGcSlices IncrementalGcContainers IncrementalGcArrayChunks IncrementalGcDequeMoves IncrementalGcPacing IncrementalGcStartSweep IncrementalGcStats IncrementalGcFinishBoundary IncrementalGcVerifier IncrementalWindowsHeaders GcWeakMapChain GcWeakMapWalkCollect GenerationalFinalizerLifecycle GenerationalLargeBufferLifecycle; do
echo "::group::incremental gc: $test"
# The lifecycle fixtures' hxml selects generational mode; compile
# the same Main with incremental mode here instead.
Expand Down
28 changes: 28 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
libhxcpp 6.0.0 (unreleased)
------------------------------------------------------------

* Fixed a Haxe 4 haxe.atomic.AtomicInt kept in a field reading freed memory after a collection: Haxe 4's AtomicInt on C++ is a cpp.Pointer into a one-element array nothing else holds, and the collector ignored cpp.Pointer fields, so it freed the array (HaxeFoundation/hxcpp#1225; Haxe 5 changed AtomicInt instead, in HaxeFoundation/haxe#12236). A cpp.Pointer field, or a pointer boxed in a Dynamic, now keeps what it points into in the GC heap, as a pointer on the stack does, and pins it under HXCPP_GC_MOVING. Of 10,000 atomics in fields, 9,999 read freed memory after a collection and none do now
* Fixed HXCPP_GC_INCREMENTAL failing to compile ("Incremental GC requires regenerated C++") with libhxcpp installed from a release, 6.0.0-rc.2 among them: the release workflow rewrote extraParams.hxml with the version and dropped its other line, the macro that turns on the generated write barriers the incremental collector needs. Only the version lines are rewritten now
* Fixed a change of link flags or libraries alone leaving the program as it was: the build tool linked again only when an object or library file had changed, so -D HXCPP_LINK_STACK_SIZE, HXCPP_LINK_NO_MEMORY_GROWTH, HXCPP_LINK_NO_EMBIND or HXCPP_LINK_NODERAWFS on an Emscripten build, which change nothing that is compiled, or a flag or library added to a target in Build.xml, did nothing until the objects changed. The flags, libraries and library paths are now part of what a link is checked against, so each program links once more after updating
* Fixed an Emscripten build failing to link (undefined symbol: __wasm_lpad_context) when -D HXCPP_LINK_NO_EXCEPTIONS was added to a project built before without it: the define also compiles without -fwasm-exceptions, but the build tool took every HXCPP_LINK_ define for a link option and compiled nothing again. It recompiles now, and once back without it
* Fixed `haxelib run hxcpp defines` failing with "Could not read" from any folder but tools/hxcpp: it opened the build tool's sources by name, relative to the caller's folder. It lists the defines the build tool reads again
* Fixed an ARM64 Windows build with HXCPP_MSVC_VER naming the Visual Studio to use: on an x64 machine the setup looked for vcvarsx64_arm64.bat, which Visual Studio calls vcvarsamd64_arm64.bat, and stopped, and on an ARM64 machine it found the ARM64 script and then ran the x64 one, compiling for x64. It runs the ARM64 script for the host
* Fixed a build whose strip or manifest step failed after the link succeeding when run again, with the output unstripped or without its manifest: the link was recorded as done before those steps ran, so the next build had nothing to do. A failure after the link now forgets it, and the next build links again
* Each thread object no longer holds a 64 KB buffer below API level 500: only Haxe 5's hx::thread::Scratch uses it, yet with Haxe 4 every Haxe thread kept one while it ran, and so did every native thread that asked for its sys.thread.Thread, for as long as Haxe's own thread list holds it, which for a native thread is until the process ends
* Fixed Socket.select returning at once with nothing ready for a timeout past 2^31 seconds, Math.POSITIVE_INFINITY included: the timeout overflowed an int of seconds. It is capped at 10^8 seconds (over three years), past which macOS' select fails, and a NaN timeout waits for nothing. Windows' Poll, which takes the same timeout, is fixed with it
* Fixed Sys.sleep returning at once, or after a much shorter time, for a duration that did not fit the native call: on Windows from 2^32 milliseconds, about 49.7 days, and past 2^31 seconds elsewhere. Sys.sleep(Math.POSITIVE_INFINITY) returned at once instead of sleeping for good. A long sleep goes in parts that fit
* Fixed Lock.wait, Semaphore.acquire, Semaphore.tryAcquire with a timeout and a blocking Deque.pop ending the process with "GCFree Zone mismatch" when called inside a GC-free zone the caller had entered, as with cpp.vm.Gc.enterGCFreeZone: when they blocked they left that zone, so the caller's own exit failed. They keep the caller's zone, as Mutex and Condition already did
* Fixed Mutex and Condition ending the process with "Bad Allocation while collecting" when a thread used them inside a GC-free zone it had entered, as with cpp.vm.Gc.enterGCFreeZone, while another thread collected. Their uncontended paths stop at a pending collection, and that stop paused the thread as if it were outside the zone; between collections it could instead wait for ever for a release the collector never sends to a thread in a zone. A thread in a zone is already safe, so cpp.vm.Gc.safePoint and those stops now do nothing there
* Fixed a malformed cppia file that calls the super constructor of a class with no constructor, in it or in a script class above it, crashing the loader, which read the constructor through a null pointer. It fails to load with "Super constructor call on a class with no constructor". The fuzz job found it (libhxcpp #257)
* Fixed a malformed cppia file whose constructor was a bare return or, in an interface, had no body loading and then crashing: a super call into it crashed the loader, and a new of its class crashed when it ran, through the constructor's missing function. It fails to load with "Constructor is not a function" (libhxcpp #257)
* Fixed a malformed cppia file that makes a new instance of a script interface loading and then crashing when it ran, interpreted and under the JIT: an interface has no host base to make the object from. It fails to load with "Could not link new" and the interface's name, as for a type with nothing to construct (libhxcpp #257)
* Fixed a malformed cppia file whose dynamic function was a bare return loading and then crashing, at the next collection after its class booted or when it was called, interpreted and under the JIT: its value was a closure of no function. It fails to load with "Dynamic function is not a function" (libhxcpp #257)
* Fixed _hx_gc_freeze copying none of a string of 4,000 bytes or more with HXCPP_GC_NURSERY, so the frozen string read past its copy: the size of a large allocation in the nursery was taken as 0 when its header had a flag, as a long string's hash slot or UTF-16 text sets

* Fixed the collector freeing large buffers that the memory of a CFFI abstract made with create_abstract pointed to, and crashing: the collector sorts the large allocations into an index on the first lookups of a collection, and the marking threads, which mark an abstract's memory conservatively, could build it two at once. One thread builds it now. In a test holding 20,000 buffers through 8,000 abstracts, 10 to 14 collections in 16 lost buffers or the process crashed

* Fixed a weak map's toString calling toString on keys the collector had already freed, and on whatever had taken their memory, which could crash: a collection during the walk, which allocates as it goes, unlinked the entries whose keys had died, and the walk went on from its entry's next, which still led to them. A weak map now holds its keys and values while a walk is on them, and lets them go at the next collection after it
* Fixed *= and -= on an element of an Array<Int> under the cppia JIT giving -2147483648 when the result passed the Int range: the JIT did them in Float arithmetic and converted back, where compiled code and the interpreter wrap, so a hash kept in an array, h[i] *= 31, went wrong once it overflowed
* Fixed cppia negating an Int as a Float wherever the result was not used as an Int, interpreted and under the JIT: -x with x = 0 printed as "-0", -(-2147483648) gave 2147483648 instead of wrapping, and Type.typeof gave TFloat, as Dynamic, in a String or as a Float
* Fixed interpreted cppia giving contains and remove on an Array<Any> as an Int where they became Dynamic or a String: "" + a.contains(x) was "1" and Std.isOfType(a.remove(x), Bool) false. The fix for the typed arrays had missed Array<Any>'s builtins
* Fixed concat with a null array under the cppia JIT ending the process where it throws Null Object Reference (with HXCPP_CHECK_POINTER, or HXCPP_CATCH_SEGV as the Cppia host has), on typed arrays and Array<Any>: the native call had no exception bridge. The script catches it, as it does interpreted
* Fixed loading a cppia module crashing with HXCPP_GC_MOVING when a collection that moved objects came while the module was making its types: updating the loading module's pointers read the types not yet made
* Fixed the heap growing to twice its working target, and with more churn to hundreds of megabytes, when a program churned objects bigger than a line (128 bytes) with little of them live. A collection that started because no free block could take an allocation counted the free rows of blocks that bigger allocations had already taken and filled as rows in use, so the heap looked full and its target doubled at every other collection, and the groups given back in between were faulted in again. Churning 2,000,000 Bytes of 2,000 bytes with 64 kept reserves 20 MB instead of 41 MB, the same churn of 2,000-character strings after it 20 MB instead of 83 MB (896 MB with HXCPP_GC_MOVING), and churning 200,000 such Bytes takes 16 ms instead of 91 ms (median of 5 processes); a program that churned 1,000 to 2,000-byte Bytes, strings and arrays peaked at 26 MB to 48 MB instead of 187 MB to 896 MB (libhxcpp #256)

libhxcpp 6.0.0-rc.2
------------------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions include/hx/GC.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ bool IsWeakRefValid(const HX_CHAR *inPtr);
// that points to real, active objects.
void MarkConservative(int *inBottom, int *inTop,hx::MarkContext *__inCtx);

// Keeps what a cpp.Pointer points into, as a pointer on the stack would
void MarkConservativePointer(void *inPtr,hx::MarkContext *__inCtx);


// Create/Remove a root.
// All statics are explicitly registered - this saves adding the whole data segment
Expand Down
8 changes: 8 additions & 0 deletions include/hx/GcTypeInference.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ template<> inline void MarkMember<cpp::Variant>(cpp::Variant &outT,hx::MarkConte
{
outT.mark(__inCtx);
}
// A cpp.Pointer field into the GC heap keeps what it points into. Haxe 4's
// haxe.atomic.AtomicInt is one into an array nothing else holds, which was
// freed under it (HaxeFoundation/hxcpp#1225)
template<typename T> inline void MarkMember(cpp::Pointer<T> &outT,hx::MarkContext *__inCtx)
{
if (outT.ptr)
hx::MarkConservativePointer((void *)outT.ptr,__inCtx);
}
template<typename T> inline void MarkMember(hx::Native<T> &outT,hx::MarkContext *__inCtx)
{
if (outT.ptr)
Expand Down
9 changes: 8 additions & 1 deletion src/Dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class Int64Data : public hx::Object
class PointerData : public hx::Object
{
public:
inline void *operator new( size_t inSize, hx::NewObjectType inAlloc=NewObjAlloc,const char *inName="cpp.Pointer")
inline void *operator new( size_t inSize, hx::NewObjectType inAlloc=NewObjContainer,const char *inName="cpp.Pointer")
{ return hx::Object::operator new(inSize,inAlloc,inName); }

PointerData(void *inValue) : mValue(inValue) {};
Expand All @@ -238,6 +238,13 @@ class PointerData : public hx::Object
return mValue < r ? -1 : mValue==r ? 0 : 1;
}

// A boxed pointer into the GC heap keeps what it points into, as a
// cpp.Pointer field does: a script's haxe.atomic.AtomicInt is one
void __Mark(hx::MarkContext *__inCtx) HXCPP_OVERRIDE
{
if (mValue)
hx::MarkConservativePointer(mValue,__inCtx);
}

void *mValue;
};
Expand Down
23 changes: 18 additions & 5 deletions src/hx/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,21 @@ struct Hash : public HashBase< typename ELEMENT::Key >
}


// A weak map holds its keys and values while a walk is on them. A
// collection the walk allocated for, as toString does, unlinked the
// entries whose keys died, and the walk went on from its entry's next,
// which still led to them, to keys already freed. The map is marked again
// where a collection might otherwise skip it: an old map in a minor
// collection, or one an incremental cycle has already scanned
struct AutoWalk
{
Hash *hash;
AutoWalk(Hash *inHash) : hash(inHash) { hash->walks++; }
AutoWalk(Hash *inHash) : hash(inHash)
{
hash->walks++;
if (Element::WeakKeys)
HX_OBJ_WB_PESSIMISTIC_GET(hash);
}
~AutoWalk() { hash->walks--; }
};

Expand Down Expand Up @@ -1104,14 +1115,16 @@ struct Hash : public HashBase< typename ELEMENT::Key >


// Mark ...
// inStrong marks the keys and values of a weak map too: see AutoWalk
struct HashMarker
{
hx::MarkContext *__inCtx;
HashMarker(hx::MarkContext *ctx) : __inCtx(ctx) { }
bool strong;
HashMarker(hx::MarkContext *ctx, bool inStrong) : __inCtx(ctx), strong(!Hash::Element::WeakKeys || inStrong) { }
void operator()(typename Hash::Element *inElem)
{
HX_MARK_ARRAY(inElem);
if (!Hash::Element::WeakKeys)
if (strong)
{
HX_MARK_MEMBER(inElem->key);
HX_MARK_MEMBER(inElem->value);
Expand All @@ -1127,14 +1140,14 @@ struct Hash : public HashBase< typename ELEMENT::Key >
if (size > 256 && hx::IncrementalRange(this,IncrementalScan,__inCtx)) return;
#endif

HashMarker marker(__inCtx);
HashMarker marker(__inCtx, walks!=0);
iterateBuckets(marker);
}

#ifdef HXCPP_GC_INCREMENTAL
static bool IncrementalScan(hx::Object *inOwner, size_t &ioBucket, size_t &ioItem, hx::MarkContext *__inCtx) {
Hash *hash = static_cast<Hash *>(inOwner);
HashMarker marker(__inCtx);
HashMarker marker(__inCtx, hash->walks!=0);
Element *element = reinterpret_cast<Element *>(ioItem);
unsigned int work = 0;
while (ioBucket < static_cast<size_t>(hash->bucketCount) && work < 256) {
Expand Down
18 changes: 9 additions & 9 deletions src/hx/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ struct Deque : public Array_obj<Dynamic>
__hxcpp_gc_safe_point();
if (!inMutex.TryLock())
{
hx::EnterGCFreeZone();
// Keeps a zone the caller is in, as Mutex does
hx::AutoGCFreeZone zone;
inMutex.Lock();
hx::ExitGCFreeZone();
}
}

Expand Down Expand Up @@ -165,9 +165,10 @@ struct Deque : public Array_obj<Dynamic>
{
mSemaphore.Reset();
mMutex.Unlock();
hx::EnterGCFreeZone();
mSemaphore.Wait();
hx::ExitGCFreeZone();
{
hx::AutoGCFreeZone zone;
mSemaphore.Wait();
}
lockFor(mMutex);
}
}
Expand Down Expand Up @@ -204,10 +205,9 @@ struct Deque : public Array_obj<Dynamic>
lockFor(mSemaphore.mMutex);
if (inBlock && !hasItems())
{
hx::EnterGCFreeZone();
hx::AutoGCFreeZone zone;
while(!hasItems())
mSemaphore.QWait();
hx::ExitGCFreeZone();
}
Dynamic result = popHead();
if (hasItems())
Expand Down Expand Up @@ -459,12 +459,12 @@ class hxLock : public hx::Object
return false;
}

hx::EnterGCFreeZone();
// Keeps a zone the caller is in, as Mutex does
hx::AutoGCFreeZone zone;
if (inTimeout<0)
mNotEmpty.Wait( );
else
mNotEmpty.WaitSeconds(wait);
hx::ExitGCFreeZone();
}
}
void Release()
Expand Down
14 changes: 13 additions & 1 deletion src/hx/cppia/ArrayBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,14 @@ struct ArraySetter : public ArrayBuiltinBase
switch((int)FUNC::op)
{
case aoMult:
case aoDiv:
case aoSub:
// Int elements stay in Int arithmetic, which wraps as compiled
// code does: through a Float, a result past the Int range
// converted to -2147483648
rightHandType = elemType == etInt ? etInt : etFloat;
break;

case aoDiv:
case aoMod:
rightHandType = etFloat;
break;
Expand Down Expand Up @@ -1260,7 +1266,12 @@ struct ArrayBuiltin : public ArrayBuiltinBase

static hx::Object *SLJIT_CALL runConcat( Array_obj<ELEM> *inArray, Array_obj<ELEM> *inOther )
{
// A null array to append throws: the exception becomes the script's
// pending one, which the code after the call checks
TRY_NATIVE
return inArray->concat(inOther).mPtr;
CATCH_NATIVE
return 0;
}


Expand Down Expand Up @@ -1891,6 +1902,7 @@ struct ArrayBuiltin : public ArrayBuiltinBase
genNullReferenceExceptionCheck(compiler, thisVal);
args[0]->genCode(compiler, sJitArg1.as(jtPointer), etObject);
compiler->callNative( (void *)runConcat, thisVal, sJitArg1.as(jtPointer));
compiler->checkException();
compiler->convertReturnReg(etObject, inDest, destType);
break;
}
Expand Down
Loading
Loading