-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
25 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,9 @@ static int done_pdl_main_pthreadID_init = 0; | |
* altogether later | ||
*/ | ||
static char* pdl_pthread_barf_msgs = NULL; | ||
static int pdl_pthread_barf_msgs_len = 0; | ||
static size_t pdl_pthread_barf_msgs_len = 0; | ||
static char* pdl_pthread_warn_msgs = NULL; | ||
static int pdl_pthread_warn_msgs_len = 0; | ||
static size_t pdl_pthread_warn_msgs_len = 0; | ||
|
||
#endif | ||
|
||
|
@@ -408,39 +408,26 @@ char pdl_pthread_main_thread() { | |
int pdl_pthread_barf_or_warn(const char* pat, int iswarn, va_list *args) | ||
{ | ||
char** msgs; | ||
int* len; | ||
size_t* len; | ||
|
||
/* Don't do anything if we are in the main pthread */ | ||
if (pdl_pthread_main_thread()) return 0; | ||
|
||
if(iswarn) | ||
{ | ||
msgs = &pdl_pthread_warn_msgs; | ||
len = &pdl_pthread_warn_msgs_len; | ||
len = &pdl_pthread_warn_msgs_len; | ||
} | ||
else | ||
{ | ||
msgs = &pdl_pthread_barf_msgs; | ||
len = &pdl_pthread_barf_msgs_len; | ||
len = &pdl_pthread_barf_msgs_len; | ||
} | ||
|
||
/* In the chunk I'm adding I need to store the actual data and trailing newline so add 1. */ | ||
int extralen = vsnprintf(NULL, 0, pat, *args) + 1; | ||
size_t extralen = vsnprintf(NULL, 0, pat, *args) + 1; | ||
pdl_pthread_realloc((void **)msgs, *len + extralen + 1); | ||
// add the new complaint to the list | ||
{ | ||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | ||
pthread_mutex_lock( &mutex ); | ||
/* (For windows, we first #undef realloc | ||
so that the system realloc function is used instead of the PerlMem_realloc | ||
macro. This currently works fine, though could conceivably require some | ||
tweaking in the future if it's found to cause any problem.) */ | ||
#ifdef WIN32 | ||
#undef realloc | ||
#endif | ||
/* FIXME: Common realloc mistake: 'msgs' nulled but not freed upon failure */ | ||
*msgs = realloc(*msgs, *len + extralen + 1); | ||
pthread_mutex_unlock( &mutex ); | ||
} | ||
vsnprintf( *msgs + *len, extralen + 1, pat, *args); | ||
/* update the length-so-far. This does NOT include the trailing '\0' */ | ||
*len += extralen; | ||
|
@@ -459,6 +446,23 @@ int pdl_pthread_barf_or_warn(const char* pat, int iswarn, va_list *args) | |
return 0; | ||
} | ||
|
||
/* void ** so update the possibly-global pointer within mutex */ | ||
void *pdl_pthread_realloc(void **p, size_t len) { | ||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | ||
pthread_mutex_lock( &mutex ); | ||
/* (For windows, we first #undef realloc | ||
so that the system realloc function is used instead of the PerlMem_realloc | ||
macro. This currently works fine, though could conceivably require some | ||
tweaking in the future if it's found to cause any problem.) */ | ||
#ifdef WIN32 | ||
#undef realloc | ||
#endif | ||
/* FIXME: Common realloc mistake: 'msgs' nulled but not freed upon failure */ | ||
*p = realloc(*p, len); | ||
pthread_mutex_unlock( &mutex ); | ||
return *p; | ||
} | ||
|
||
/* copied from [email protected]:git/git.git 2.34-ish thread-util.c */ | ||
/* changed GIT_WINDOWS_NATIVE to WIN32 */ | ||
#if defined(hpux) || defined(__hpux) || defined(_hpux) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters