Skip to content

Commit

Permalink
Merge branch 'master' into ci-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan63 committed Oct 12, 2024
2 parents 3c1498a + 66b8f88 commit bce93ec
Show file tree
Hide file tree
Showing 38 changed files with 682 additions and 345 deletions.
81 changes: 46 additions & 35 deletions include/hx/GC.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,12 @@ class ImmixAllocator
{
#ifdef HXCPP_GC_NURSERY

#ifdef HXCPP_ALIGN_ALLOC
// make sure buffer is 8-byte aligned
unsigned char *buffer = alloc->spaceFirst + ( (size_t)alloc->spaceFirst & 4 );
#else
unsigned char *buffer = alloc->spaceFirst;
#endif
unsigned char *end = buffer + (inSize + 4);

if ( end > alloc->spaceOversize )
Expand All @@ -381,48 +386,54 @@ class ImmixAllocator
((unsigned int *)buffer)[-1] = inSize;
}

#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
hx::GCOnNewPointer(buffer);
#endif

#ifdef HXCPP_TELEMETRY
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
#endif

return buffer;

#else
#ifndef HXCPP_ALIGN_ALLOC
// Inline the fast-path if we can
// We know the object can hold a pointer (vtable) and that the size is int-aligned
int start = alloc->spaceStart;
int end = start + sizeof(int) + inSize;

if ( end <= alloc->spaceEnd )
{
alloc->spaceStart = end;

unsigned int *buffer = (unsigned int *)(alloc->allocBase + start);

int startRow = start>>IMMIX_LINE_BITS;

alloc->allocStartFlags[ startRow ] |= gImmixStartFlag[start&127];

if (inContainer)
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
hx::gMarkIDWithContainer;
else
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
hx::gMarkID;

#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
hx::GCOnNewPointer(buffer);
#endif

#ifdef HXCPP_TELEMETRY
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
#endif
return buffer;
}
#endif // HXCPP_ALIGN_ALLOC
// Inline the fast-path if we can
// We know the object can hold a pointer (vtable) and that the size is int-aligned
int start = alloc->spaceStart;
#ifdef HXCPP_ALIGN_ALLOC
// Ensure odd alignment in 8 bytes
start += 4 - (start & 4);
#endif
int end = start + sizeof(int) + inSize;

if ( end <= alloc->spaceEnd )
{
alloc->spaceStart = end;

unsigned int *buffer = (unsigned int *)(alloc->allocBase + start);

int startRow = start>>IMMIX_LINE_BITS;

alloc->allocStartFlags[ startRow ] |= gImmixStartFlag[start&127];

if (inContainer)
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
hx::gMarkIDWithContainer;
else
*buffer++ = (( (end+(IMMIX_LINE_LEN-1))>>IMMIX_LINE_BITS) -startRow) |
(inSize<<IMMIX_ALLOC_SIZE_SHIFT) |
hx::gMarkID;

#if defined(HXCPP_GC_CHECK_POINTER) && defined(HXCPP_GC_DEBUG_ALWAYS_MOVE)
hx::GCOnNewPointer(buffer);
#endif

#ifdef HXCPP_TELEMETRY
__hxt_gc_new((hx::StackContext *)alloc,buffer, inSize, inName);
#endif
return buffer;
}

// Fall back to external method
void *result = alloc->CallAlloc(inSize, inContainer ? IMMIX_ALLOC_IS_CONTAINER : 0);
Expand Down
40 changes: 24 additions & 16 deletions include/hx/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,28 @@ struct HxMutex
pthread_mutexattr_t mta;
pthread_mutexattr_init(&mta);
pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE);
mValid = pthread_mutex_init(&mMutex,&mta) ==0;
mMutex = new pthread_mutex_t();
mValid = pthread_mutex_init(mMutex,&mta) ==0;
}
~HxMutex() { if (mValid) pthread_mutex_destroy(&mMutex); }
void Lock() { pthread_mutex_lock(&mMutex); }
void Unlock() { pthread_mutex_unlock(&mMutex); }
bool TryLock() { return !pthread_mutex_trylock(&mMutex); }
~HxMutex()
{
if (mValid)
pthread_mutex_destroy(mMutex);
delete mMutex;
}
void Lock() { pthread_mutex_lock(mMutex); }
void Unlock() { pthread_mutex_unlock(mMutex); }
bool TryLock() { return !pthread_mutex_trylock(mMutex); }
bool IsValid() { return mValid; }
void Clean()
{
if (mValid)
pthread_mutex_destroy(&mMutex);
pthread_mutex_destroy(mMutex);
mValid = 0;
}

