diff -r -c Python-2.4a2/Modules/datetimemodule.c Python-2.4a2_fixed/Modules/datetimemodule.c *** Python-2.4a2/Modules/datetimemodule.c Sun Jun 20 22:41:32 2004 --- Python-2.4a2_fixed/Modules/datetimemodule.c Sun Aug 29 14:32:55 2004 *************** *** 2238,2248 **** --- 2238,2253 ---- struct tm *tm; time_t t; PyObject *result = NULL; + struct tm localtime_r_result; t = _PyTime_DoubleToTimet(ts); if (t == (time_t)-1 && PyErr_Occurred()) return NULL; + #ifdef HAVE_LOCALTIME_R + tm = localtime_r(&t, localtime_r_result); + #else tm = localtime(&t); + #endif if (tm) result = PyObject_CallFunction(cls, "iii", tm->tm_year + 1900, diff -r -c Python-2.4a2/Modules/getaddrinfo.c Python-2.4a2_fixed/Modules/getaddrinfo.c *** Python-2.4a2/Modules/getaddrinfo.c Sun Aug 17 21:28:39 2003 --- Python-2.4a2_fixed/Modules/getaddrinfo.c Sun Aug 29 16:08:11 2004 *************** *** 342,347 **** --- 342,349 ---- port = htons((u_short)atoi(servname)); } else { struct servent *sp; + struct servent getservbyname_r_buffer; + char getservbyname_r_char[8192]; char *proto; proto = NULL; *************** *** 359,365 **** --- 361,373 ---- fprintf(stderr, "panic!\n"); break; } + #ifdef HAVE_GETSERVBYNAME_R + getservbyname_r_char[sizeof(getservbyname_r_char)-1]=0; + if ((sp = getservbyname_r(servname, proto, &getservbyname_r_buffer, + getservbyname_r_char, sizeof(getservbyname_r_char)-1)) == NULL) + #else if ((sp = getservbyname(servname, proto)) == NULL) + #endif ERR(EAI_SERVICE); port = sp->s_port; if (pai->ai_socktype == GAI_ANY) { *************** *** 492,497 **** --- 500,510 ---- u_short port = port0 & 0xffff; struct hostent *hp; struct addrinfo *cur; + + char gethostbyaddr_r_char[8192]; + struct addrinfo gethostbyaddr_r_buffer; + int gethostbyaddr_r_error; + int error = 0; #ifdef ENABLE_IPV6 int h_error; *************** *** 500,507 **** --- 513,525 ---- #ifdef ENABLE_IPV6 hp = getipnodebyaddr(addr, gai_afd->a_addrlen, gai_afd->a_af, &h_error); #else + #ifdef HAVE_GETHOSTBYADDR_R + hp = gethostbyaddr_r(addr, gai_afd->a_addrlen, AF_INET, gethostbyaddr_r_buffer, + gethostbyaddr_r_char, sizeof(gethostbyaddr_r_char)-1, &gethostbyaddr_r_error ); + #else hp = gethostbyaddr(addr, gai_afd->a_addrlen, AF_INET); #endif + #endif if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) { GET_AI(cur, gai_afd, hp->h_addr_list[0], port); GET_CANONNAME(cur, hp->h_name); *************** *** 541,546 **** --- 559,568 ---- struct gai_afd *gai_afd; int i, error = 0, h_error; char *ap; + + struct hostent gethostbyname_r_struct; + char gethostbyname_r_char[8192]; + int gethostbyname_r_result; top = NULL; sentinel.ai_next = NULL; *************** *** 552,558 **** --- 574,588 ---- } else hp = getipnodebyname(hostname, af, AI_ADDRCONFIG, &h_error); #else + #ifdef HAVE_GETHOSTBYNAME_5_ARG + // Solaris uses the 5-arg version + hp = gethostbyname_r(hostname, &gethostbyname_r_struct, gethostbyname_r_char, + sizeof(gethostbyname_r_char)-1, &gethostbyname_r_result); + // TODO: Find 3 and 6 arg versions. + #else + // Linux, windows will be safe with the single-arg version. hp = gethostbyname(hostname); + #endif h_error = h_errno; #endif if (hp == NULL) { diff -r -c Python-2.4a2/Modules/posixmodule.c Python-2.4a2_fixed/Modules/posixmodule.c *** Python-2.4a2/Modules/posixmodule.c Tue Jun 15 18:49:58 2004 --- Python-2.4a2_fixed/Modules/posixmodule.c Sun Aug 29 14:52:12 2004 *************** *** 1640,1645 **** --- 1640,1646 ---- PyObject *d, *v; DIR *dirp; struct dirent *ep; + struct dirent readdir_r_buffer; int arg_is_unicode = 1; if (!PyArg_ParseTuple(args, "U:listdir", &v)) { *************** *** 1656,1662 **** --- 1657,1667 ---- PyMem_Free(name); return NULL; } + #ifdef HAVE_READDIR_R + while ((ep = readdir_r(dirp, &readdir_r_buffer)) != NULL) { + #else while ((ep = readdir(dirp)) != NULL) { + #endif if (ep->d_name[0] == '.' && (NAMLEN(ep) == 1 || (ep->d_name[1] == '.' && NAMLEN(ep) == 2))) *************** *** 3139,3148 **** { PyObject *result = NULL; char *name; ! int old_errno = errno; errno = 0; name = getlogin(); if (name == NULL) { if (errno) posix_error(); --- 3144,3169 ---- { PyObject *result = NULL; char *name; ! int old_errno = errno; ! ! // SMH: Is L_cuserid always defined in stdio.h??? ! // should really be getlogin_r_buffer[L_cuserid] ! char getlogin_r_buffer[1024]; ! int getlogin_r_result = 0; errno = 0; + #ifdef HAVE_GETLOGIN_R + getlogin_r_result = getlogin_r(getlogin_r_buffer, sizeof( getlogin_r_buffer)-1 ); + if (getlogin_r_result) { + name = NULL; + } else + { + getlogin_r_buffer[sizeof(getlogin_r_buffer)-1] = 0; + name = buffer; + } + #else name = getlogin(); + #endif if (name == NULL) { if (errno) posix_error(); diff -r -c Python-2.4a2/Modules/timemodule.c Python-2.4a2_fixed/Modules/timemodule.c *** Python-2.4a2/Modules/timemodule.c Tue Aug 3 17:58:55 2004 --- Python-2.4a2_fixed/Modules/timemodule.c Sun Aug 29 15:11:05 2004 *************** *** 391,397 **** --- 391,401 ---- if (tup == NULL) { time_t tt = time(NULL); + #ifdef HAVE_LOCALTIME_R + buf = *localtime_r(&tt, &buf); + #else buf = *localtime(&tt); + #endif } else if (!gettmarg(tup, &buf)) return NULL; *************** *** 497,510 **** --- 501,523 ---- PyObject *tup = NULL; struct tm buf; char *p; + char asctime_r_buffer[200]; if (!PyArg_ParseTuple(args, "|O:asctime", &tup)) return NULL; if (tup == NULL) { time_t tt = time(NULL); + #ifdef HAVE_LOCALTIME_R + buf = *localtime_r(&tt, &buf); + #else buf = *localtime(&tt); + #endif } else if (!gettmarg(tup, &buf)) return NULL; + #ifdef HAVE_ASCTIME_R + p = asctime_r(&buf, &asctime_r_buffer); + #else p = asctime(&buf); + #endif if (p[24] == '\n') p[24] = '\0'; return PyString_FromString(p); *************** *** 523,528 **** --- 536,542 ---- PyObject *ot = NULL; time_t tt; char *p; + char ctime_r_buffer[200]; if (!PyArg_ParseTuple(args, "|O:ctime", &ot)) return NULL; *************** *** 536,542 **** --- 550,560 ---- if (tt == (time_t)-1 && PyErr_Occurred()) return NULL; } + #ifdef HAVE_CTIME_R + p = ctime_r(&tt, &ctime_r_buffer); + #else p = ctime(&tt); + #endif if (p == NULL) { PyErr_SetString(PyExc_ValueError, "unconvertible time"); return NULL; *************** *** 563,569 **** --- 581,591 ---- if (!PyArg_ParseTuple(args, "O:mktime", &tup)) return NULL; tt = time(&tt); + #ifdef HAVE_LOCALTIME_R + buf = *localtime_r(&tt, &buf); + #else buf = *localtime(&tt); + #endif if (!gettmarg(tup, &buf)) return NULL; tt = mktime(&buf); *************** *** 663,677 **** --- 685,708 ---- #define YEAR ((time_t)((365 * 24 + 6) * 3600)) time_t t; struct tm *p; + struct tm localtime_r_buffer; long janzone, julyzone; char janname[10], julyname[10]; t = (time((time_t *)0) / YEAR) * YEAR; + #ifdef HAVE_LOCALTIME_R + p = localtime_r(&t, &localtime_r_buffer); + #else p = localtime(&t); + #endif janzone = -p->tm_gmtoff; strncpy(janname, p->tm_zone ? p->tm_zone : " ", 9); janname[9] = '\0'; t += YEAR/2; + #ifdef HAVE_LOCALTIME_R + p = localtime_r(&t, &localtime_r_buffer); + #else p = localtime(&t); + #endif julyzone = -p->tm_gmtoff; strncpy(julyname, p->tm_zone ? p->tm_zone : " ", 9); julyname[9] = '\0';