Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make CHECK_STATUS_PTHREAD signal-safe
14 changes: 12 additions & 2 deletions Python/thread_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,19 @@ typedef struct {
pthread_mutex_t mut;
} pthread_lock;

#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why casting strlen() to int?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, I copied this macro from traceback.c.


#define CHECK_STATUS(name) if (status != 0) { perror(name); error = 1; }
#define CHECK_STATUS_PTHREAD(name) if (status != 0) { fprintf(stderr, \
"%s: %s\n", name, strerror(status)); error = 1; }
/* CHECK_STATUS_PTHREAD is async-signal-safe */
#define CHECK_STATUS_PTHREAD(name) \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never understood the purpose of these functions. Do we really need these checks? Why not replacing them with an assertion?

If you want to get them at runtime, maybe call Py_FatalError()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I'm inclined not to remove them right now.
OTOH, this whole PR may be made obsolete by #2408.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I'm inclined not to remove them right now. OTOH, this whole PR may be made obsolete by #2408.

Oh no, please finish your work. I like the idea of more reliable locks :-)

if (status != 0) { \
int _stderr_fd = 2; \
PUTS(_stderr_fd, name); \
PUTS(_stderr_fd, ": failed with status "); \
_Py_DumpDecimal(_stderr_fd, (unsigned long) status); \
PUTS(_stderr_fd, "\n"); \
error = 1; \
}

/*
* Initialization.
Expand Down