static_link
test.TestkLeak.hx
package test;
import haxe.crypto.Hmac;
import haxe.io.Bytes;
class TestLeak
{
static function main(){
trace('Library initialized');
}
public static function testHMac():Bool{
var content:String = "test.,][|";
var height:Int = 1;
var hmacKeyBytes:Bytes = Bytes.alloc(4);
hmacKeyBytes.setInt32(0, height);
var hmacBytes:Bytes = (new Hmac(HashMethod.SHA256)).make(hmacKeyBytes, Bytes.ofString(content));
var hmacHex:String = hmacBytes.toHex();
var hmacString:String = hmacBytes.toString();
//trace("Hex:", hmacHex, "String:", hmacString);
return hmacHex.length==64;
}
}
Host.cpp
#include <stdio.h>
#include <iostream>
#include <memory>
#include <windows.h>
#include <thread>
#include <stdlib.h>
#include <functional>
#include <ctime>
#include "HxcppConfig.h"
#include "test/TestLeak.h"
extern "C" const char *hxRunLibrary();
extern "C" void hxcpp_set_top_of_stack();
std::clock_t start;
double duration;
void innerLoop(){
int inTop=0;
hx::SetTopOfStack((int *)&inTop, true);
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
bool result = ::test::TestLeak::testHMac();
printf("duration:%f, threadId:%d\n", duration);
hx::EnterGCFreeZone();
Sleep(1);
hx::ExitGCFreeZone();
hx::SetTopOfStack((int *)0,true);
}
void calculationLoop(){
while(true) innerLoop(threadId);
}
int calculation1(){
calculationLoop();
return 1;
};
int main(int argc, char* argv[]){
hxcpp_set_top_of_stack();
const char *err = hxRunLibrary();
if (err) {
// Unhandled exceptions ...
fprintf(stderr,"Error %s\n", err );
return -1;
}
std::thread calculator1 (calculation1);
calculator1.join();
return 1;
}
Thread paused after constant times call, and gdb prints 3 threads exit with code 0, which were created before hxRunLibrary() (guess by output), and no any output until interrput.