From ebbe7696c76f6be50d35e3466609c3ae0d426154 Mon Sep 17 00:00:00 2001 From: tevador Date: Wed, 9 Oct 2019 19:49:54 +0200 Subject: [PATCH] Fix examples --- src/tests/api-example1.c | 5 +++-- src/tests/api-example2.cpp | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/tests/api-example1.c b/src/tests/api-example1.c index f45d54b..e5f8526 100644 --- a/src/tests/api-example1.c +++ b/src/tests/api-example1.c @@ -6,9 +6,10 @@ int main() { const char myInput[] = "RandomX example input"; char hash[RANDOMX_HASH_SIZE]; - randomx_cache *myCache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT); + randomx_flags flags = randomx_get_flags(); + randomx_cache *myCache = randomx_alloc_cache(flags); randomx_init_cache(myCache, &myKey, sizeof myKey); - randomx_vm *myMachine = randomx_create_vm(RANDOMX_FLAG_DEFAULT, myCache, NULL); + randomx_vm *myMachine = randomx_create_vm(flags, myCache, NULL); randomx_calculate_hash(myMachine, &myInput, sizeof myInput, hash); diff --git a/src/tests/api-example2.cpp b/src/tests/api-example2.cpp index 5b3757e..610aaa8 100644 --- a/src/tests/api-example2.cpp +++ b/src/tests/api-example2.cpp @@ -8,14 +8,17 @@ int main() { const char myInput[] = "RandomX example input"; char hash[RANDOMX_HASH_SIZE]; - randomx_cache *myCache = randomx_alloc_cache((randomx_flags)(RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES)); + randomx_flags flags = randomx_get_flags(); + flags |= RANDOMX_FLAG_LARGE_PAGES; + flags |= RANDOMX_FLAG_FULL_MEM; + randomx_cache *myCache = randomx_alloc_cache(flags); if (myCache == nullptr) { std::cout << "Cache allocation failed" << std::endl; return 1; } randomx_init_cache(myCache, myKey, sizeof myKey); - randomx_dataset *myDataset = randomx_alloc_dataset(RANDOMX_FLAG_LARGE_PAGES); + randomx_dataset *myDataset = randomx_alloc_dataset(flags); if (myDataset == nullptr) { std::cout << "Dataset allocation failed" << std::endl; return 1; @@ -28,7 +31,7 @@ int main() { t2.join(); randomx_release_cache(myCache); - randomx_vm *myMachine = randomx_create_vm((randomx_flags)(RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_LARGE_PAGES), nullptr, myDataset); + randomx_vm *myMachine = randomx_create_vm(flags, nullptr, myDataset); if (myMachine == nullptr) { std::cout << "Failed to create a virtual machine" << std::endl; return 1; @@ -40,7 +43,7 @@ int main() { randomx_release_dataset(myDataset); for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) - std::cout << std::hex << ((int)hash[i] & 0xff); + std::cout << std::hex << std::setw(2) << std::setfill('0') << ((int)hash[i] & 0xff); std::cout << std::endl;