<pre style='margin:0'>
Christopher Nielsen (mascguy) pushed a commit to branch master
in repository macports-legacy-support.
</pre>
<p><a href="https://github.com/macports/macports-legacy-support/commit/34e47c0a3bafc1693ce83d24f03264ba05cb7c86">https://github.com/macports/macports-legacy-support/commit/34e47c0a3bafc1693ce83d24f03264ba05cb7c86</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 34e47c0a3bafc1693ce83d24f03264ba05cb7c86
</span>Author: Marcus Calhoun-Lopez <mcalhoun@macports.org>
AuthorDate: Tue May 7 05:44:59 2024 -0700
<span style='display:block; white-space:pre;color:#404040;'> add test for bug in pthread_get_stacksize_np
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> see https://github.com/rust-lang/rust/issues/43347
</span><span style='display:block; white-space:pre;color:#404040;'> see https://trac.macports.org/ticket/68015
</span>---
test/test_pthread_get_stacksize_np.c | 52 ++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/test/test_pthread_get_stacksize_np.c b/test/test_pthread_get_stacksize_np.c
</span>new file mode 100644
<span style='display:block; white-space:pre;color:#808080;'>index 0000000..b4bf074
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>--- /dev/null
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/test/test_pthread_get_stacksize_np.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -0,0 +1,52 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <pthread.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <assert.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stdio.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stddef.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <unistd.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+size_t stack_size_main = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+size_t stack_size_thread = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+size_t stack_size_detached = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+void *thread_function(void *arg) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( !pthread_main_np() && "Unknown error, thread should *not* be main" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ stack_size_thread = pthread_get_stacksize_np(pthread_self());
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( stack_size_thread && "Unknown error, stack size should *not* be zero" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+void *detached_function(void *arg) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( !pthread_main_np() && "Unknown error, thread should *not* be main" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ stack_size_detached = pthread_get_stacksize_np(pthread_self());
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( stack_size_detached && "Unknown error, stack size should *not* be zero" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int main()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ pthread_t thread;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ pthread_t thread_detached;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ pthread_attr_t attr;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( pthread_main_np() && "Unknown error, thread should be main." );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ stack_size_main = pthread_get_stacksize_np(pthread_self());
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( !pthread_create(&thread, NULL, thread_function, NULL) && "Unknown error, cannot create first thread" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ pthread_join(thread, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( !pthread_attr_init(&attr) && "Unknown error, cannot initialises attribute" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( !pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) && "Unknown error, cannot set detached state" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( !pthread_create(&thread_detached, &attr, detached_function, NULL) && "Unknown error, cannot create second thread" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( !pthread_attr_destroy(&attr) && "Unknown error, cannot destroy attribute" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ usleep(1000);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while( !stack_size_detached );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( stack_size_thread == stack_size_detached && "Unknown Error, non-main threads are assumed to have the same stack size" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ assert( stack_size_main > stack_size_thread && "Default stack size for main thread is the same as the default stack size of non-main threads" );
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("Stack size for the non-main thread (%zu) is larger than for non-main threads (%zu), which is expected.\n", stack_size_main, stack_size_thread);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span></pre><pre style='margin:0'>
</pre>