From Ye Wison to ~sircmpwn/hare-users
Thanks for all the detailed replies, very appreciated:) I'm porting my previous production code from C to hare (for learning and testing purposes BEFORE migrating from C to Hare), so pthread in C works fine without any problem (I mean on FreeBSD, didn't test it on Linux yet), so I doubt that the 'weird behaviors' related to Linux (specific to Alpine Linux) or Hare impl. But of course, I will try on another distro to confirm later:) Btw, `C wrapper function to create pthread object on the heap and use in hare function (binding)` works (tested). But consider what you said before (stdlib not designed for multithreading) and the previous `cpp issues` ...that's also a real thing I need to think about.
From Ye Wison to ~sircmpwn/hare-users
Yup, done, it works now, many thanks;) On Sat, Jan 11, 2025 at 12:36 PM Bor Grošelj Simić <bgs@turminal.net> wrote: > > You need to update your hare compiler. There was a brief period before harec > version 880d0539bc3bef2f4346209cf57e30b0462d7c4e when hare-ev was broken on > amd64.
From Ye Wison to ~sircmpwn/hare-users
Just gave it a try with `hare-ev`, but it fails to run the example. My Alpine VM: Linux my-alpine 6.12.1-0-lts #1-Alpine SMP PREEMPT_DYNAMIC 2024-11-25 16:25:11 x86_64 Linux ```bash /home/wison/temp/hare-ev/cmd/tcpserv HAREPATH=./src:/usr/local/src/hare/stdlib:/usr/local/src/hare/third-party hare run main.ha # 0/7 tasks completed (0%) # Assertion failed: (final->storage == STORAGE_STRUCT && final->struct_union.packed) || type->size == SIZE_UNDEFINED || type->size == 0 || type->size % type->align == 0 (src/qtype.c: aggregate_lookup: 148)
From Ye Wison to ~sircmpwn/hare-users
Thanks for the quick reply from you guys ("Drew DeVault" and "Bor Grošelj Simić"), very appreciated. So, I end up with the following considerations/solutions and questions. 1. Write the C wrapper functions to init the `pthread_xxx` struct instance in the right way and return a pointer on the heap, something like this: ```c #include <pthread.h> pthread_attr_t *init_pthread_attr(void) { return malloc(sizeof(pthread_attr_t)); }
From Ye Wison to ~sircmpwn/hare-users
I was working on `pthread` stuff before, below's the bindings I wrote (a long time ago) and it works for a while: ```hare export def PTHREAD_CREATE_JOINABLE: int = 0; export def PTHREAD_CREATE_DETACHED: int = 1; export type pthread_attr_t = nullable *opaque; export @symbol("pthread_attr_init") fn pthread_attr_init(attr: *pthread_attr_t) int; ``` And the following sample code works:
From Ye Wison to ~sircmpwn/hare-users
Actually, maybe simply swapping the `hare test` output and `fmt::println` would be an easy fix/improvement? Let's me show you my case: When I run `hare test`, I got the following output: ```bash Running 50/50 tests: ucp::create_body_payload_should_work.............................PASS in 0.000012060s ucp::create_body_payload_should_fail.............................PASS in 0.000175381s
From Ye Wison to ~sircmpwn/hare-users
Ok, thanks for the quick reply, very appreciated:) 2 things: 1. Yes, if I allocate `assert_err_buf` on the heap, it works: Minimal demo code: ```hare @test fn just_a_test() void = { const expected_hex_string = "FAB0AA000000CAFA"; let assert_err_buf: memio::stream = memio::dynamic(); // Can't close it, as it needs to live outside the function scope. // defer io::close(&assert_err_buf)!;
From Ye Wison to ~sircmpwn/hare-users
I need to customize the `assert` fail message in my project, but it doesn't seems to work except the error message is a string literal. Minimal demo code: ```hare @test fn just_a_test() void = { const expected_hex_string = "FAB0AA000000CAFA"; const assert_err_buf: [1024]u8 = [0x00...]; const assert_err_msg = fmt::bsprintf( &assert_err_buf, "encoded frame bytes not equal to '{}'", expected_hex_string);
From Ye Wison to ~sircmpwn/hare-users
I'm doing a performance test for my protocol parser, I found that the `alloc` or `rt::malloc` accidentally consume memory, it causes the program consume starting from 2MB, that's why I wrote the following test to prove my guess: ```hare use rt; use time; export fn main() void = { // 1. Use `alloc` // for(let index=0z; index < 1000000; index +=1) {
From Ye Wison to ~sircmpwn/hare-users
Thanks for the pointer, but it doesn't work for my case:) I tried your above code, but it didn't skip the particular test cases, instead, it stopped running all test cases, and it showed "No tests run":) Also, when I tried to add few more folder and moved the test file around, then I encount my prev posted question again: xxxxx': `typedef variable $HARE_TD_xxx not set` But if I create a new hare project, import (use) my current hare project (I put it into the `third-party` folder), and run `hare run` and `hare test`, then everything is fine.... I'm trying on Alpine Linux.