bool mValid;
pthread_mutex_t mMutex;
pthread_mutex_t *mMutex;
};

#define THREAD_FUNC_TYPE void *
Expand Down Expand Up @@ -196,13 +202,14 @@ struct HxSemaphore
{
mSet = false;
mValid = true;
pthread_cond_init(&mCondition,0);
mCondition = new pthread_cond_t();
pthread_cond_init(mCondition,0);
}
~HxSemaphore()
{
if (mValid)
{
pthread_cond_destroy(&mCondition);
pthread_cond_destroy(mCondition);
}
}
// For autolock
Expand All @@ -213,13 +220,13 @@ struct HxSemaphore
if (!mSet)
{
mSet = true;
pthread_cond_signal( &mCondition );
pthread_cond_signal( mCondition );
}
}
void QSet()
{
mSet = true;
pthread_cond_signal( &mCondition );
pthread_cond_signal( mCondition );
}
void Reset()
{
Expand All @@ -231,14 +238,14 @@ struct HxSemaphore
{
AutoLock lock(mMutex);
while( !mSet )
pthread_cond_wait( &mCondition, &mMutex.mMutex );
pthread_cond_wait( mCondition, mMutex.mMutex );
mSet = false;
}
// when we already hold the mMutex lock ...
void QWait()
{
while( !mSet )
pthread_cond_wait( &mCondition, &mMutex.mMutex );
pthread_cond_wait( mCondition, mMutex.mMutex );
mSet = false;
}
// Returns true if the wait was success, false on timeout.
Expand All @@ -262,7 +269,7 @@ struct HxSemaphore

int result = 0;
// Wait for set to be true...
while( !mSet && (result=pthread_cond_timedwait( &mCondition, &mMutex.mMutex, &spec )) != ETIMEDOUT)
while( !mSet && (result=pthread_cond_timedwait( mCondition, mMutex.mMutex, &spec )) != ETIMEDOUT)
{
if (result!=0)
{
Expand Down Expand Up @@ -290,13 +297,14 @@ struct HxSemaphore
if (mValid)
{
mValid = false;
pthread_cond_destroy(&mCondition);
pthread_cond_destroy(mCondition);
}
delete mCondition;
}


HxMutex mMutex;
pthread_cond_t mCondition;
pthread_cond_t *mCondition;
bool mSet;
bool mValid;
};
Expand Down
2 changes: 1 addition & 1 deletion include/hxcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

// Must allign allocs to 8 bytes to match floating point requirement?
// Ints must br read on 4-byte boundary
#if defined(EMSCRIPTEN) || defined(GCW0)
#if (!defined(HXCPP_ALIGN_FLOAT) && (defined(EMSCRIPTEN) || defined(GCW0)) )
#define HXCPP_ALIGN_ALLOC
#endif

Expand Down
File renamed without changes.
File renamed without changes.
113 changes: 113 additions & 0 deletions project/thirdparty/mbedtls-files.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<xml>

<set name="MBEDTLS_DIR" value="${HXCPP}/project/thirdparty/mbedtls-2.28.2" />

<files id="mbedtls">
<depend name="${this_dir}/mbedtls-files.xml" dateOnly="true" />
<cache value="true" asLibrary="true" />

<include name="${this_dir}/mbedtls-flags.xml" />

<compilerflag value="-std=c99" unless="MSVC_VER" />

<file name="${MBEDTLS_DIR}/library/aes.c" />
<file name="${MBEDTLS_DIR}/library/aesni.c" />
<file name="${MBEDTLS_DIR}/library/arc4.c" />
<file name="${MBEDTLS_DIR}/library/aria.c" />
<file name="${MBEDTLS_DIR}/library/asn1parse.c" />
<file name="${MBEDTLS_DIR}/library/asn1write.c" />
<file name="${MBEDTLS_DIR}/library/base64.c" />
<file name="${MBEDTLS_DIR}/library/bignum.c" />
<file name="${MBEDTLS_DIR}/library/blowfish.c" />
<file name="${MBEDTLS_DIR}/library/camellia.c" />
<file name="${MBEDTLS_DIR}/library/ccm.c" />
<file name="${MBEDTLS_DIR}/library/chacha20.c" />
<file name="${MBEDTLS_DIR}/library/chachapoly.c" />
<file name="${MBEDTLS_DIR}/library/cipher.c" />
<file name="${MBEDTLS_DIR}/library/cipher_wrap.c" />
<file name="${MBEDTLS_DIR}/library/constant_time.c" />
<file name="${MBEDTLS_DIR}/library/cmac.c" />
<file name="${MBEDTLS_DIR}/library/ctr_drbg.c" />
<file name="${MBEDTLS_DIR}/library/des.c" />
<file name="${MBEDTLS_DIR}/library/dhm.c" />
<file name="${MBEDTLS_DIR}/library/ecdh.c" />
<file name="${MBEDTLS_DIR}/library/ecdsa.c" />
<file name="${MBEDTLS_DIR}/library/ecjpake.c" />
<file name="${MBEDTLS_DIR}/library/ecp.c" />
<file name="${MBEDTLS_DIR}/library/ecp_curves.c" />
<file name="${MBEDTLS_DIR}/library/entropy.c" />
<file name="${MBEDTLS_DIR}/library/entropy_poll.c" />
<file name="${MBEDTLS_DIR}/library/error.c" />
<file name="${MBEDTLS_DIR}/library/gcm.c" />
<file name="${MBEDTLS_DIR}/library/havege.c" />
<file name="${MBEDTLS_DIR}/library/hkdf.c" />
<file name="${MBEDTLS_DIR}/library/hmac_drbg.c" />
<file name="${MBEDTLS_DIR}/library/md.c" />
<file name="${MBEDTLS_DIR}/library/md2.c" />
<file name="${MBEDTLS_DIR}/library/md4.c" />
<file name="${MBEDTLS_DIR}/library/md5.c" />
<file name="${MBEDTLS_DIR}/library/memory_buffer_alloc.c" />
<file name="${MBEDTLS_DIR}/library/mps_reader.c" />
<file name="${MBEDTLS_DIR}/library/mps_trace.c" />
<file name="${MBEDTLS_DIR}/library/nist_kw.c" />
<file name="${MBEDTLS_DIR}/library/oid.c" />
<file name="${MBEDTLS_DIR}/library/padlock.c" />
<file name="${MBEDTLS_DIR}/library/pem.c" />
<file name="${MBEDTLS_DIR}/library/pk.c" />
<file name="${MBEDTLS_DIR}/library/pk_wrap.c" />
<file name="${MBEDTLS_DIR}/library/pkcs12.c" />
<file name="${MBEDTLS_DIR}/library/pkcs5.c" />
<file name="${MBEDTLS_DIR}/library/pkparse.c" />
<file name="${MBEDTLS_DIR}/library/pkwrite.c" />
<file name="${MBEDTLS_DIR}/library/platform.c" />
<file name="${MBEDTLS_DIR}/library/platform_util.c" />
<file name="${MBEDTLS_DIR}/library/poly1305.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_aead.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_cipher.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_client.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_driver_wrappers.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_ecp.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_hash.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_mac.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_rsa.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_se.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_slot_management.c" />
<file name="${MBEDTLS_DIR}/library/psa_crypto_storage.c" />
<file name="${MBEDTLS_DIR}/library/psa_its_file.c" />
<file name="${MBEDTLS_DIR}/library/ripemd160.c" />
<file name="${MBEDTLS_DIR}/library/rsa.c" />
<file name="${MBEDTLS_DIR}/library/rsa_internal.c" />
<file name="${MBEDTLS_DIR}/library/sha1.c" />
<file name="${MBEDTLS_DIR}/library/sha256.c" />
<file name="${MBEDTLS_DIR}/library/sha512.c" />
<file name="${MBEDTLS_DIR}/library/threading.c" />
<file name="${MBEDTLS_DIR}/library/timing.c" />
<file name="${MBEDTLS_DIR}/library/version.c" />
<file name="${MBEDTLS_DIR}/library/version_features.c" />
<file name="${MBEDTLS_DIR}/library/xtea.c" />

<file name="${MBEDTLS_DIR}/library/certs.c" />
<file name="${MBEDTLS_DIR}/library/pkcs11.c" />
<file name="${MBEDTLS_DIR}/library/x509.c" />
<file name="${MBEDTLS_DIR}/library/x509_create.c" />
<file name="${MBEDTLS_DIR}/library/x509_crl.c" />
<file name="${MBEDTLS_DIR}/library/x509_crt.c" />
<file name="${MBEDTLS_DIR}/library/x509_csr.c" />
<file name="${MBEDTLS_DIR}/library/x509write_crt.c" />
<file name="${MBEDTLS_DIR}/library/x509write_csr.c" />

<file name="${MBEDTLS_DIR}/library/debug.c" />
<file name="${MBEDTLS_DIR}/library/net_sockets.c" />
<file name="${MBEDTLS_DIR}/library/ssl_cache.c" />
<file name="${MBEDTLS_DIR}/library/ssl_ciphersuites.c" />
<file name="${MBEDTLS_DIR}/library/ssl_cli.c" />
<file name="${MBEDTLS_DIR}/library/ssl_cookie.c" />
<file name="${MBEDTLS_DIR}/library/ssl_msg.c" />
<file name="${MBEDTLS_DIR}/library/ssl_srv.c" />
<file name="${MBEDTLS_DIR}/library/ssl_ticket.c" />
<file name="${MBEDTLS_DIR}/library/ssl_tls.c" />
<file name="${MBEDTLS_DIR}/library/ssl_tls13_keys.c" />
</files>

</xml>
9 changes: 9 additions & 0 deletions project/thirdparty/mbedtls-flags.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<xml>

<depend name="${HXCPP}/project/thirdparty/mbedtls-flags.xml" dateOnly="true" />

<compilerflag value="-I${HXCPP}/project/thirdparty/mbedtls-2.28.2/include" />
<compilerflag value="-I${HXCPP}/project/thirdparty/config/mbedtls/include" />
<compilerflag value="-DMBEDTLS_USER_CONFIG_FILE=&lt;mbedtls_config.h&gt;" />

</xml>
2 changes: 1 addition & 1 deletion src/Dynamic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class PointerData : public hx::Object
String toString()
{
char buf[100];
sprintf(buf,"Pointer(%p)", mValue);
snprintf(buf,sizeof(buf),"Pointer(%p)", mValue);
return String(buf);
}
String __ToString() const { return String(mValue); }
Expand Down
2 changes: 1 addition & 1 deletion src/hx/CFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Abstract_obj : public Object
return _hxcpp_toString( Dynamic(this) );

char buffer[40];
sprintf(buffer,"0x%p", mHandle);
snprintf(buffer,sizeof(buffer),"0x%p", mHandle);

return HX_CSTRING("Abstract(") +
__hxcpp_get_kind(this) +
Expand Down
7 changes: 5 additions & 2 deletions src/hx/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ static void CriticalErrorHandler(String inErr, bool allowFixup)
return;
#endif

#ifdef HXCPP_STACK_TRACE
hx::StackContext *ctx = hx::StackContext::getCurrent();
ctx->beginCatch(true);
#endif

if (sCriticalErrorHandler!=null())
sCriticalErrorHandler(inErr);

#ifdef HXCPP_STACK_TRACE
hx::StackContext *ctx = hx::StackContext::getCurrent();
ctx->beginCatch(true);
ctx->dumpExceptionStack();
#endif

Expand Down
Loading

0 comments on commit bce93ec

Please sign in to comment.