[Python-checkins] CVS: python/dist/src/Modules addrinfo.h,NONE,1.1.2.1 getaddrinfo.c,NONE,1.1.2.1 getnameinfo.c,NONE,1.2.2.1 testcapi_long.h,NONE,1.2.2.1 _codecsmodule.c,2.6,2.6.8.1 _cursesmodule.c,2.51,2.51.4.1 _sre.c,2.55,2.55.4.1 _testcapimodule.c,1.3,1.3.4.1 _tkinter.c,1.115,1.115.6.1 _weakref.c,1.10,1.10.4.1 arraymodule.c,2.62,2.62.6.1 binascii.c,2.28,2.28.6.1 fcntlmodule.c,2.28,2.28.6.1 main.c,1.52,1.52.4.1 makesetup,1.35,1.35.6.1 mathmodule.c,2.58,2.58.8.1 mmapmodule.c,2.28,2.28.2.1 parsermodule.c,2.60,2.60.6.1 pcremodule.c,2.25,2.25.8.1 posixmodule.c,2.187,2.187.4.1 pyexpat.c,2.45,2.45.4.1 regexpr.c,1.33,1.33.8.1 selectmodule.c,2.50,2.50.6.1 socketmodule.c,1.141,1.141.4.1 sre.h,2.18,2.18.10.1 sre_constants.h,2.12,2.12.4.1 stropmodule.c,2.75,2.75.8.1 structmodule.c,2.42,2.42.4.1 termios.c,2.24,2.24.4.1 timemodule.c,2.110,2.110.4.1 xreadlinesmodule.c,1.5,1.5.4.1
Tim Peters
tim_one@users.sourceforge.net
2001年7月07日 15:55:32 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv24450/mergedescr/dist/src/Modules
Modified Files:
Tag: descr-branch
_codecsmodule.c _cursesmodule.c _sre.c _testcapimodule.c
_tkinter.c _weakref.c arraymodule.c binascii.c fcntlmodule.c
main.c makesetup mathmodule.c mmapmodule.c parsermodule.c
pcremodule.c posixmodule.c pyexpat.c regexpr.c selectmodule.c
socketmodule.c sre.h sre_constants.h stropmodule.c
structmodule.c termios.c timemodule.c xreadlinesmodule.c
Added Files:
Tag: descr-branch
addrinfo.h getaddrinfo.c getnameinfo.c testcapi_long.h
Log Message:
Merge of trunk tag date2001-07-06 into descr-branch.
--- NEW FILE: addrinfo.h ---
/*
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef HAVE_GETADDRINFO
/*
* Error return codes from getaddrinfo()
*/
#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */
#define EAI_AGAIN 2 /* temporary failure in name resolution */
#define EAI_BADFLAGS 3 /* invalid value for ai_flags */
#define EAI_FAIL 4 /* non-recoverable failure in name resolution */
#define EAI_FAMILY 5 /* ai_family not supported */
#define EAI_MEMORY 6 /* memory allocation failure */
#define EAI_NODATA 7 /* no address associated with hostname */
#define EAI_NONAME 8 /* hostname nor servname provided, or not known */
#define EAI_SERVICE 9 /* servname not supported for ai_socktype */
#define EAI_SOCKTYPE 10 /* ai_socktype not supported */
#define EAI_SYSTEM 11 /* system error returned in errno */
#define EAI_BADHINTS 12
#define EAI_PROTOCOL 13
#define EAI_MAX 14
#endif
/*
* Flag values for getaddrinfo()
*/
#ifndef AI_PASSIVE
#define AI_PASSIVE 0x00000001 /* get address to use bind() */
#define AI_CANONNAME 0x00000002 /* fill ai_canonname */
#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */
/* valid flags for addrinfo */
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */
#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */
/* special recommended flags for getipnodebyname */
#define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG)
#endif
/*
* Constants for getnameinfo()
*/
#ifndef NI_MAXHOST
#define NI_MAXHOST 1025
#define NI_MAXSERV 32
#endif
/*
* Flag values for getnameinfo()
*/
#ifndef NI_NOFQDN
#define NI_NOFQDN 0x00000001
#define NI_NUMERICHOST 0x00000002
#define NI_NAMEREQD 0x00000004
#define NI_NUMERICSERV 0x00000008
#define NI_DGRAM 0x00000010
#endif
#ifndef HAVE_ADDRINFO
struct addrinfo {
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
int ai_family; /* PF_xxx */
int ai_socktype; /* SOCK_xxx */
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
size_t ai_addrlen; /* length of ai_addr */
char *ai_canonname; /* canonical name for hostname */
struct sockaddr *ai_addr; /* binary address */
struct addrinfo *ai_next; /* next structure in linked list */
};
#endif
#ifndef HAVE_SOCKADDR_STORAGE
/*
* RFC 2553: protocol-independent placeholder for socket addresses
*/
#define _SS_MAXSIZE 128
#ifdef HAVE_LONG_LONG
#define _SS_ALIGNSIZE (sizeof(long long))
#else
#define _SS_ALIGNSIZE (sizeof(double))
#endif
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(u_char) * 2)
#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(u_char) * 2 - \
_SS_PAD1SIZE - _SS_ALIGNSIZE)
struct sockaddr_storage {
#ifdef HAVE_SOCKADDR_SA_LEN
unsigned char ss_len; /* address length */
unsigned char ss_family; /* address family */
#else
unsigned short ss_family; /* address family */
#endif
char __ss_pad1[_SS_PAD1SIZE];
#ifdef HAVE_LONG_LONG
long long __ss_align; /* force desired structure storage alignment */
#else
double __ss_align; /* force desired structure storage alignment */
#endif
char __ss_pad2[_SS_PAD2SIZE];
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
extern void freehostent Py_PROTO((struct hostent *));
#ifdef __cplusplus
}
#endif
#endif
--- NEW FILE: getaddrinfo.c ---
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* GAI_ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR GAI_ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON GAI_ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN GAI_ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* "#ifdef FAITH" part is local hack for supporting IPv4-v6 translator.
*
* Issues to be discussed:
* - Thread safe-ness must be checked.
* - Return values. There are nonstandard return values defined and used
* in the source code. This is because RFC2133 is silent about which error
* code must be returned for which situation.
* - PF_UNSPEC case would be handled in getipnodebyname() with the AI_ALL flag.
*/
#if 0
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <unistd.h>
#include "addrinfo.h"
#endif
#if defined(__KAME__) && defined(INET6)
# define FAITH
#endif
#define SUCCESS 0
#define GAI_ANY 0
#define YES 1
#define NO 0
#ifdef FAITH
static int translate = NO;
static struct in6_addr faith_prefix = IN6ADDR_GAI_ANY_INIT;
#endif
static const char in_addrany[] = { 0, 0, 0, 0 };
static const char in6_addrany[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static const char in_loopback[] = { 127, 0, 0, 1 };
static const char in6_loopback[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
};
struct sockinet {
u_char si_len;
u_char si_family;
u_short si_port;
};
static struct gai_afd {
int a_af;
int a_addrlen;
int a_socklen;
int a_off;
const char *a_addrany;
const char *a_loopback;
} gai_afdl [] = {
#ifdef INET6
#define N_INET6 0
{PF_INET6, sizeof(struct in6_addr),
sizeof(struct sockaddr_in6),
offsetof(struct sockaddr_in6, sin6_addr),
in6_addrany, in6_loopback},
#define N_INET 1
#else
#define N_INET 0
#endif
{PF_INET, sizeof(struct in_addr),
sizeof(struct sockaddr_in),
offsetof(struct sockaddr_in, sin_addr),
in_addrany, in_loopback},
{0, 0, 0, 0, NULL, NULL},
};
#ifdef INET6
#define PTON_MAX 16
#else
#define PTON_MAX 4
#endif
static int get_name Py_PROTO((const char *, struct gai_afd *,
struct addrinfo **, char *, struct addrinfo *,
int));
static int get_addr Py_PROTO((const char *, int, struct addrinfo **,
struct addrinfo *, int));
static int str_isnumber Py_PROTO((const char *));
static char *ai_errlist[] = {
"success.",
"address family for hostname not supported.", /* EAI_ADDRFAMILY */
"temporary failure in name resolution.", /* EAI_AGAIN */
"invalid value for ai_flags.", /* EAI_BADFLAGS */
"non-recoverable failure in name resolution.", /* EAI_FAIL */
"ai_family not supported.", /* EAI_FAMILY */
"memory allocation failure.", /* EAI_MEMORY */
"no address associated with hostname.", /* EAI_NODATA */
"hostname nor servname provided, or not known.",/* EAI_NONAME */
"servname not supported for ai_socktype.", /* EAI_SERVICE */
"ai_socktype not supported.", /* EAI_SOCKTYPE */
"system error returned in errno.", /* EAI_SYSTEM */
"invalid value for hints.", /* EAI_BADHINTS */
"resolved protocol is unknown.", /* EAI_PROTOCOL */
"unknown error.", /* EAI_MAX */
};
#define GET_CANONNAME(ai, str) \
if (pai->ai_flags & AI_CANONNAME) {\
if (((ai)->ai_canonname = (char *)malloc(strlen(str) + 1)) != NULL) {\
strcpy((ai)->ai_canonname, (str));\
} else {\
error = EAI_MEMORY;\
goto free;\
}\
}
#ifdef HAVE_SOCKADDR_SA_LEN
#define GET_AI(ai, gai_afd, addr, port) {\
char *p;\
if (((ai) = (struct addrinfo *)malloc(sizeof(struct addrinfo) +\
((gai_afd)->a_socklen)))\
== NULL) goto free;\
memcpy(ai, pai, sizeof(struct addrinfo));\
(ai)->ai_addr = (struct sockaddr *)((ai) + 1);\
memset((ai)->ai_addr, 0, (gai_afd)->a_socklen);\
(ai)->ai_addr->sa_len = (ai)->ai_addrlen = (gai_afd)->a_socklen;\
(ai)->ai_addr->sa_family = (ai)->ai_family = (gai_afd)->a_af;\
((struct sockinet *)(ai)->ai_addr)->si_port = port;\
p = (char *)((ai)->ai_addr);\
memcpy(p + (gai_afd)->a_off, (addr), (gai_afd)->a_addrlen);\
}
#else
#define GET_AI(ai, gai_afd, addr, port) {\
char *p;\
if (((ai) = (struct addrinfo *)malloc(sizeof(struct addrinfo) +\
((gai_afd)->a_socklen)))\
== NULL) goto free;\
memcpy(ai, pai, sizeof(struct addrinfo));\
(ai)->ai_addr = (struct sockaddr *)((ai) + 1);\
memset((ai)->ai_addr, 0, (gai_afd)->a_socklen);\
(ai)->ai_addr->sa_family = (ai)->ai_family = (gai_afd)->a_af;\
((struct sockinet *)(ai)->ai_addr)->si_port = port;\
p = (char *)((ai)->ai_addr);\
memcpy(p + (gai_afd)->a_off, (addr), (gai_afd)->a_addrlen);\
}
#endif
#define ERR(err) { error = (err); goto bad; }
char *
gai_strerror(ecode)
int ecode;
{
if (ecode < 0 || ecode > EAI_MAX)
ecode = EAI_MAX;
return ai_errlist[ecode];
}
void
freeaddrinfo(ai)
struct addrinfo *ai;
{
struct addrinfo *next;
do {
next = ai->ai_next;
if (ai->ai_canonname)
free(ai->ai_canonname);
/* no need to free(ai->ai_addr) */
free(ai);
} while ((ai = next) != NULL);
}
static int
str_isnumber(p)
const char *p;
{
char *q = (char *)p;
while (*q) {
if (! isdigit(*q))
return NO;
q++;
}
return YES;
}
int
getaddrinfo(hostname, servname, hints, res)
const char *hostname, *servname;
const struct addrinfo *hints;
struct addrinfo **res;
{
struct addrinfo sentinel;
struct addrinfo *top = NULL;
struct addrinfo *cur;
int i, error = 0;
char pton[PTON_MAX];
struct addrinfo ai;
struct addrinfo *pai;
u_short port;
#ifdef FAITH
static int firsttime = 1;
if (firsttime) {
/* translator hack */
{
char *q = getenv("GAI");
if (q && inet_pton(AF_INET6, q, &faith_prefix) == 1)
translate = YES;
}
firsttime = 0;
}
#endif
/* initialize file static vars */
sentinel.ai_next = NULL;
cur = &sentinel;
pai = &ai;
pai->ai_flags = 0;
pai->ai_family = PF_UNSPEC;
pai->ai_socktype = GAI_ANY;
pai->ai_protocol = GAI_ANY;
pai->ai_addrlen = 0;
pai->ai_canonname = NULL;
pai->ai_addr = NULL;
pai->ai_next = NULL;
port = GAI_ANY;
if (hostname == NULL && servname == NULL)
return EAI_NONAME;
if (hints) {
/* error check for hints */
if (hints->ai_addrlen || hints->ai_canonname ||
hints->ai_addr || hints->ai_next)
ERR(EAI_BADHINTS); /* xxx */
if (hints->ai_flags & ~AI_MASK)
ERR(EAI_BADFLAGS);
switch (hints->ai_family) {
case PF_UNSPEC:
case PF_INET:
#ifdef INET6
case PF_INET6:
#endif
break;
default:
ERR(EAI_FAMILY);
}
memcpy(pai, hints, sizeof(*pai));
switch (pai->ai_socktype) {
case GAI_ANY:
switch (pai->ai_protocol) {
case GAI_ANY:
break;
case IPPROTO_UDP:
pai->ai_socktype = SOCK_DGRAM;
break;
case IPPROTO_TCP:
pai->ai_socktype = SOCK_STREAM;
break;
default:
pai->ai_socktype = SOCK_RAW;
break;
}
break;
case SOCK_RAW:
break;
case SOCK_DGRAM:
if (pai->ai_protocol != IPPROTO_UDP &&
pai->ai_protocol != GAI_ANY)
ERR(EAI_BADHINTS); /*xxx*/
pai->ai_protocol = IPPROTO_UDP;
break;
case SOCK_STREAM:
if (pai->ai_protocol != IPPROTO_TCP &&
pai->ai_protocol != GAI_ANY)
ERR(EAI_BADHINTS); /*xxx*/
pai->ai_protocol = IPPROTO_TCP;
break;
default:
ERR(EAI_SOCKTYPE);
break;
}
}
/*
* service port
*/
if (servname) {
if (str_isnumber(servname)) {
if (pai->ai_socktype == GAI_ANY) {
/* caller accept *GAI_ANY* socktype */
pai->ai_socktype = SOCK_DGRAM;
pai->ai_protocol = IPPROTO_UDP;
}
port = htons(atoi(servname));
} else {
struct servent *sp;
char *proto;
proto = NULL;
switch (pai->ai_socktype) {
case GAI_ANY:
proto = NULL;
break;
case SOCK_DGRAM:
proto = "udp";
break;
case SOCK_STREAM:
proto = "tcp";
break;
default:
fprintf(stderr, "panic!\n");
break;
}
if ((sp = getservbyname(servname, proto)) == NULL)
ERR(EAI_SERVICE);
port = sp->s_port;
if (pai->ai_socktype == GAI_ANY)
if (strcmp(sp->s_proto, "udp") == 0) {
pai->ai_socktype = SOCK_DGRAM;
pai->ai_protocol = IPPROTO_UDP;
} else if (strcmp(sp->s_proto, "tcp") == 0) {
pai->ai_socktype = SOCK_STREAM;
pai->ai_protocol = IPPROTO_TCP;
} else
ERR(EAI_PROTOCOL); /*xxx*/
}
}
/*
* hostname == NULL.
* passive socket -> anyaddr (0.0.0.0 or ::)
* non-passive socket -> localhost (127.0.0.1 or ::1)
*/
if (hostname == NULL) {
struct gai_afd *gai_afd;
for (gai_afd = &gai_afdl[0]; gai_afd->a_af; gai_afd++) {
if (!(pai->ai_family == PF_UNSPEC
|| pai->ai_family == gai_afd->a_af)) {
continue;
}
if (pai->ai_flags & AI_PASSIVE) {
GET_AI(cur->ai_next, gai_afd, gai_afd->a_addrany, port);
/* xxx meaningless?
* GET_CANONNAME(cur->ai_next, "anyaddr");
*/
} else {
GET_AI(cur->ai_next, gai_afd, gai_afd->a_loopback,
port);
/* xxx meaningless?
* GET_CANONNAME(cur->ai_next, "localhost");
*/
}
cur = cur->ai_next;
}
top = sentinel.ai_next;
if (top)
goto good;
else
ERR(EAI_FAMILY);
}
/* hostname as numeric name */
for (i = 0; gai_afdl[i].a_af; i++) {
if (inet_pton(gai_afdl[i].a_af, hostname, pton)) {
u_long v4a;
u_char pfx;
switch (gai_afdl[i].a_af) {
case AF_INET:
v4a = ((struct in_addr *)pton)->s_addr;
if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
pai->ai_flags &= ~AI_CANONNAME;
v4a >>= IN_CLASSA_NSHIFT;
if (v4a == 0 || v4a == IN_LOOPBACKNET)
pai->ai_flags &= ~AI_CANONNAME;
break;
#ifdef INET6
case AF_INET6:
pfx = ((struct in6_addr *)pton)->s6_addr8[0];
if (pfx == 0 || pfx == 0xfe || pfx == 0xff)
pai->ai_flags &= ~AI_CANONNAME;
break;
#endif
}
if (pai->ai_family == gai_afdl[i].a_af ||
pai->ai_family == PF_UNSPEC) {
if (! (pai->ai_flags & AI_CANONNAME)) {
GET_AI(top, &gai_afdl[i], pton, port);
goto good;
}
/*
* if AI_CANONNAME and if reverse lookup
* fail, return ai anyway to pacify
* calling application.
*
* XXX getaddrinfo() is a name->address
* translation function, and it looks strange
* that we do addr->name translation here.
*/
get_name(pton, &gai_afdl[i], &top, pton, pai, port);
goto good;
} else
ERR(EAI_FAMILY); /*xxx*/
}
}
if (pai->ai_flags & AI_NUMERICHOST)
ERR(EAI_NONAME);
/* hostname as alphabetical name */
error = get_addr(hostname, pai->ai_family, &top, pai, port);
if (error == 0) {
if (top) {
good:
*res = top;
return SUCCESS;
} else
error = EAI_FAIL;
}
free:
if (top)
freeaddrinfo(top);
bad:
*res = NULL;
return error;
}
static int
get_name(addr, gai_afd, res, numaddr, pai, port0)
const char *addr;
struct gai_afd *gai_afd;
struct addrinfo **res;
char *numaddr;
struct addrinfo *pai;
int port0;
{
u_short port = port0 & 0xffff;
struct hostent *hp;
struct addrinfo *cur;
int error = 0, h_error;
#ifdef INET6
hp = getipnodebyaddr(addr, gai_afd->a_addrlen, gai_afd->a_af, &h_error);
#else
hp = gethostbyaddr(addr, gai_afd->a_addrlen, AF_INET);
#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);
} else
GET_AI(cur, gai_afd, numaddr, port);
#ifdef INET6
if (hp)
freehostent(hp);
#endif
*res = cur;
return SUCCESS;
free:
if (cur)
freeaddrinfo(cur);
#ifdef INET6
if (hp)
freehostent(hp);
#endif
/* bad: */
*res = NULL;
return error;
}
static int
get_addr(hostname, af, res, pai, port0)
const char *hostname;
int af;
struct addrinfo **res;
struct addrinfo *pai;
int port0;
{
u_short port = port0 & 0xffff;
struct addrinfo sentinel;
struct hostent *hp;
struct addrinfo *top, *cur;
struct gai_afd *gai_afd;
int i, error = 0, h_error;
char *ap;
#ifndef INET6
extern int h_errno;
#endif
top = NULL;
sentinel.ai_next = NULL;
cur = &sentinel;
#ifdef INET6
if (af == AF_UNSPEC) {
hp = getipnodebyname(hostname, AF_INET6,
AI_ADDRCONFIG|AI_ALL|AI_V4MAPPED, &h_error);
} else
hp = getipnodebyname(hostname, af, AI_ADDRCONFIG, &h_error);
#else
hp = gethostbyname(hostname);
h_error = h_errno;
#endif
if (hp == NULL) {
switch (h_error) {
case HOST_NOT_FOUND:
case NO_DATA:
error = EAI_NODATA;
break;
case TRY_AGAIN:
error = EAI_AGAIN;
break;
case NO_RECOVERY:
default:
error = EAI_FAIL;
break;
}
goto bad;
}
if ((hp->h_name == NULL) || (hp->h_name[0] == 0) ||
(hp->h_addr_list[0] == NULL))
ERR(EAI_FAIL);
for (i = 0; (ap = hp->h_addr_list[i]) != NULL; i++) {
switch (af) {
#ifdef INET6
case AF_INET6:
gai_afd = &gai_afdl[N_INET6];
break;
#endif
#ifndef INET6
default: /* AF_UNSPEC */
#endif
case AF_INET:
gai_afd = &gai_afdl[N_INET];
break;
#ifdef INET6
default: /* AF_UNSPEC */
if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ap)) {
ap += sizeof(struct in6_addr) -
sizeof(struct in_addr);
gai_afd = &gai_afdl[N_INET];
} else
gai_afd = &gai_afdl[N_INET6];
break;
#endif
}
#ifdef FAITH
if (translate && gai_afd->a_af == AF_INET) {
struct in6_addr *in6;
GET_AI(cur->ai_next, &gai_afdl[N_INET6], ap, port);
in6 = &((struct sockaddr_in6 *)cur->ai_next->ai_addr)->sin6_addr;
memcpy(&in6->s6_addr32[0], &faith_prefix,
sizeof(struct in6_addr) - sizeof(struct in_addr));
memcpy(&in6->s6_addr32[3], ap, sizeof(struct in_addr));
} else
#endif /* FAITH */
GET_AI(cur->ai_next, gai_afd, ap, port);
if (cur == &sentinel) {
top = cur->ai_next;
GET_CANONNAME(top, hp->h_name);
}
cur = cur->ai_next;
}
#ifdef INET6
freehostent(hp);
#endif
*res = top;
return SUCCESS;
free:
if (top)
freeaddrinfo(top);
#ifdef INET6
if (hp)
freehostent(hp);
#endif
bad:
*res = NULL;
return error;
}
--- NEW FILE: getnameinfo.c ---
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Issues to be discussed:
* - Thread safe-ness must be checked
* - Return values. There seems to be no standard for return value (RFC2133)
* but INRIA implementation returns EAI_xxx defined for getaddrinfo().
*/
#if 0
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
#include <string.h>
#include <stddef.h>
#include "addrinfo.h"
#endif
#define SUCCESS 0
#define YES 1
#define NO 0
static struct gni_afd {
int a_af;
int a_addrlen;
int a_socklen;
int a_off;
} gni_afdl [] = {
#ifdef INET6
{PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
offsetof(struct sockaddr_in6, sin6_addr)},
#endif
{PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
offsetof(struct sockaddr_in, sin_addr)},
{0, 0, 0},
};
struct gni_sockinet {
u_char si_len;
u_char si_family;
u_short si_port;
};
#define ENI_NOSOCKET 0
#define ENI_NOSERVNAME 1
#define ENI_NOHOSTNAME 2
#define ENI_MEMORY 3
#define ENI_SYSTEM 4
#define ENI_FAMILY 5
#define ENI_SALEN 6
int
getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
const struct sockaddr *sa;
size_t salen;
char *host;
size_t hostlen;
char *serv;
size_t servlen;
int flags;
{
struct gni_afd *gni_afd;
struct servent *sp;
struct hostent *hp;
u_short port;
int family, len, i;
char *addr, *p;
u_long v4a;
u_char pfx;
int h_error;
char numserv[512];
char numaddr[512];
if (sa == NULL)
return ENI_NOSOCKET;
#ifdef HAVE_SOCKADDR_SA_LEN
len = sa->sa_len;
if (len != salen) return ENI_SALEN;
#else
len = salen;
#endif
family = sa->sa_family;
for (i = 0; gni_afdl[i].a_af; i++)
if (gni_afdl[i].a_af == family) {
gni_afd = &gni_afdl[i];
goto found;
}
return ENI_FAMILY;
found:
if (len != gni_afd->a_socklen) return ENI_SALEN;
port = ((struct gni_sockinet *)sa)->si_port; /* network byte order */
addr = (char *)sa + gni_afd->a_off;
if (serv == NULL || servlen == 0) {
/* what we should do? */
} else if (flags & NI_NUMERICSERV) {
sprintf(numserv, "%d", ntohs(port));
if (strlen(numserv) > servlen)
return ENI_MEMORY;
strcpy(serv, numserv);
} else {
sp = getservbyport(port, (flags & NI_DGRAM) ? "udp" : "tcp");
if (sp) {
if (strlen(sp->s_name) > servlen)
return ENI_MEMORY;
strcpy(serv, sp->s_name);
} else
return ENI_NOSERVNAME;
}
switch (sa->sa_family) {
case AF_INET:
v4a = ((struct sockaddr_in *)sa)->sin_addr.s_addr;
if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
flags |= NI_NUMERICHOST;
v4a >>= IN_CLASSA_NSHIFT;
if (v4a == 0 || v4a == IN_LOOPBACKNET)
flags |= NI_NUMERICHOST;
break;
#ifdef INET6
case AF_INET6:
pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr8[0];
if (pfx == 0 || pfx == 0xfe || pfx == 0xff)
flags |= NI_NUMERICHOST;
break;
#endif
}
if (host == NULL || hostlen == 0) {
/* what should we do? */
} else if (flags & NI_NUMERICHOST) {
if (inet_ntop(gni_afd->a_af, addr, numaddr, sizeof(numaddr))
== NULL)
return ENI_SYSTEM;
if (strlen(numaddr) > hostlen)
return ENI_MEMORY;
strcpy(host, numaddr);
} else {
#ifdef INET6
hp = getipnodebyaddr(addr, gni_afd->a_addrlen, gni_afd->a_af, &h_error);
#else
hp = gethostbyaddr(addr, gni_afd->a_addrlen, gni_afd->a_af);
h_error = h_errno;
#endif
if (hp) {
if (flags & NI_NOFQDN) {
p = strchr(hp->h_name, '.');
if (p) *p = '0円';
}
if (strlen(hp->h_name) > hostlen) {
#ifdef INET6
freehostent(hp);
#endif
return ENI_MEMORY;
}
strcpy(host, hp->h_name);
#ifdef INET6
freehostent(hp);
#endif
} else {
if (flags & NI_NAMEREQD)
return ENI_NOHOSTNAME;
if (inet_ntop(gni_afd->a_af, addr, numaddr, sizeof(numaddr))
== NULL)
return ENI_NOHOSTNAME;
if (strlen(numaddr) > hostlen)
return ENI_MEMORY;
strcpy(host, numaddr);
}
}
return SUCCESS;
}
--- NEW FILE: testcapi_long.h ---
/* Poor-man's template. Macros used:
TESTNAME name of the test (like test_long_api_inner)
TYPENAME the signed type (like long)
F_S_TO_PY convert signed to pylong; TYPENAME -> PyObject*
F_PY_TO_S convert pylong to signed; PyObject* -> TYPENAME
F_U_TO_PY convert unsigned to pylong; unsigned TYPENAME -> PyObject*
F_PY_TO_U convert pylong to unsigned; PyObject* -> unsigned TYPENAME
*/
static PyObject *
TESTNAME(PyObject *error(const char*))
{
const int NBITS = sizeof(TYPENAME) * 8;
unsigned TYPENAME base;
PyObject *pyresult;
int i;
/* Note: This test lets PyObjects leak if an error is raised. Since
an error should never be raised, leaks are impossible <wink>. */
/* Test native -> PyLong -> native roundtrip identity.
* Generate all powers of 2, and test them and their negations,
* plus the numbers +-1 off from them.
*/
base = 1;
for (i = 0;
i < NBITS + 1; /* on last, base overflows to 0 */
++i, base <<= 1)
{
int j;
for (j = 0; j < 6; ++j) {
TYPENAME in, out;
unsigned TYPENAME uin, uout;
/* For 0, 1, 2 use base; for 3, 4, 5 use -base */
uin = j < 3 ? base
: (unsigned TYPENAME)(-(TYPENAME)base);
/* For 0 & 3, subtract 1.
* For 1 & 4, leave alone.
* For 2 & 5, add 1.
*/
uin += (unsigned TYPENAME)(TYPENAME)(j % 3 - 1);
pyresult = F_U_TO_PY(uin);
if (pyresult == NULL)
return error(
"unsigned unexpected null result");
uout = F_PY_TO_U(pyresult);
if (uout == (unsigned TYPENAME)-1 && PyErr_Occurred())
return error(
"unsigned unexpected -1 result");
if (uout != uin)
return error(
"unsigned output != input");
UNBIND(pyresult);
in = (TYPENAME)uin;
pyresult = F_S_TO_PY(in);
if (pyresult == NULL)
return error(
"signed unexpected null result");
out = F_PY_TO_S(pyresult);
if (out == (TYPENAME)-1 && PyErr_Occurred())
return error(
"signed unexpected -1 result");
if (out != in)
return error(
"signed output != input");
UNBIND(pyresult);
}
}
/* Overflow tests. The loop above ensured that all limit cases that
* should not overflow don't overflow, so all we need to do here is
* provoke one-over-the-limit cases (not exhaustive, but sharp).
*/
{
PyObject *one, *x, *y;
TYPENAME out;
unsigned TYPENAME uout;
one = PyLong_FromLong(1);
if (one == NULL)
return error(
"unexpected NULL from PyLong_FromLong");
/* Unsigned complains about -1? */
x = PyNumber_Negative(one);
if (x == NULL)
return error(
"unexpected NULL from PyNumber_Negative");
uout = F_PY_TO_U(x);
if (uout != (unsigned TYPENAME)-1 || !PyErr_Occurred())
return error(
"PyLong_AsUnsignedXXX(-1) didn't complain");
PyErr_Clear();
UNBIND(x);
/* Unsigned complains about 2**NBITS? */
y = PyLong_FromLong((long)NBITS);
if (y == NULL)
return error(
"unexpected NULL from PyLong_FromLong");
x = PyNumber_Lshift(one, y); /* 1L << NBITS, == 2**NBITS */
UNBIND(y);
if (x == NULL)
return error(
"unexpected NULL from PyNumber_Lshift");
uout = F_PY_TO_U(x);
if (uout != (unsigned TYPENAME)-1 || !PyErr_Occurred())
return error(
"PyLong_AsUnsignedXXX(2**NBITS) didn't "
"complain");
PyErr_Clear();
/* Signed complains about 2**(NBITS-1)?
x still has 2**NBITS. */
y = PyNumber_Rshift(x, one); /* 2**(NBITS-1) */
UNBIND(x);
if (y == NULL)
return error(
"unexpected NULL from PyNumber_Rshift");
out = F_PY_TO_S(y);
if (out != (TYPENAME)-1 || !PyErr_Occurred())
return error(
"PyLong_AsXXX(2**(NBITS-1)) didn't "
"complain");
PyErr_Clear();
/* Signed complains about -2**(NBITS-1)-1?;
y still has 2**(NBITS-1). */
x = PyNumber_Negative(y); /* -(2**(NBITS-1)) */
UNBIND(y);
if (x == NULL)
return error(
"unexpected NULL from PyNumber_Negative");
y = PyNumber_Subtract(x, one); /* -(2**(NBITS-1))-1 */
UNBIND(x);
if (y == NULL)
return error(
"unexpected NULL from PyNumber_Subtract");
out = F_PY_TO_S(y);
if (out != (TYPENAME)-1 || !PyErr_Occurred())
return error(
"PyLong_AsXXX(-2**(NBITS-1)-1) didn't "
"complain");
PyErr_Clear();
UNBIND(y);
Py_XDECREF(x);
Py_XDECREF(y);
Py_DECREF(one);
}
Py_INCREF(Py_None);
return Py_None;
}
Index: _codecsmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_codecsmodule.c,v
retrieving revision 2.6
retrieving revision 2.6.8.1
diff -C2 -r2.6 -r2.6.8.1
*** _codecsmodule.c 2000年09月21日 21:09:45 2.6
--- _codecsmodule.c 2001年07月07日 22:55:29 2.6.8.1
***************
*** 300,304 ****
}
! #ifdef MS_WIN32
static PyObject *
--- 300,304 ----
}
! #if defined(MS_WIN32) && defined(HAVE_USABLE_WCHAR_T)
static PyObject *
***************
*** 441,445 ****
const char *errors = NULL;
! if (!PyArg_ParseTuple(args, "O|zi:utf_16_le_encode",
&str, &errors))
return NULL;
--- 441,445 ----
const char *errors = NULL;
! if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
&str, &errors))
return NULL;
***************
*** 464,468 ****
const char *errors = NULL;
! if (!PyArg_ParseTuple(args, "O|zi:utf_16_be_encode",
&str, &errors))
return NULL;
--- 464,468 ----
const char *errors = NULL;
! if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
&str, &errors))
return NULL;
***************
*** 596,600 ****
}
! #ifdef MS_WIN32
static PyObject *
--- 596,600 ----
}
! #if defined(MS_WIN32) && defined(HAVE_USABLE_WCHAR_T)
static PyObject *
***************
*** 651,655 ****
{"readbuffer_encode", readbuffer_encode, 1},
{"charbuffer_encode", charbuffer_encode, 1},
! #ifdef MS_WIN32
{"mbcs_encode", mbcs_encode, 1},
{"mbcs_decode", mbcs_decode, 1},
--- 651,655 ----
{"readbuffer_encode", readbuffer_encode, 1},
{"charbuffer_encode", charbuffer_encode, 1},
! #if defined(MS_WIN32) && defined(HAVE_USABLE_WCHAR_T)
{"mbcs_encode", mbcs_encode, 1},
{"mbcs_decode", mbcs_decode, 1},
Index: _cursesmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_cursesmodule.c,v
retrieving revision 2.51
retrieving revision 2.51.4.1
diff -C2 -r2.51 -r2.51.4.1
*** _cursesmodule.c 2001年04月10日 19:53:37 2.51
--- _cursesmodule.c 2001年07月07日 22:55:29 2.51.4.1
***************
*** 190,195 ****
if (PyInt_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj);
! } else if(PyString_Check(obj) &
! (PyString_Size(obj) == 1)) {
*ch = (chtype) *PyString_AsString(obj);
} else {
--- 190,195 ----
if (PyInt_Check(obj)) {
*ch = (chtype) PyInt_AsLong(obj);
! } else if(PyString_Check(obj)
! && (PyString_Size(obj) == 1)) {
*ch = (chtype) *PyString_AsString(obj);
} else {
Index: _sre.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_sre.c,v
retrieving revision 2.55
retrieving revision 2.55.4.1
diff -C2 -r2.55 -r2.55.4.1
*** _sre.c 2001年04月15日 19:00:58 2.55
--- _sre.c 2001年07月07日 22:55:29 2.55.4.1
***************
*** 29,32 ****
--- 29,35 ----
* 2001年03月20日 fl lots of fixes for 2.1b2
* 2001年04月15日 fl export copyright as Python attribute, not global
+ * 2001年04月28日 fl added __copy__ methods (work in progress)
+ * 2001年05月14日 fl fixes for 1.5.2
+ * 2001年07月01日 fl added BIGCHARSET support (from Martin von Loewis)
*
* Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
***************
*** 44,50 ****
static char copyright[] =
! " SRE 2.1b2 Copyright (c) 1997-2001 by Secret Labs AB ";
#include "Python.h"
#include "sre.h"
--- 47,54 ----
static char copyright[] =
! " SRE 2.1.1 Copyright (c) 1997-2001 by Secret Labs AB ";
#include "Python.h"
+ #include "structmember.h" /* offsetof */
#include "sre.h"
***************
*** 87,90 ****
--- 91,97 ----
#undef USE_INLINE
+ /* enables copy/deepcopy handling (work in progress) */
+ #undef USE_BUILTIN_COPY
+
#if PY_VERSION_HEX < 0x01060000
#define PyObject_DEL(op) PyMem_DEL((op))
***************
*** 445,448 ****
--- 452,456 ----
return this == that;
+ #if defined(HAVE_UNICODE)
case SRE_AT_UNI_BOUNDARY:
if (state->beginning == state->end)
***************
*** 462,465 ****
--- 470,475 ----
SRE_UNI_IS_WORD((int) ptr[0]) : 0;
return this == that;
+ #endif
+
}
***************
*** 498,501 ****
--- 508,524 ----
break;
+ case SRE_OP_BIGCHARSET:
+ /* <BIGCHARSET> <blockcount> <256 blockindices> <blocks> */
+ {
+ int count, block;
+ count = *(set++);
+ block = ((unsigned char*)set)[ch >> 8];
+ set += 128;
+ if (set[block*16 + ((ch & 255)>>4)] & (1 << (ch & 15)))
+ return ok;
+ set += count*16;
+ break;
+ }
+
case SRE_OP_CATEGORY:
/* <CATEGORY> <code> */
***************
*** 1082,1086 ****
state->repeat = rp->prev;
/* FIXME: the following fix doesn't always work (#133283) */
! if (0 && rp->pattern[2] == 65535) {
/* unbounded repeat */
for (;;) {
--- 1105,1109 ----
state->repeat = rp->prev;
/* FIXME: the following fix doesn't always work (#133283) */
! if (rp->pattern[2] == 65535) {
/* unbounded repeat */
for (;;) {
***************
*** 1287,1290 ****
--- 1310,1315 ----
return NULL;
+ self->codesize = n;
+
for (i = 0; i < n; i++) {
PyObject *o = PyList_GET_ITEM(code, i);
***************
*** 1673,1692 ****
static PyObject*
! call(char* function, PyObject* args)
{
PyObject* name;
! PyObject* module;
PyObject* func;
PyObject* result;
! name = PyString_FromString(SRE_MODULE);
if (!name)
return NULL;
! module = PyImport_Import(name);
Py_DECREF(name);
! if (!module)
return NULL;
! func = PyObject_GetAttrString(module, function);
! Py_DECREF(module);
if (!func)
return NULL;
--- 1698,1717 ----
static PyObject*
! call(char* module, char* function, PyObject* args)
{
PyObject* name;
! PyObject* mod;
PyObject* func;
PyObject* result;
! name = PyString_FromString(module);
if (!name)
return NULL;
! mod = PyImport_Import(name);
Py_DECREF(name);
! if (!mod)
return NULL;
! func = PyObject_GetAttrString(mod, function);
! Py_DECREF(mod);
if (!func)
return NULL;
***************
*** 1697,1700 ****
--- 1722,1745 ----
}
+ #ifdef USE_BUILTIN_COPY
+ static int
+ deepcopy(PyObject** object, PyObject* memo)
+ {
+ PyObject* copy;
+
+ copy = call(
+ "copy", "deepcopy",
+ Py_BuildValue("OO", *object, memo)
+ );
+ if (!copy)
+ return 0;
+
+ Py_DECREF(*object);
+ *object = copy;
+
+ return 1; /* success */
+ }
+ #endif
+
static PyObject*
pattern_sub(PatternObject* self, PyObject* args, PyObject* kw)
***************
*** 1709,1713 ****
/* delegate to Python code */
! return call("_sub", Py_BuildValue("OOOO", self, template, string, count));
}
--- 1754,1761 ----
/* delegate to Python code */
! return call(
! SRE_MODULE, "_sub",
! Py_BuildValue("OOOO", self, template, string, count)
! );
}
***************
*** 1724,1728 ****
/* delegate to Python code */
! return call("_subn", Py_BuildValue("OOOO", self, template, string, count));
}
--- 1772,1779 ----
/* delegate to Python code */
! return call(
! SRE_MODULE, "_subn",
! Py_BuildValue("OOOO", self, template, string, count)
! );
}
***************
*** 1738,1742 ****
/* delegate to Python code */
! return call("_split", Py_BuildValue("OOO", self, string, maxsplit));
}
--- 1789,1796 ----
/* delegate to Python code */
! return call(
! SRE_MODULE, "_split",
! Py_BuildValue("OOO", self, string, maxsplit)
! );
}
***************
*** 1845,1848 ****
--- 1899,1959 ----
}
+ static PyObject*
+ pattern_copy(PatternObject* self, PyObject* args)
+ {
+ #ifdef USE_BUILTIN_COPY
+ PatternObject* copy;
+ int offset;
+
+ if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
+ return NULL;
+
+ copy = PyObject_NEW_VAR(PatternObject, &Pattern_Type, self->codesize);
+ if (!copy)
+ return NULL;
+
+ offset = offsetof(PatternObject, groups);
+
+ Py_XINCREF(self->groupindex);
+ Py_XINCREF(self->indexgroup);
+ Py_XINCREF(self->pattern);
+
+ memcpy((char*) copy + offset, (char*) self + offset,
+ sizeof(PatternObject) + self->codesize * sizeof(SRE_CODE) - offset);
+
+ return (PyObject*) copy;
+ #else
+ PyErr_SetString(PyExc_TypeError, "cannot copy this pattern object");
+ return NULL;
+ #endif
+ }
+
+ static PyObject*
+ pattern_deepcopy(PatternObject* self, PyObject* args)
+ {
+ #ifdef USE_BUILTIN_COPY
+ PatternObject* copy;
+
+ PyObject* memo;
+ if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
+ return NULL;
+
+ copy = (PatternObject*) pattern_copy(self, Py_None);
+ if (!copy)
+ return NULL;
+
+ if (!deepcopy(©->groupindex, memo) ||
+ !deepcopy(©->indexgroup, memo) ||
+ !deepcopy(©->pattern, memo)) {
+ Py_DECREF(copy);
+ return NULL;
+ }
+
+ #else
+ PyErr_SetString(PyExc_TypeError, "cannot deepcopy this pattern object");
+ return NULL;
+ #endif
+ }
+
static PyMethodDef pattern_methods[] = {
{"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS},
***************
*** 1852,1857 ****
{"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS},
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS},
- /* experimental */
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
{NULL, NULL}
};
--- 1963,1969 ----
{"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS},
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS},
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS},
+ {"__copy__", (PyCFunction) pattern_copy, METH_VARARGS},
+ {"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_VARARGS},
{NULL, NULL}
};
***************
*** 1974,1978 ****
/* delegate to Python code */
return call(
! "_expand",
Py_BuildValue("OOO", self->pattern, self, template)
);
--- 2086,2090 ----
/* delegate to Python code */
return call(
! SRE_MODULE, "_expand",
Py_BuildValue("OOO", self->pattern, self, template)
);
***************
*** 2212,2215 ****
--- 2324,2388 ----
}
+ static PyObject*
+ match_copy(MatchObject* self, PyObject* args)
+ {
+ #ifdef USE_BUILTIN_COPY
+ MatchObject* copy;
+ int slots, offset;
+
+ if (args != Py_None && !PyArg_ParseTuple(args, ":__copy__"))
+ return NULL;
+
+ slots = 2 * (self->pattern->groups+1);
+
+ copy = PyObject_NEW_VAR(MatchObject, &Match_Type, slots);
+ if (!copy)
+ return NULL;
+
+ /* this value a constant, but any compiler should be able to
+ figure that out all by itself */
+ offset = offsetof(MatchObject, string);
+
+ Py_XINCREF(self->pattern);
+ Py_XINCREF(self->string);
+ Py_XINCREF(self->regs);
+
+ memcpy((char*) copy + offset, (char*) self + offset,
+ sizeof(MatchObject) + slots * sizeof(int) - offset);
+
+ return (PyObject*) copy;
+ #else
+ PyErr_SetString(PyExc_TypeError, "cannot copy this match object");
+ return NULL;
+ #endif
+ }
+
+ static PyObject*
+ match_deepcopy(MatchObject* self, PyObject* args)
+ {
+ #ifdef USE_BUILTIN_COPY
+ MatchObject* copy;
+
+ PyObject* memo;
+ if (!PyArg_ParseTuple(args, "O:__deepcopy__", &memo))
+ return NULL;
+
+ copy = (MatchObject*) match_copy(self, Py_None);
+ if (!copy)
+ return NULL;
+
+ if (!deepcopy((PyObject**) ©->pattern, memo) ||
+ !deepcopy(©->string, memo) ||
+ !deepcopy(©->regs, memo)) {
+ Py_DECREF(copy);
+ return NULL;
+ }
+
+ #else
+ PyErr_SetString(PyExc_TypeError, "cannot deepcopy this match object");
+ return NULL;
+ #endif
+ }
+
static PyMethodDef match_methods[] = {
{"group", (PyCFunction) match_group, METH_VARARGS},
***************
*** 2220,2223 ****
--- 2393,2398 ----
{"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS},
{"expand", (PyCFunction) match_expand, METH_VARARGS},
+ {"__copy__", (PyCFunction) match_copy, METH_VARARGS},
+ {"__deepcopy__", (PyCFunction) match_deepcopy, METH_VARARGS},
{NULL, NULL}
};
Index: _testcapimodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_testcapimodule.c,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -C2 -r1.3 -r1.3.4.1
*** _testcapimodule.c 2001年04月13日 17:08:15 1.3
--- _testcapimodule.c 2001年07月07日 22:55:29 1.3.4.1
***************
*** 10,13 ****
--- 10,29 ----
static PyObject *TestError; /* set to exception object in init */
+ /* Raise TestError with test_name + ": " + msg, and return NULL. */
+
+ static PyObject *
+ raiseTestError(const char* test_name, const char* msg)
+ {
+ char buf[2048];
+
+ if (strlen(test_name) + strlen(msg) > sizeof(buf) - 50)
+ PyErr_SetString(TestError, "internal error msg too large");
+ else {
+ sprintf(buf, "%s: %s", test_name, msg);
+ PyErr_SetString(TestError, buf);
+ }
+ return NULL;
+ }
+
/* Test #defines from config.h (particularly the SIZEOF_* defines).
***************
*** 37,40 ****
--- 53,57 ----
return sizeof_error(#FATNAME, #TYPE, FATNAME, sizeof(TYPE))
+ CHECK_SIZEOF(SIZEOF_SHORT, short);
CHECK_SIZEOF(SIZEOF_INT, int);
CHECK_SIZEOF(SIZEOF_LONG, long);
***************
*** 146,150 ****
if (!PyArg_ParseTuple(args, ":test_dict_iteration"))
return NULL;
!
for (i = 0; i < 200; i++) {
if (test_dict_inner(i) < 0) {
--- 163,167 ----
if (!PyArg_ParseTuple(args, ":test_dict_iteration"))
return NULL;
!
for (i = 0; i < 200; i++) {
if (test_dict_inner(i) < 0) {
***************
*** 157,164 ****
}
static PyMethodDef TestMethods[] = {
! {"test_config", test_config, METH_VARARGS},
! {"test_list_api", test_list_api, METH_VARARGS},
! {"test_dict_iteration", test_dict_iteration, METH_VARARGS},
{NULL, NULL} /* sentinel */
};
--- 174,270 ----
}
+
+ /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG)
+ PyLong_{As, From}{Unsigned,}LongLong().
+
+ Note that the meat of the test is contained in testcapi_long.h.
+ This is revolting, but delicate code duplication is worse: "almost
+ exactly the same" code is needed to test LONG_LONG, but the ubiquitous
+ dependence on type names makes it impossible to use a parameterized
+ function. A giant macro would be even worse than this. A C++ template
+ would be perfect.
+
+ The "report an error" functions are deliberately not part of the #include
+ file: if the test fails, you can set a breakpoint in the appropriate
+ error function directly, and crawl back from there in the debugger.
+ */
+
+ #define UNBIND(X) Py_DECREF(X); (X) = NULL
+
+ static PyObject *
+ raise_test_long_error(const char* msg)
+ {
+ return raiseTestError("test_long_api", msg);
+ }
+
+ #define TESTNAME test_long_api_inner
+ #define TYPENAME long
+ #define F_S_TO_PY PyLong_FromLong
+ #define F_PY_TO_S PyLong_AsLong
+ #define F_U_TO_PY PyLong_FromUnsignedLong
+ #define F_PY_TO_U PyLong_AsUnsignedLong
+
+ #include "testcapi_long.h"
+
+ static PyObject *
+ test_long_api(PyObject* self, PyObject* args)
+ {
+ if (!PyArg_ParseTuple(args, ":test_long_api"))
+ return NULL;
+
+ return TESTNAME(raise_test_long_error);
+ }
+
+ #undef TESTNAME
+ #undef TYPENAME
+ #undef F_S_TO_PY
+ #undef F_PY_TO_S
+ #undef F_U_TO_PY
+ #undef F_PY_TO_U
+
+ #ifdef HAVE_LONG_LONG
+
+ static PyObject *
+ raise_test_longlong_error(const char* msg)
+ {
+ return raiseTestError("test_longlong_api", msg);
+ }
+
+ #define TESTNAME test_longlong_api_inner
+ #define TYPENAME LONG_LONG
+ #define F_S_TO_PY PyLong_FromLongLong
+ #define F_PY_TO_S PyLong_AsLongLong
+ #define F_U_TO_PY PyLong_FromUnsignedLongLong
+ #define F_PY_TO_U PyLong_AsUnsignedLongLong
+
+ #include "testcapi_long.h"
+
+ static PyObject *
+ test_longlong_api(PyObject* self, PyObject* args)
+ {
+ if (!PyArg_ParseTuple(args, ":test_longlong_api"))
+ return NULL;
+
+ return TESTNAME(raise_test_longlong_error);
+ }
+
+ #undef TESTNAME
+ #undef TYPENAME
+ #undef F_S_TO_PY
+ #undef F_PY_TO_S
+ #undef F_U_TO_PY
+ #undef F_PY_TO_U
+
+ #endif /* ifdef HAVE_LONG_LONG */
+
+
static PyMethodDef TestMethods[] = {
! {"test_config", test_config, METH_VARARGS},
! {"test_list_api", test_list_api, METH_VARARGS},
! {"test_dict_iteration", test_dict_iteration, METH_VARARGS},
! {"test_long_api", test_long_api, METH_VARARGS},
! #ifdef HAVE_LONG_LONG
! {"test_longlong_api", test_longlong_api, METH_VARARGS},
! #endif
{NULL, NULL} /* sentinel */
};
Index: _tkinter.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_tkinter.c,v
retrieving revision 1.115
retrieving revision 1.115.6.1
diff -C2 -r1.115 -r1.115.6.1
*** _tkinter.c 2000年10月29日 00:44:43 1.115
--- _tkinter.c 2001年07月07日 22:55:29 1.115.6.1
***************
*** 1852,1856 ****
context->maxsize = maxsize;
! return _PyTuple_Resize(&context->tuple, maxsize, 0) >= 0;
}
--- 1852,1856 ----
context->maxsize = maxsize;
! return _PyTuple_Resize(&context->tuple, maxsize) >= 0;
}
***************
*** 1936,1940 ****
return NULL;
! if (_PyTuple_Resize(&context.tuple, context.size, 0))
return NULL;
--- 1936,1940 ----
return NULL;
! if (_PyTuple_Resize(&context.tuple, context.size))
return NULL;
Index: _weakref.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_weakref.c,v
retrieving revision 1.10
retrieving revision 1.10.4.1
diff -C2 -r1.10 -r1.10.4.1
*** _weakref.c 2001年04月13日 17:15:47 1.10
--- _weakref.c 2001年07月07日 22:55:29 1.10.4.1
***************
*** 737,741 ****
|| object->ob_refcnt != 0) {
PyErr_BadInternalCall();
- /* not sure what we should return here */
return;
}
--- 737,740 ----
***************
*** 793,797 ****
}
}
- return;
}
--- 792,795 ----
Index: arraymodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v
retrieving revision 2.62
retrieving revision 2.62.6.1
diff -C2 -r2.62 -r2.62.6.1
*** arraymodule.c 2001年01月25日 22:12:43 2.62
--- arraymodule.c 2001年07月07日 22:55:29 2.62.6.1
***************
*** 1543,1547 ****
0, /* tp_getattro */
0, /* tp_setattro */
! &array_as_buffer, /* tp_as _buffer*/
Py_TPFLAGS_DEFAULT, /* tp_flags */
arraytype_doc, /* tp_doc */
--- 1543,1547 ----
0, /* tp_getattro */
0, /* tp_setattro */
! &array_as_buffer, /* tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /* tp_flags */
arraytype_doc, /* tp_doc */
Index: binascii.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/binascii.c,v
retrieving revision 2.28
retrieving revision 2.28.6.1
diff -C2 -r2.28 -r2.28.6.1
*** binascii.c 2001年01月09日 02:11:57 2.28
--- binascii.c 2001年07月07日 22:55:29 2.28.6.1
***************
*** 336,339 ****
--- 336,343 ----
return NULL;
+ if ( ascii_len == 0) {
+ PyErr_SetString(Error, "Cannot decode empty input");
+ return NULL;
+ }
bin_len = ((ascii_len+3)/4)*3; /* Upper bound, corrected later */
Index: fcntlmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/fcntlmodule.c,v
retrieving revision 2.28
retrieving revision 2.28.6.1
diff -C2 -r2.28 -r2.28.6.1
*** fcntlmodule.c 2001年01月25日 10:10:39 2.28
--- fcntlmodule.c 2001年07月07日 22:55:29 2.28.6.1
***************
*** 16,19 ****
--- 16,31 ----
+ static int
+ conv_descriptor(PyObject *object, int *target)
+ {
+ int fd = PyObject_AsFileDescriptor(object);
+
+ if (fd < 0)
+ return 0;
+ *target = fd;
+ return 1;
+ }
+
+
/* fcntl(fd, opt, [arg]) */
***************
*** 29,33 ****
char buf[1024];
! if (PyArg_ParseTuple(args, "iis#:fcntl", &fd, &code, &str, &len)) {
if (len > sizeof buf) {
PyErr_SetString(PyExc_ValueError,
--- 41,46 ----
char buf[1024];
! if (PyArg_ParseTuple(args, "O&is#:fcntl",
! conv_descriptor, &fd, &code, &str, &len)) {
if (len > sizeof buf) {
PyErr_SetString(PyExc_ValueError,
***************
*** 48,53 ****
PyErr_Clear();
arg = 0;
! if (!PyArg_ParseTuple(args, "ii|i;fcntl requires 2 integers and optionally a third integer or a string",
! &fd, &code, &arg)) {
return NULL;
}
--- 61,68 ----
PyErr_Clear();
arg = 0;
! if (!PyArg_ParseTuple(args,
! "O&i|i;fcntl requires a file or file descriptor,"
! " an integer and optionally a third integer or a string",
! conv_descriptor, &fd, &code, &arg)) {
return NULL;
}
***************
*** 67,77 ****
\n\
Perform the requested operation on file descriptor fd. The operation\n\
! is defined by op and is operating system dependent. Typically these\n\
! codes can be retrieved from the library module FCNTL. The argument arg\n\
! is optional, and defaults to 0; it may be an int or a string. If arg is\n\
! given as a string, the return value of fcntl is a string of that length,\n\
! containing the resulting value put in the arg buffer by the operating system.\n\
! The length of the arg string is not allowed to exceed 1024 bytes. If the arg\n\
! given is an integer or if none is specified, the result value is an integer\n\
corresponding to the return value of the fcntl call in the C code.";
--- 82,92 ----
\n\
Perform the requested operation on file descriptor fd. The operation\n\
! is defined by op and is operating system dependent. These constants are\n\
! available from the fcntl module. The argument arg is optional, and\n\
! defaults to 0; it may be an int or a string. If arg is given as a string,\n\
! the return value of fcntl is a string of that length, containing the\n\
! resulting value put in the arg buffer by the operating system.The length\n\
! of the arg string is not allowed to exceed 1024 bytes. If the arg given\n\
! is an integer or if none is specified, the result value is an integer\n\
corresponding to the return value of the fcntl call in the C code.";
***************
*** 90,94 ****
char buf[1024];
! if (PyArg_ParseTuple(args, "iis#:ioctl", &fd, &code, &str, &len)) {
if (len > sizeof buf) {
PyErr_SetString(PyExc_ValueError,
--- 105,110 ----
char buf[1024];
! if (PyArg_ParseTuple(args, "O&is#:ioctl",
! conv_descriptor, &fd, &code, &str, &len)) {
if (len > sizeof buf) {
PyErr_SetString(PyExc_ValueError,
***************
*** 109,114 ****
PyErr_Clear();
arg = 0;
! if (!PyArg_ParseTuple(args, "ii|i;ioctl requires 2 integers and optionally a third integer or a string",
! &fd, &code, &arg)) {
return NULL;
}
--- 125,132 ----
PyErr_Clear();
arg = 0;
! if (!PyArg_ParseTuple(args,
! "O&i|i;ioctl requires a file or file descriptor,"
! " an integer and optionally a third integer or a string",
! conv_descriptor, &fd, &code, &arg)) {
return NULL;
}
***************
*** 146,150 ****
int ret;
! if (!PyArg_ParseTuple(args, "ii:flock", &fd, &code))
return NULL;
--- 164,169 ----
int ret;
! if (!PyArg_ParseTuple(args, "O&i:flock",
! conv_descriptor, &fd, &code))
return NULL;
***************
*** 203,207 ****
PyObject *lenobj = NULL, *startobj = NULL;
! if (!PyArg_ParseTuple(args, "ii|OOi:lockf", &fd, &code,
&lenobj, &startobj, &whence))
return NULL;
--- 222,227 ----
PyObject *lenobj = NULL, *startobj = NULL;
! if (!PyArg_ParseTuple(args, "O&i|OOi:lockf",
! conv_descriptor, &fd, &code,
&lenobj, &startobj, &whence))
return NULL;
***************
*** 325,328 ****
--- 345,393 ----
if (ins(d, "LOCK_NB", (long)LOCK_NB)) return -1;
if (ins(d, "LOCK_UN", (long)LOCK_UN)) return -1;
+ #ifdef F_DUPFD
+ if (ins(d, "F_DUPFD", (long)F_DUPFD)) return -1;
+ #endif
+ #ifdef F_GETFD
+ if (ins(d, "F_GETFD", (long)F_GETFD)) return -1;
+ #endif
+ #ifdef F_SETFD
+ if (ins(d, "F_SETFD", (long)F_SETFD)) return -1;
+ #endif
+ #ifdef F_GETFL
+ if (ins(d, "F_GETFL", (long)F_GETFL)) return -1;
+ #endif
+ #ifdef F_SETFL
+ if (ins(d, "F_SETFL", (long)F_SETFL)) return -1;
+ #endif
+ #ifdef F_GETLK
+ if (ins(d, "F_GETLK", (long)F_GETLK)) return -1;
+ #endif
+ #ifdef F_SETLK
+ if (ins(d, "F_SETLK", (long)F_SETLK)) return -1;
+ #endif
+ #ifdef F_SETLKW
+ if (ins(d, "F_SETLKW", (long)F_SETLKW)) return -1;
+ #endif
+ #ifdef F_GETOWN
+ if (ins(d, "F_GETOWN", (long)F_GETOWN)) return -1;
+ #endif
+ #ifdef F_SETOWN
+ if (ins(d, "F_SETOWN", (long)F_SETOWN)) return -1;
+ #endif
+ #ifdef F_GETSIG
+ if (ins(d, "F_GETSIG", (long)F_GETSIG)) return -1;
+ #endif
+ #ifdef F_SETSIG
+ if (ins(d, "F_SETSIG", (long)F_SETSIG)) return -1;
+ #endif
+ #ifdef F_RDLCK
+ if (ins(d, "F_RDLCK", (long)F_RDLCK)) return -1;
+ #endif
+ #ifdef F_WRLCK
+ if (ins(d, "F_WRLCK", (long)F_WRLCK)) return -1;
+ #endif
+ #ifdef F_UNLCK
+ if (ins(d, "F_UNLCK", (long)F_UNLCK)) return -1;
+ #endif
return 0;
}
Index: main.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/main.c,v
retrieving revision 1.52
retrieving revision 1.52.4.1
diff -C2 -r1.52 -r1.52.4.1
*** main.c 2001年04月10日 22:07:07 1.52
--- main.c 2001年07月07日 22:55:29 1.52.4.1
***************
*** 15,19 ****
#define PYTHONHOMEHELP "<prefix>\\lib"
#else
! #define PYTHONHOMEHELP "<prefix>/python2.0"
#endif
--- 15,19 ----
#define PYTHONHOMEHELP "<prefix>\\lib"
#else
! #define PYTHONHOMEHELP "<prefix>/pythonX.X"
#endif
Index: makesetup
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/makesetup,v
retrieving revision 1.35
retrieving revision 1.35.6.1
diff -C2 -r1.35 -r1.35.6.1
*** makesetup 2001年03月02日 07:09:54 1.35
--- makesetup 2001年07月07日 22:55:29 1.35.6.1
***************
*** 217,221 ****
esac
case $doconfig in
! no) cc="$cc \$(CCSHARED) \$(CFLAGS)";;
*)
cc="$cc \$(PY_CFLAGS)";;
--- 217,221 ----
esac
case $doconfig in
! no) cc="$cc \$(CCSHARED) \$(CFLAGS) \$(CPPFLAGS)";;
*)
cc="$cc \$(PY_CFLAGS)";;
Index: mathmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mathmodule.c,v
retrieving revision 2.58
retrieving revision 2.58.8.1
diff -C2 -r2.58 -r2.58.8.1
*** mathmodule.c 2000年10月12日 19:42:00 2.58
--- mathmodule.c 2001年07月07日 22:55:29 2.58.8.1
***************
*** 129,133 ****
FUNC1(floor, floor,
"floor(x)\n\nReturn the floor of x as a real.")
! FUNC2(fmod, fmod,
"fmod(x,y)\n\nReturn fmod(x, y), according to platform C."
" x % y may differ.")
--- 129,133 ----
FUNC1(floor, floor,
"floor(x)\n\nReturn the floor of x as a real.")
! FUNC2(fmod, fmod,
"fmod(x,y)\n\nReturn fmod(x, y), according to platform C."
" x % y may differ.")
Index: mmapmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/mmapmodule.c,v
retrieving revision 2.28
retrieving revision 2.28.2.1
diff -C2 -r2.28 -r2.28.2.1
*** mmapmodule.c 2001年04月21日 02:46:11 2.28
--- mmapmodule.c 2001年07月07日 22:55:29 2.28.2.1
***************
*** 164,177 ****
PyObject *args)
{
- char value;
- char *where;
CHECK_VALID(NULL);
if (!PyArg_ParseTuple(args, ":read_byte"))
return NULL;
if (self->pos < self->size) {
! where = self->data + self->pos;
! value = (char) *(where);
self->pos += 1;
! return Py_BuildValue("c", (char) *(where));
} else {
PyErr_SetString (PyExc_ValueError, "read byte out of range");
--- 164,174 ----
PyObject *args)
{
CHECK_VALID(NULL);
if (!PyArg_ParseTuple(args, ":read_byte"))
return NULL;
if (self->pos < self->size) {
! char value = self->data[self->pos];
self->pos += 1;
! return Py_BuildValue("c", value);
} else {
PyErr_SetString (PyExc_ValueError, "read byte out of range");
***************
*** 228,241 ****
PyObject *args)
{
! int start = self->pos;
char *needle;
int len;
CHECK_VALID(NULL);
! if (!PyArg_ParseTuple (args, "s#|i:find", &needle, &len, &start)) {
return NULL;
} else {
! char *p = self->data+self->pos;
! char *e = self->data+self->size;
while (p < e) {
char *s = p;
--- 225,247 ----
PyObject *args)
{
! long start = self->pos;
char *needle;
int len;
CHECK_VALID(NULL);
! if (!PyArg_ParseTuple (args, "s#|l:find", &needle, &len, &start)) {
return NULL;
} else {
! char *p;
! char *e = self->data + self->size;
!
! if (start < 0)
! start += self->size;
! if (start < 0)
! start = 0;
! else if ((size_t)start > self->size)
! start = self->size;
! p = self->data + start;
!
while (p < e) {
char *s = p;
***************
*** 246,251 ****
if (!*n) {
return Py_BuildValue (
! "i",
! (int) (p - (self->data + start)));
}
p++;
--- 252,257 ----
if (!*n) {
return Py_BuildValue (
! "l",
! (long) (p - self->data));
}
p++;
Index: parsermodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/parsermodule.c,v
retrieving revision 2.60
retrieving revision 2.60.6.1
diff -C2 -r2.60 -r2.60.6.1
*** parsermodule.c 2001年01月07日 05:59:59 2.60
--- parsermodule.c 2001年07月07日 22:55:29 2.60.6.1
***************
*** 2525,2529 ****
node* next = 0; /* node to process after this one */
! while (res & (tree != 0)) {
nch = NCH(tree);
next = 0;
--- 2525,2529 ----
node* next = 0; /* node to process after this one */
! while (res && (tree != 0)) {
nch = NCH(tree);
next = 0;
Index: pcremodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pcremodule.c,v
retrieving revision 2.25
retrieving revision 2.25.8.1
diff -C2 -r2.25 -r2.25.8.1
*** pcremodule.c 2000年09月01日 23:29:27 2.25
--- pcremodule.c 2001年07月07日 22:55:29 2.25.8.1
***************
*** 75,79 ****
PyObject *list;
! if (!PyArg_ParseTuple(args, "t#|iiii:match", &string, &stringlen, &pos, &endpos, &options))
return NULL;
if (endpos == -1) {endpos = stringlen;}
--- 75,80 ----
PyObject *list;
! if (!PyArg_ParseTuple(args, "t#|iii:match", &string, &stringlen,
! &pos, &endpos, &options))
return NULL;
if (endpos == -1) {endpos = stringlen;}
Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.187
retrieving revision 2.187.4.1
diff -C2 -r2.187 -r2.187.4.1
*** posixmodule.c 2001年04月14日 17:55:09 2.187
--- posixmodule.c 2001年07月07日 22:55:29 2.187.4.1
***************
*** 64,73 ****
#define HAVE_EXECV 1
#define HAVE_GETCWD 1
- #define HAVE_GETEGID 1
- #define HAVE_GETEUID 1
- #define HAVE_GETGID 1
- #define HAVE_GETPPID 1
- #define HAVE_GETUID 1
- #define HAVE_KILL 1
#define HAVE_OPENDIR 1
#define HAVE_PIPE 1
--- 64,67 ----
***************
*** 153,157 ****
--- 147,155 ----
extern int rmdir(const char *);
#endif
+ #ifdef __BORLANDC__
+ extern int chmod(const char *, int);
+ #else
extern int chmod(const char *, mode_t);
+ #endif
extern int chown(const char *, uid_t, gid_t);
extern char *getcwd(char *, int);
***************
*** 355,358 ****
--- 353,364 ----
}
+ static PyObject *
+ posix_error_with_allocated_filename(char* name)
+ {
+ PyObject *rc = PyErr_SetFromErrnoWithFilename(PyExc_OSError, name);
+ PyMem_Free(name);
+ return rc;
+ }
+
#ifdef MS_WIN32
static PyObject *
***************
*** 469,475 ****
posix_1str(PyObject *args, char *format, int (*func)(const char*))
{
! char *path1;
int res;
! if (!PyArg_ParseTuple(args, format, &path1))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 475,482 ----
posix_1str(PyObject *args, char *format, int (*func)(const char*))
{
! char *path1 = NULL;
int res;
! if (!PyArg_ParseTuple(args, format,
! Py_FileSystemDefaultEncoding, &path1))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 477,481 ****
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_filename(path1);
Py_INCREF(Py_None);
return Py_None;
--- 484,489 ----
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_allocated_filename(path1);
! PyMem_Free(path1);
Py_INCREF(Py_None);
return Py_None;
***************
*** 486,496 ****
int (*func)(const char *, const char *))
{
! char *path1, *path2;
int res;
! if (!PyArg_ParseTuple(args, format, &path1, &path2))
return NULL;
Py_BEGIN_ALLOW_THREADS
res = (*func)(path1, path2);
Py_END_ALLOW_THREADS
if (res != 0)
/* XXX how to report both path1 and path2??? */
--- 494,508 ----
int (*func)(const char *, const char *))
{
! char *path1 = NULL, *path2 = NULL;
int res;
! if (!PyArg_ParseTuple(args, format,
! Py_FileSystemDefaultEncoding, &path1,
! Py_FileSystemDefaultEncoding, &path2))
return NULL;
Py_BEGIN_ALLOW_THREADS
res = (*func)(path1, path2);
Py_END_ALLOW_THREADS
+ PyMem_Free(path1);
+ PyMem_Free(path2);
if (res != 0)
/* XXX how to report both path1 and path2??? */
***************
*** 552,556 ****
{
STRUCT_STAT st;
! char *path;
int res;
--- 564,568 ----
{
STRUCT_STAT st;
! char *path = NULL;
int res;
***************
*** 560,564 ****
#endif /* MS_WIN32 */
! if (!PyArg_ParseTuple(args, format, &path))
return NULL;
--- 572,577 ----
#endif /* MS_WIN32 */
! if (!PyArg_ParseTuple(args, format,
! Py_FileSystemDefaultEncoding, &path))
return NULL;
***************
*** 567,570 ****
--- 580,584 ----
/* the library call can blow up if the file name is too long! */
if (pathlen > MAX_PATH) {
+ PyMem_Free(path);
errno = ENAMETOOLONG;
return posix_error();
***************
*** 589,594 ****
Py_END_ALLOW_THREADS
if (res != 0)
! return posix_error_with_filename(path);
return _pystat_fromstructstat(st);
}
--- 603,609 ----
Py_END_ALLOW_THREADS
if (res != 0)
! return posix_error_with_allocated_filename(path);
+ PyMem_Free(path);
return _pystat_fromstructstat(st);
}
***************
*** 682,686 ****
posix_chdir(PyObject *self, PyObject *args)
{
! return posix_1str(args, "s:chdir", chdir);
}
--- 697,701 ----
posix_chdir(PyObject *self, PyObject *args)
{
! return posix_1str(args, "et:chdir", chdir);
}
***************
*** 693,700 ****
posix_chmod(PyObject *self, PyObject *args)
{
! char *path;
int i;
int res;
! if (!PyArg_ParseTuple(args, "si", &path, &i))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 708,716 ----
posix_chmod(PyObject *self, PyObject *args)
{
! char *path = NULL;
int i;
int res;
! if (!PyArg_ParseTuple(args, "eti", Py_FileSystemDefaultEncoding,
! &path, &i))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 702,706 ****
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_filename(path);
Py_INCREF(Py_None);
return Py_None;
--- 718,723 ----
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_allocated_filename(path);
! PyMem_Free(path);
Py_INCREF(Py_None);
return Py_None;
***************
*** 747,754 ****
posix_chown(PyObject *self, PyObject *args)
{
! char *path;
int uid, gid;
int res;
! if (!PyArg_ParseTuple(args, "sii:chown", &path, &uid, &gid))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 764,773 ----
posix_chown(PyObject *self, PyObject *args)
{
! char *path = NULL;
int uid, gid;
int res;
! if (!PyArg_ParseTuple(args, "etii:chown",
! Py_FileSystemDefaultEncoding, &path,
! &uid, &gid))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 756,760 ****
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_filename(path);
Py_INCREF(Py_None);
return Py_None;
--- 775,780 ----
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_allocated_filename(path);
! PyMem_Free(path);
Py_INCREF(Py_None);
return Py_None;
***************
*** 793,797 ****
posix_link(PyObject *self, PyObject *args)
{
! return posix_2str(args, "ss:link", link);
}
#endif /* HAVE_LINK */
--- 813,817 ----
posix_link(PyObject *self, PyObject *args)
{
! return posix_2str(args, "etet:link", link);
}
#endif /* HAVE_LINK */
***************
*** 814,832 ****
#if defined(MS_WIN32) && !defined(HAVE_OPENDIR)
- char *name;
- int len;
PyObject *d, *v;
HANDLE hFindFile;
WIN32_FIND_DATA FileData;
! char namebuf[MAX_PATH+5];
char ch;
! if (!PyArg_ParseTuple(args, "t#:listdir", &name, &len))
return NULL;
- if (len >= MAX_PATH) {
- PyErr_SetString(PyExc_ValueError, "path too long");
- return NULL;
- }
- strcpy(namebuf, name);
ch = namebuf[len-1];
if (ch != '/' && ch != '\\' && ch != ':')
--- 834,849 ----
#if defined(MS_WIN32) && !defined(HAVE_OPENDIR)
PyObject *d, *v;
HANDLE hFindFile;
WIN32_FIND_DATA FileData;
! /* MAX_PATH characters could mean a bigger encoded string */
! char namebuf[MAX_PATH*2+5];
! char *bufptr = namebuf;
! int len = sizeof(namebuf)/sizeof(namebuf[0]);
char ch;
! if (!PyArg_ParseTuple(args, "et#:listdir",
! Py_FileSystemDefaultEncoding, &bufptr, &len))
return NULL;
ch = namebuf[len-1];
if (ch != '/' && ch != '\\' && ch != ':')
***************
*** 842,846 ****
if (errno == ERROR_FILE_NOT_FOUND)
return PyList_New(0);
! return win32_error("FindFirstFile", name);
}
do {
--- 859,863 ----
if (errno == ERROR_FILE_NOT_FOUND)
return PyList_New(0);
! return win32_error("FindFirstFile", namebuf);
}
do {
***************
*** 866,870 ****
if (FindClose(hFindFile) == FALSE)
! return win32_error("FindClose", name);
return d;
--- 883,887 ----
if (FindClose(hFindFile) == FALSE)
! return win32_error("FindClose", namebuf);
return d;
***************
*** 1043,1046 ****
--- 1060,1085 ----
} /* end of posix_listdir */
+ #ifdef MS_WIN32
+ /* A helper function for abspath on win32 */
+ static PyObject *
+ posix__getfullpathname(PyObject *self, PyObject *args)
+ {
+ /* assume encoded strings wont more than double no of chars */
+ char inbuf[MAX_PATH*2];
+ char *inbufp = inbuf;
+ int insize = sizeof(inbuf)/sizeof(inbuf[0]);
+ char outbuf[MAX_PATH*2];
+ char *temp;
+ if (!PyArg_ParseTuple (args, "et#:_getfullpathname",
+ Py_FileSystemDefaultEncoding, &inbufp,
+ &insize))
+ return NULL;
+ if (!GetFullPathName(inbuf, sizeof(outbuf)/sizeof(outbuf[0]),
+ outbuf, &temp))
+ return win32_error("GetFullPathName", inbuf);
+ return PyString_FromString(outbuf);
+ } /* end of posix__getfullpathname */
+ #endif /* MS_WIN32 */
+
static char posix_mkdir__doc__[] =
"mkdir(path [, mode=0777]) -> None\n\
***************
*** 1051,1057 ****
{
int res;
! char *path;
int mode = 0777;
! if (!PyArg_ParseTuple(args, "s|i:mkdir", &path, &mode))
return NULL;
Py_BEGIN_ALLOW_THREADS
--- 1090,1097 ----
{
int res;
! char *path = NULL;
int mode = 0777;
! if (!PyArg_ParseTuple(args, "et|i:mkdir",
! Py_FileSystemDefaultEncoding, &path, &mode))
return NULL;
Py_BEGIN_ALLOW_THREADS
***************
*** 1063,1067 ****
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_filename(path);
Py_INCREF(Py_None);
return Py_None;
--- 1103,1108 ----
Py_END_ALLOW_THREADS
if (res < 0)
! return posix_error_with_allocated_filename(path);
! PyMem_Free(path);
Py_INCREF(Py_None);
return Py_None;
***************
*** 1096,1100 ****
posix_rename(PyObject *self, PyObject *args)
{
! return posix_2str(args, "ss:rename", rename);
}
--- 1137,1141 ----
posix_rename(PyObject *self, PyObject *args)
{
! return posix_2str(args, "etet:rename", rename);
}
***************
*** 1107,1111 ****
posix_rmdir(PyObject *self, PyObject *args)
{
! return posix_1str(args, "s:rmdir", rmdir);
}
--- 1148,1152 ----
posix_rmdir(PyObject *self, PyObject *args)
{
! return posix_1str(args, "et:rmdir", rmdir);
}
***************
*** 1118,1122 ****
posix_stat(PyObject *self, PyObject *args)
{
! return posix_do_stat(self, args, "s:stat", STAT);
}
--- 1159,1163 ----
posix_stat(PyObject *self, PyObject *args)
{
! return posix_do_stat(self, args, "et:stat", STAT);
}
***************
*** 1170,1174 ****
posix_unlink(PyObject *self, PyObject *args)
{
! return posix_1str(args, "s:remove", unlink);
}
--- 1211,1215 ----
posix_unlink(PyObject *self, PyObject *args)
{
! return posix_1str(args, "et:remove", unlink);
}
***************
*** 3114,3120 ****
{
#ifdef HAVE_LSTAT
! return posix_do_stat(self, args, "s:lstat", lstat);
#else /* !HAVE_LSTAT */
! return posix_do_stat(self, args, "s:lstat", STAT);
#endif /* !HAVE_LSTAT */
}
--- 3155,3161 ----
{
#ifdef HAVE_LSTAT
! return posix_do_stat(self, args, "et:lstat", lstat);
#else /* !HAVE_LSTAT */
! return posix_do_stat(self, args, "et:lstat", STAT);
#endif /* !HAVE_LSTAT */
}
***************
*** 3152,3156 ****
posix_symlink(PyObject *self, PyObject *args)
{
! return posix_2str(args, "ss:symlink", symlink);
}
#endif /* HAVE_SYMLINK */
--- 3193,3197 ----
posix_symlink(PyObject *self, PyObject *args)
{
! return posix_2str(args, "etet:symlink", symlink);
}
#endif /* HAVE_SYMLINK */
***************
*** 3329,3337 ****
posix_open(PyObject *self, PyObject *args)
{
! char *file;
int flag;
int mode = 0777;
int fd;
! if (!PyArg_ParseTuple(args, "si|i", &file, &flag, &mode))
return NULL;
--- 3370,3380 ----
posix_open(PyObject *self, PyObject *args)
{
! char *file = NULL;
int flag;
int mode = 0777;
int fd;
! if (!PyArg_ParseTuple(args, "eti|i",
! Py_FileSystemDefaultEncoding, &file,
! &flag, &mode))
return NULL;
***************
*** 3340,3344 ****
Py_END_ALLOW_THREADS
if (fd < 0)
! return posix_error_with_filename(file);
return PyInt_FromLong((long)fd);
}
--- 3383,3388 ----
Py_END_ALLOW_THREADS
if (fd < 0)
! return posix_error_with_allocated_filename(file);
! PyMem_Free(file);
return PyInt_FromLong((long)fd);
}
***************
*** 5459,5462 ****
--- 5503,5509 ----
#endif
{"abort", posix_abort, METH_VARARGS, posix_abort__doc__},
+ #ifdef MS_WIN32
+ {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
+ #endif
{NULL, NULL} /* Sentinel */
};
***************
*** 5618,5632 ****
! #if ( defined(_MSC_VER) || defined(__WATCOMC__) ) && !defined(__QNX__)
#define INITFUNC initnt
#define MODNAME "nt"
! #else
! #if defined(PYOS_OS2)
#define INITFUNC initos2
#define MODNAME "os2"
#else
#define INITFUNC initposix
#define MODNAME "posix"
- #endif
#endif
--- 5665,5679 ----
! #if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)) && !defined(__QNX__)
#define INITFUNC initnt
#define MODNAME "nt"
!
! #elif defined(PYOS_OS2)
#define INITFUNC initos2
#define MODNAME "os2"
+
#else
#define INITFUNC initposix
#define MODNAME "posix"
#endif
Index: pyexpat.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pyexpat.c,v
retrieving revision 2.45
retrieving revision 2.45.4.1
diff -C2 -r2.45 -r2.45.4.1
*** pyexpat.c 2001年03月24日 19:58:26 2.45
--- pyexpat.c 2001年07月07日 22:55:29 2.45.4.1
***************
*** 964,970 ****
int i;
! if (!PyArg_ParseTuple(args, "s|s:ExternalEntityParserCreate", &context,
! &encoding)) {
! return NULL;
}
--- 964,970 ----
int i;
! if (!PyArg_ParseTuple(args, "s|s:ExternalEntityParserCreate",
! &context, &encoding)) {
! return NULL;
}
***************
*** 1144,1148 ****
self->in_callback = 0;
self->handlers = NULL;
! if (namespace_separator) {
self->itself = XML_ParserCreateNS(encoding, *namespace_separator);
}
--- 1144,1148 ----
self->in_callback = 0;
self->handlers = NULL;
! if (namespace_separator != NULL) {
self->itself = XML_ParserCreateNS(encoding, *namespace_separator);
}
***************
*** 1187,1192 ****
if (self->handlers != NULL) {
for (i = 0; handler_info[i].name != NULL; i++) {
! Py_XDECREF(self->handlers[i]);
}
free(self->handlers);
--- 1187,1195 ----
if (self->handlers != NULL) {
+ PyObject *temp;
for (i = 0; handler_info[i].name != NULL; i++) {
! temp = self->handlers[i];
! self->handlers[i] = NULL;
! Py_XDECREF(temp);
}
free(self->handlers);
***************
*** 1319,1331 ****
xmlparse_traverse(xmlparseobject *op, visitproc visit, void *arg)
{
! int i, err;
! for (i = 0; handler_info[i].name != NULL; i++) {
! if (!op->handlers[i])
! continue;
! err = visit(op->handlers[i], arg);
! if (err)
! return err;
! }
! return 0;
}
--- 1322,1334 ----
xmlparse_traverse(xmlparseobject *op, visitproc visit, void *arg)
{
! int i, err;
! for (i = 0; handler_info[i].name != NULL; i++) {
! if (!op->handlers[i])
! continue;
! err = visit(op->handlers[i], arg);
! if (err)
! return err;
! }
! return 0;
}
***************
*** 1333,1338 ****
xmlparse_clear(xmlparseobject *op)
{
! clear_handlers(op, 1);
! return 0;
}
#endif
--- 1336,1341 ----
xmlparse_clear(xmlparseobject *op)
{
! clear_handlers(op, 1);
! return 0;
}
#endif
***************
*** 1383,1401 ****
pyexpat_ParserCreate(PyObject *notused, PyObject *args, PyObject *kw)
{
! char *encoding = NULL;
! char *namespace_separator = NULL;
! static char *kwlist[] = {"encoding", "namespace_separator", NULL};
!
! if (!PyArg_ParseTupleAndKeywords(args, kw, "|zz:ParserCreate", kwlist,
! &encoding, &namespace_separator))
! return NULL;
! if (namespace_separator != NULL
! && strlen(namespace_separator) != 1) {
! PyErr_SetString(PyExc_ValueError,
! "namespace_separator must be one character,"
! " omitted, or None");
! return NULL;
! }
! return newxmlparseobject(encoding, namespace_separator);
}
--- 1386,1404 ----
pyexpat_ParserCreate(PyObject *notused, PyObject *args, PyObject *kw)
{
! char *encoding = NULL;
! char *namespace_separator = NULL;
! static char *kwlist[] = {"encoding", "namespace_separator", NULL};
!
! if (!PyArg_ParseTupleAndKeywords(args, kw, "|zz:ParserCreate", kwlist,
! &encoding, &namespace_separator))
! return NULL;
! if (namespace_separator != NULL
! && strlen(namespace_separator) > 1) {
! PyErr_SetString(PyExc_ValueError,
! "namespace_separator must be at most one"
! " character, omitted, or None");
! return NULL;
! }
! return newxmlparseobject(encoding, namespace_separator);
}
***************
*** 1430,1437 ****
"Python wrapper for Expat parser.";
- /* Initialization function for the module */
-
- void initpyexpat(void); /* avoid compiler warnings */
-
#if PY_VERSION_HEX < 0x20000F0
--- 1433,1436 ----
***************
*** 1440,1453 ****
PyModule_AddObject(PyObject *m, char *name, PyObject *o)
{
! PyObject *dict;
! if (!PyModule_Check(m) || o == NULL)
! return -1;
! dict = PyModule_GetDict(m);
! if (dict == NULL)
! return -1;
! if (PyDict_SetItemString(dict, name, o))
! return -1;
! Py_DECREF(o);
! return 0;
}
--- 1439,1452 ----
PyModule_AddObject(PyObject *m, char *name, PyObject *o)
{
! PyObject *dict;
! if (!PyModule_Check(m) || o == NULL)
! return -1;
! dict = PyModule_GetDict(m);
! if (dict == NULL)
! return -1;
! if (PyDict_SetItemString(dict, name, o))
! return -1;
! Py_DECREF(o);
! return 0;
}
***************
*** 1455,1459 ****
PyModule_AddIntConstant(PyObject *m, char *name, long value)
{
! return PyModule_AddObject(m, name, PyInt_FromLong(value));
}
--- 1454,1458 ----
PyModule_AddIntConstant(PyObject *m, char *name, long value)
{
! return PyModule_AddObject(m, name, PyInt_FromLong(value));
}
***************
*** 1461,1465 ****
PyModule_AddStringConstant(PyObject *m, char *name, char *value)
{
! return PyModule_AddObject(m, name, PyString_FromString(value));
}
--- 1460,1464 ----
PyModule_AddStringConstant(PyObject *m, char *name, char *value)
{
! return PyModule_AddObject(m, name, PyString_FromString(value));
}
***************
*** 1487,1495 ****
}
DL_EXPORT(void)
! initpyexpat(void)
{
PyObject *m, *d;
! PyObject *errmod_name = PyString_FromString("pyexpat.errors");
PyObject *errors_module;
PyObject *modelmod_name;
--- 1486,1506 ----
}
+ /* Initialization function for the module */
+
+ #ifndef MODULE_NAME
+ #define MODULE_NAME "pyexpat"
+ #endif
+
+ #ifndef MODULE_INITFUNC
+ #define MODULE_INITFUNC initpyexpat
+ #endif
+
+ void MODULE_INITFUNC(void); /* avoid compiler warnings */
+
DL_EXPORT(void)
! MODULE_INITFUNC(void)
{
PyObject *m, *d;
! PyObject *errmod_name = PyString_FromString(MODULE_NAME ".errors");
PyObject *errors_module;
PyObject *modelmod_name;
***************
*** 1499,1503 ****
if (errmod_name == NULL)
return;
! modelmod_name = PyString_FromString("pyexpat.model");
if (modelmod_name == NULL)
return;
--- 1510,1514 ----
if (errmod_name == NULL)
return;
! modelmod_name = PyString_FromString(MODULE_NAME ".model");
if (modelmod_name == NULL)
return;
***************
*** 1506,1510 ****
/* Create the module and add the functions */
! m = Py_InitModule3("pyexpat", pyexpat_methods,
pyexpat_module_documentation);
--- 1517,1521 ----
/* Create the module and add the functions */
! m = Py_InitModule3(MODULE_NAME, pyexpat_methods,
pyexpat_module_documentation);
***************
*** 1548,1552 ****
errors_module = PyDict_GetItem(d, errmod_name);
if (errors_module == NULL) {
! errors_module = PyModule_New("pyexpat.errors");
if (errors_module != NULL) {
PyDict_SetItem(sys_modules, errmod_name, errors_module);
--- 1559,1563 ----
errors_module = PyDict_GetItem(d, errmod_name);
if (errors_module == NULL) {
! errors_module = PyModule_New(MODULE_NAME ".errors");
if (errors_module != NULL) {
PyDict_SetItem(sys_modules, errmod_name, errors_module);
***************
*** 1558,1562 ****
model_module = PyDict_GetItem(d, modelmod_name);
if (model_module == NULL) {
! model_module = PyModule_New("pyexpat.model");
if (model_module != NULL) {
PyDict_SetItem(sys_modules, modelmod_name, model_module);
--- 1569,1573 ----
model_module = PyDict_GetItem(d, modelmod_name);
if (model_module == NULL) {
! model_module = PyModule_New(MODULE_NAME ".model");
if (model_module != NULL) {
PyDict_SetItem(sys_modules, modelmod_name, model_module);
***************
*** 1633,1645 ****
clear_handlers(xmlparseobject *self, int decref)
{
! int i = 0;
! for (; handler_info[i].name!=NULL; i++) {
! if (decref){
! Py_XDECREF(self->handlers[i]);
! }
! self->handlers[i]=NULL;
! handler_info[i].setter(self->itself, NULL);
! }
}
--- 1644,1659 ----
clear_handlers(xmlparseobject *self, int decref)
{
! int i = 0;
! PyObject *temp;
! for (; handler_info[i].name!=NULL; i++) {
! if (decref) {
! temp = self->handlers[i];
! self->handlers[i] = NULL;
! Py_XDECREF(temp);
! }
! self->handlers[i]=NULL;
! handler_info[i].setter(self->itself, NULL);
! }
}
***************
*** 1652,1665 ****
pairsetter setter)
{
! void *start_handler=NULL;
! void *end_handler=NULL;
if (self->handlers[startHandler]
! && self->handlers[endHandler]!=Py_None) {
! start_handler=handler_info[startHandler].handler;
}
if (self->handlers[EndElement]
! && self->handlers[EndElement] !=Py_None) {
! end_handler=handler_info[endHandler].handler;
}
setter(self->itself, start_handler, end_handler);
--- 1666,1679 ----
pairsetter setter)
{
! void *start_handler = NULL;
! void *end_handler = NULL;
if (self->handlers[startHandler]
! && self->handlers[endHandler] != Py_None) {
! start_handler = handler_info[startHandler].handler;
}
if (self->handlers[EndElement]
! && self->handlers[EndElement] != Py_None) {
! end_handler = handler_info[endHandler].handler;
}
setter(self->itself, start_handler, end_handler);
Index: regexpr.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/regexpr.c,v
retrieving revision 1.33
retrieving revision 1.33.8.1
diff -C2 -r1.33 -r1.33.8.1
*** regexpr.c 2000年07月21日 06:00:07 1.33
--- regexpr.c 2001年07月07日 22:55:29 1.33.8.1
***************
*** 1384,1388 ****
goto bad_match_register;
ch = 10 * (a - '0') + ch - '0';
! if (ch <= 0 || ch >= RE_NREGS)
goto bad_match_register;
bufp->uses_registers = 1;
--- 1384,1388 ----
goto bad_match_register;
ch = 10 * (a - '0') + ch - '0';
! if (ch == 0 || ch >= RE_NREGS)
goto bad_match_register;
bufp->uses_registers = 1;
Index: selectmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/selectmodule.c,v
retrieving revision 2.50
retrieving revision 2.50.6.1
diff -C2 -r2.50 -r2.50.6.1
*** selectmodule.c 2001年03月02日 06:28:17 2.50
--- selectmodule.c 2001年07月07日 22:55:29 2.50.6.1
***************
*** 363,367 ****
int fd, events = POLLIN | POLLPRI | POLLOUT;
! if (!PyArg_ParseTuple(args, "O|i", &o, &events)) {
return NULL;
}
--- 363,367 ----
int fd, events = POLLIN | POLLPRI | POLLOUT;
! if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) {
return NULL;
}
***************
*** 393,397 ****
int fd;
! if (!PyArg_ParseTuple(args, "O", &o)) {
return NULL;
}
--- 393,397 ----
int fd;
! if (!PyArg_ParseTuple(args, "O:unregister", &o)) {
return NULL;
}
***************
*** 432,436 ****
PyObject *value = NULL, *num = NULL;
! if (!PyArg_ParseTuple(args, "|O", &tout)) {
return NULL;
}
--- 432,436 ----
PyObject *value = NULL, *num = NULL;
! if (!PyArg_ParseTuple(args, "|O:poll", &tout)) {
return NULL;
}
Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.141
retrieving revision 1.141.4.1
diff -C2 -r1.141 -r1.141.4.1
*** socketmodule.c 2001年04月16日 00:21:33 1.141
--- socketmodule.c 2001年07月07日 22:55:29 1.141.4.1
***************
*** 179,182 ****
--- 179,190 ----
#endif
+ #ifdef HAVE_STDDEF_H
+ #include <stddef.h>
+ #endif
+
+ #ifndef offsetof
+ #define offsetof(type, member) ((size_t)(&((type *)0)->member))
+ #endif
+
#ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK /* For QNX only? */
***************
*** 188,191 ****
--- 196,206 ----
#endif
+ /* XXX 24-Jun-2000 Tim: I have no idea what the code inside this block is
+ trying to do, and don't have time to look. Looks like Unix-specific code
+ in those files, though, which will never compile on Windows. */
+ #ifndef MS_WINDOWS
+ #include "addrinfo.h"
+ #endif /* ifndef MS_WINDOWS hack */
+
#ifdef USE_SSL
#include "openssl/rsa.h"
***************
*** 197,200 ****
--- 212,235 ----
#endif /* USE_SSL */
+ /* XXX 24-Jun-2000 Tim: I have no idea what the code inside this block is
+ trying to do, and don't have time to look. Looks like Unix-specific code
+ in those files, though, which will never compile on Windows. */
+ #ifndef MS_WINDOWS
+
+ #ifndef HAVE_INET_PTON
+ int inet_pton (int af, char *src, void *dst);
+ char *inet_ntop(int af, void *src, char *dst, socklen_t size);
+ #endif
+
+ /* I know this is a bad practice, but it is the easiest... */
+ #ifndef HAVE_GETADDRINFO
+ #include "getaddrinfo.c"
+ #endif
+ #ifndef HAVE_GETNAMEINFO
+ #include "getnameinfo.c"
+ #endif
+
+ #endif /* ifndef MS_WINDOWS hack */
+
#if defined(MS_WINDOWS) || defined(__BEOS__)
/* BeOS suffers from the same socket dichotomy as Win32... - [cjh] */
***************
*** 791,794 ****
--- 826,830 ----
if (!getsockaddrlen(s, &addrlen))
return NULL;
+ memset(addrbuf, 0, addrlen);
Py_BEGIN_ALLOW_THREADS
newfd = accept(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
***************
*** 962,967 ****
#ifdef __BEOS__
! /* We have incomplete socket support. */
! PyErr_SetString( PySocket_Error, "getsockopt not supported" );
return NULL;
#else
--- 998,1003 ----
#ifdef __BEOS__
! /* We have incomplete socket support. */
! PyErr_SetString(PySocket_Error, "getsockopt not supported");
return NULL;
#else
***************
*** 989,993 ****
return NULL;
res = getsockopt(s->sock_fd, level, optname,
! (void *)PyString_AsString(buf), &buflen);
if (res < 0) {
Py_DECREF(buf);
--- 1025,1029 ----
return NULL;
res = getsockopt(s->sock_fd, level, optname,
! (void *)PyString_AS_STRING(buf), &buflen);
if (res < 0) {
Py_DECREF(buf);
***************
*** 1213,1216 ****
--- 1249,1253 ----
if (!getsockaddrlen(s, &addrlen))
return NULL;
+ memset(addrbuf, 0, addrlen);
Py_BEGIN_ALLOW_THREADS
res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen);
***************
*** 1361,1365 ****
return NULL;
Py_BEGIN_ALLOW_THREADS
! n = recvfrom(s->sock_fd, PyString_AsString(buf), len, flags,
#ifndef MS_WINDOWS
#if defined(PYOS_OS2)
--- 1398,1403 ----
return NULL;
Py_BEGIN_ALLOW_THREADS
! memset(addrbuf, 0, addrlen);
! n = recvfrom(s->sock_fd, PyString_AS_STRING(buf), len, flags,
#ifndef MS_WINDOWS
#if defined(PYOS_OS2)
***************
*** 2919,2920 ****
--- 2957,2995 ----
#endif
}
+
+ /* Simplistic emulation code for inet_pton that only works for IPv4 */
+ #ifndef HAVE_INET_PTON
+ int
+ inet_pton (int af, char *src, void *dst)
+ {
+ if(af == AF_INET){
+ long packed_addr;
+ #ifdef USE_GUSI1
+ packed_addr = (long)inet_addr(src).s_addr;
+ #else
+ packed_addr = inet_addr(src);
+ #endif
+ if (packed_addr == INADDR_NONE)
+ return 0;
+ memcpy(dst, &packed_addr, 4);
+ return 1;
+ }
+ /* Should set errno to EAFNOSUPPORT */
+ return -1;
+ }
+
+ char *
+ inet_ntop(int af, void *src, char *dst, socklen_t size)
+ {
+ if (af == AF_INET) {
+ struct in_addr packed_addr;
+ if (size < 16)
+ /* Should set errno to ENOSPC. */
+ return NULL;
+ memcpy(&packed_addr, src, sizeof(packed_addr));
+ return strncpy(dst, inet_ntoa(packed_addr), size);
+ }
+ /* Should set errno to EAFNOSUPPORT */
+ return NULL;
+ }
+ #endif
Index: sre.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/sre.h,v
retrieving revision 2.18
retrieving revision 2.18.10.1
diff -C2 -r2.18 -r2.18.10.1
*** sre.h 2000年08月03日 16:29:50 2.18
--- sre.h 2001年07月07日 22:55:29 2.18.10.1
***************
*** 4,8 ****
* regular expression matching engine
*
! * Copyright (c) 1997-2000 by Secret Labs AB. All rights reserved.
*
* See the _sre.c file for information on usage and redistribution.
--- 4,8 ----
* regular expression matching engine
*
! * Copyright (c) 1997-2001 by Secret Labs AB. All rights reserved.
*
* See the _sre.c file for information on usage and redistribution.
***************
*** 14,23 ****
#include "sre_constants.h"
! /* size of a code word (must be unsigned short or larger) */
#define SRE_CODE unsigned short
typedef struct {
PyObject_VAR_HEAD
! int groups;
PyObject* groupindex;
PyObject* indexgroup;
--- 14,30 ----
#include "sre_constants.h"
! /* size of a code word (must be unsigned short or larger, and
! large enough to hold a Py_UNICODE character) */
! #ifdef Py_UNICODE_WIDE
! #define SRE_CODE unsigned long
! #else
#define SRE_CODE unsigned short
+ #endif
+ #define SRE_CODE unsigned short
+
typedef struct {
PyObject_VAR_HEAD
! int groups; /* must be first! */
PyObject* groupindex;
PyObject* indexgroup;
***************
*** 26,29 ****
--- 33,37 ----
int flags; /* flags used when compiling pattern source */
/* pattern code */
+ int codesize;
SRE_CODE code[1];
} PatternObject;
***************
*** 33,37 ****
typedef struct {
PyObject_VAR_HEAD
! PyObject* string; /* link to the target string */
PyObject* regs; /* cached list of matching spans */
PatternObject* pattern; /* link to the regex (pattern) object */
--- 41,45 ----
typedef struct {
PyObject_VAR_HEAD
! PyObject* string; /* link to the target string (must be first) */
PyObject* regs; /* cached list of matching spans */
PatternObject* pattern; /* link to the regex (pattern) object */
Index: sre_constants.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/sre_constants.h,v
retrieving revision 2.12
retrieving revision 2.12.4.1
diff -C2 -r2.12 -r2.12.4.1
*** sre_constants.h 2001年03月22日 15:50:09 2.12
--- sre_constants.h 2001年07月07日 22:55:29 2.12.4.1
***************
*** 12,16 ****
*/
! #define SRE_MAGIC 20010320
#define SRE_OP_FAILURE 0
#define SRE_OP_SUCCESS 1
--- 12,16 ----
*/
! #define SRE_MAGIC 20010701
#define SRE_OP_FAILURE 0
#define SRE_OP_SUCCESS 1
***************
*** 24,45 ****
#define SRE_OP_CATEGORY 9
#define SRE_OP_CHARSET 10
! #define SRE_OP_GROUPREF 11
! #define SRE_OP_GROUPREF_IGNORE 12
! #define SRE_OP_IN 13
! #define SRE_OP_IN_IGNORE 14
! #define SRE_OP_INFO 15
! #define SRE_OP_JUMP 16
! #define SRE_OP_LITERAL 17
! #define SRE_OP_LITERAL_IGNORE 18
! #define SRE_OP_MARK 19
! #define SRE_OP_MAX_UNTIL 20
! #define SRE_OP_MIN_UNTIL 21
! #define SRE_OP_NOT_LITERAL 22
! #define SRE_OP_NOT_LITERAL_IGNORE 23
! #define SRE_OP_NEGATE 24
! #define SRE_OP_RANGE 25
! #define SRE_OP_REPEAT 26
! #define SRE_OP_REPEAT_ONE 27
! #define SRE_OP_SUBPATTERN 28
#define SRE_AT_BEGINNING 0
#define SRE_AT_BEGINNING_LINE 1
--- 24,46 ----
#define SRE_OP_CATEGORY 9
#define SRE_OP_CHARSET 10
! #define SRE_OP_BIGCHARSET 11
! #define SRE_OP_GROUPREF 12
! #define SRE_OP_GROUPREF_IGNORE 13
! #define SRE_OP_IN 14
! #define SRE_OP_IN_IGNORE 15
! #define SRE_OP_INFO 16
! #define SRE_OP_JUMP 17
! #define SRE_OP_LITERAL 18
! #define SRE_OP_LITERAL_IGNORE 19
! #define SRE_OP_MARK 20
! #define SRE_OP_MAX_UNTIL 21
! #define SRE_OP_MIN_UNTIL 22
! #define SRE_OP_NOT_LITERAL 23
! #define SRE_OP_NOT_LITERAL_IGNORE 24
! #define SRE_OP_NEGATE 25
! #define SRE_OP_RANGE 26
! #define SRE_OP_REPEAT 27
! #define SRE_OP_REPEAT_ONE 28
! #define SRE_OP_SUBPATTERN 29
#define SRE_AT_BEGINNING 0
#define SRE_AT_BEGINNING_LINE 1
Index: stropmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/stropmodule.c,v
retrieving revision 2.75
retrieving revision 2.75.8.1
diff -C2 -r2.75 -r2.75.8.1
*** stropmodule.c 2000年09月26日 05:46:01 2.75
--- stropmodule.c 2001年07月07日 22:55:29 2.75.8.1
***************
*** 1,10 ****
-
/* strop module */
static char strop_module__doc__[] =
! "Common string manipulations, optimized for speed.\n\
! \n\
! Always use \"import string\" rather than referencing\n\
! this module directly.";
#include "Python.h"
--- 1,9 ----
/* strop module */
static char strop_module__doc__[] =
! "Common string manipulations, optimized for speed.\n"
! "\n"
! "Always use \"import string\" rather than referencing\n"
! "this module directly.";
#include "Python.h"
***************
*** 14,17 ****
--- 13,20 ----
XXX are defined for all 8-bit characters! */
+ #define WARN if (PyErr_Warn(PyExc_DeprecationWarning, \
+ "strop functions are obsolete; use string methods")) \
+ return NULL
+
/* The lstrip(), rstrip() and strip() functions are implemented
in do_strip(), which uses an additional parameter to indicate what
***************
*** 79,91 ****
static char splitfields__doc__[] =
! "split(s [,sep [,maxsplit]]) -> list of strings\n\
! splitfields(s [,sep [,maxsplit]]) -> list of strings\n\
! \n\
! Return a list of the words in the string s, using sep as the\n\
! delimiter string. If maxsplit is nonzero, splits into at most\n\
! maxsplit words. If sep is not specified, any whitespace string\n\
! is a separator. Maxsplit defaults to 0.\n\
! \n\
! (split and splitfields are synonymous)";
static PyObject *
--- 82,94 ----
static char splitfields__doc__[] =
! "split(s [,sep [,maxsplit]]) -> list of strings\n"
! "splitfields(s [,sep [,maxsplit]]) -> list of strings\n"
! "\n"
! "Return a list of the words in the string s, using sep as the\n"
! "delimiter string. If maxsplit is nonzero, splits into at most\n"
! "maxsplit words. If sep is not specified, any whitespace string\n"
! "is a separator. Maxsplit defaults to 0.\n"
! "\n"
! "(split and splitfields are synonymous)";
static PyObject *
***************
*** 97,100 ****
--- 100,104 ----
PyObject *list, *item;
+ WARN;
sub = NULL;
n = 0;
***************
*** 149,160 ****
static char joinfields__doc__[] =
! "join(list [,sep]) -> string\n\
! joinfields(list [,sep]) -> string\n\
! \n\
! Return a string composed of the words in list, with\n\
! intervening occurrences of sep. Sep defaults to a single\n\
! space.\n\
! \n\
! (join and joinfields are synonymous)";
static PyObject *
--- 153,164 ----
static char joinfields__doc__[] =
! "join(list [,sep]) -> string\n"
! "joinfields(list [,sep]) -> string\n"
! "\n"
! "Return a string composed of the words in list, with\n"
! "intervening occurrences of sep. Sep defaults to a single\n"
! "space.\n"
! "\n"
! "(join and joinfields are synonymous)";
static PyObject *
***************
*** 169,172 ****
--- 173,177 ----
intargfunc getitemfunc;
+ WARN;
if (!PyArg_ParseTuple(args, "O|t#:join", &seq, &sep, &seplen))
return NULL;
***************
*** 280,290 ****
static char find__doc__[] =
! "find(s, sub [,start [,end]]) -> in\n\
! \n\
! Return the lowest index in s where substring sub is found,\n\
! such that sub is contained within s[start,end]. Optional\n\
! arguments start and end are interpreted as in slice notation.\n\
! \n\
! Return -1 on failure.";
static PyObject *
--- 285,295 ----
static char find__doc__[] =
! "find(s, sub [,start [,end]]) -> in\n"
! "\n"
! "Return the lowest index in s where substring sub is found,\n"
! "such that sub is contained within s[start,end]. Optional\n"
! "arguments start and end are interpreted as in slice notation.\n"
! "\n"
! "Return -1 on failure.";
static PyObject *
***************
*** 294,297 ****
--- 299,303 ----
int len, n, i = 0, last = INT_MAX;
+ WARN;
if (!PyArg_ParseTuple(args, "t#t#|ii:find", &s, &len, &sub, &n, &i, &last))
return NULL;
***************
*** 322,332 ****
static char rfind__doc__[] =
! "rfind(s, sub [,start [,end]]) -> int\n\
! \n\
! Return the highest index in s where substring sub is found,\n\
! such that sub is contained within s[start,end]. Optional\n\
! arguments start and end are interpreted as in slice notation.\n\
! \n\
! Return -1 on failure.";
static PyObject *
--- 328,338 ----
static char rfind__doc__[] =
! "rfind(s, sub [,start [,end]]) -> int\n"
! "\n"
! "Return the highest index in s where substring sub is found,\n"
! "such that sub is contained within s[start,end]. Optional\n"
! "arguments start and end are interpreted as in slice notation.\n"
! "\n"
! "Return -1 on failure.";
static PyObject *
***************
*** 337,340 ****
--- 343,347 ----
int i = 0, last = INT_MAX;
+ WARN;
if (!PyArg_ParseTuple(args, "t#t#|ii:rfind", &s, &len, &sub, &n, &i, &last))
return NULL;
***************
*** 398,409 ****
static char strip__doc__[] =
! "strip(s) -> string\n\
! \n\
! Return a copy of the string s with leading and trailing\n\
! whitespace removed.";
static PyObject *
strop_strip(PyObject *self, PyObject *args)
{
return do_strip(args, BOTHSTRIP);
}
--- 405,417 ----
static char strip__doc__[] =
! "strip(s) -> string\n"
! "\n"
! "Return a copy of the string s with leading and trailing\n"
! "whitespace removed.";
static PyObject *
strop_strip(PyObject *self, PyObject *args)
{
+ WARN;
return do_strip(args, BOTHSTRIP);
}
***************
*** 411,421 ****
static char lstrip__doc__[] =
! "lstrip(s) -> string\n\
! \n\
! Return a copy of the string s with leading whitespace removed.";
static PyObject *
strop_lstrip(PyObject *self, PyObject *args)
{
return do_strip(args, LEFTSTRIP);
}
--- 419,430 ----
static char lstrip__doc__[] =
! "lstrip(s) -> string\n"
! "\n"
! "Return a copy of the string s with leading whitespace removed.";
static PyObject *
strop_lstrip(PyObject *self, PyObject *args)
{
+ WARN;
return do_strip(args, LEFTSTRIP);
}
***************
*** 423,433 ****
static char rstrip__doc__[] =
! "rstrip(s) -> string\n\
! \n\
! Return a copy of the string s with trailing whitespace removed.";
static PyObject *
strop_rstrip(PyObject *self, PyObject *args)
{
return do_strip(args, RIGHTSTRIP);
}
--- 432,443 ----
static char rstrip__doc__[] =
! "rstrip(s) -> string\n"
! "\n"
! "Return a copy of the string s with trailing whitespace removed.";
static PyObject *
strop_rstrip(PyObject *self, PyObject *args)
{
+ WARN;
return do_strip(args, RIGHTSTRIP);
}
***************
*** 435,441 ****
static char lower__doc__[] =
! "lower(s) -> string\n\
! \n\
! Return a copy of the string s converted to lowercase.";
static PyObject *
--- 445,451 ----
static char lower__doc__[] =
! "lower(s) -> string\n"
! "\n"
! "Return a copy of the string s converted to lowercase.";
static PyObject *
***************
*** 447,450 ****
--- 457,461 ----
int changed;
+ WARN;
if (!PyArg_Parse(args, "t#", &s, &n))
return NULL;
***************
*** 473,479 ****
static char upper__doc__[] =
! "upper(s) -> string\n\
! \n\
! Return a copy of the string s converted to uppercase.";
static PyObject *
--- 484,490 ----
static char upper__doc__[] =
! "upper(s) -> string\n"
! "\n"
! "Return a copy of the string s converted to uppercase.";
static PyObject *
***************
*** 485,488 ****
--- 496,500 ----
int changed;
+ WARN;
if (!PyArg_Parse(args, "t#", &s, &n))
return NULL;
***************
*** 511,518 ****
static char capitalize__doc__[] =
! "capitalize(s) -> string\n\
! \n\
! Return a copy of the string s with only its first character\n\
! capitalized.";
static PyObject *
--- 523,530 ----
static char capitalize__doc__[] =
! "capitalize(s) -> string\n"
! "\n"
! "Return a copy of the string s with only its first character\n"
! "capitalized.";
static PyObject *
***************
*** 524,527 ****
--- 536,540 ----
int changed;
+ WARN;
if (!PyArg_Parse(args, "t#", &s, &n))
return NULL;
***************
*** 559,568 ****
static char expandtabs__doc__[] =
! "expandtabs(string, [tabsize]) -> string\n\
! \n\
! Expand tabs in a string, i.e. replace them by one or more spaces,\n\
! depending on the current column and the given tab size (default 8).\n\
! The column number is reset to zero after each newline occurring in the\n\
! string. This doesn't understand other non-printing characters.";
static PyObject *
--- 572,581 ----
static char expandtabs__doc__[] =
! "expandtabs(string, [tabsize]) -> string\n"
! "\n"
! "Expand tabs in a string, i.e. replace them by one or more spaces,\n"
! "depending on the current column and the given tab size (default 8).\n"
! "The column number is reset to zero after each newline occurring in the\n"
! "string. This doesn't understand other non-printing characters.";
static PyObject *
***************
*** 579,582 ****
--- 592,596 ----
int tabsize = 8;
+ WARN;
/* Get arguments */
if (!PyArg_ParseTuple(args, "s#|i:expandtabs", &string, &stringlen, &tabsize))
***************
*** 630,638 ****
static char count__doc__[] =
! "count(s, sub[, start[, end]]) -> int\n\
! \n\
! Return the number of occurrences of substring sub in string\n\
! s[start:end]. Optional arguments start and end are\n\
! interpreted as in slice notation.";
static PyObject *
--- 644,652 ----
static char count__doc__[] =
! "count(s, sub[, start[, end]]) -> int\n"
! "\n"
! "Return the number of occurrences of substring sub in string\n"
! "s[start:end]. Optional arguments start and end are\n"
! "interpreted as in slice notation.";
static PyObject *
***************
*** 644,647 ****
--- 658,662 ----
int m, r;
+ WARN;
if (!PyArg_ParseTuple(args, "t#t#|ii:count", &s, &len, &sub, &n, &i, &last))
return NULL;
***************
*** 674,681 ****
static char swapcase__doc__[] =
! "swapcase(s) -> string\n\
! \n\
! Return a copy of the string s with upper case characters\n\
! converted to lowercase and vice versa.";
static PyObject *
--- 689,696 ----
static char swapcase__doc__[] =
! "swapcase(s) -> string\n"
! "\n"
! "Return a copy of the string s with upper case characters\n"
! "converted to lowercase and vice versa.";
static PyObject *
***************
*** 687,690 ****
--- 702,706 ----
int changed;
+ WARN;
if (!PyArg_Parse(args, "t#", &s, &n))
return NULL;
***************
*** 718,729 ****
static char atoi__doc__[] =
! "atoi(s [,base]) -> int\n\
! \n\
! Return the integer represented by the string s in the given\n\
! base, which defaults to 10. The string s must consist of one\n\
! or more digits, possibly preceded by a sign. If base is 0, it\n\
! is chosen from the leading characters of s, 0 for octal, 0x or\n\
! 0X for hexadecimal. If base is 16, a preceding 0x or 0X is\n\
! accepted.";
static PyObject *
--- 734,745 ----
static char atoi__doc__[] =
! "atoi(s [,base]) -> int\n"
! "\n"
! "Return the integer represented by the string s in the given\n"
! "base, which defaults to 10. The string s must consist of one\n"
! "or more digits, possibly preceded by a sign. If base is 0, it\n"
! "is chosen from the leading characters of s, 0 for octal, 0x or\n"
! "0X for hexadecimal. If base is 16, a preceding 0x or 0X is\n"
! "accepted.";
static PyObject *
***************
*** 735,738 ****
--- 751,755 ----
char buffer[256]; /* For errors */
+ WARN;
if (!PyArg_ParseTuple(args, "s|i:atoi", &s, &base))
return NULL;
***************
*** 770,782 ****
static char atol__doc__[] =
! "atol(s [,base]) -> long\n\
! \n\
! Return the long integer represented by the string s in the\n\
! given base, which defaults to 10. The string s must consist\n\
! of one or more digits, possibly preceded by a sign. If base\n\
! is 0, it is chosen from the leading characters of s, 0 for\n\
! octal, 0x or 0X for hexadecimal. If base is 16, a preceding\n\
! 0x or 0X is accepted. A trailing L or l is not accepted,\n\
! unless base is 0.";
static PyObject *
--- 787,799 ----
static char atol__doc__[] =
! "atol(s [,base]) -> long\n"
! "\n"
! "Return the long integer represented by the string s in the\n"
! "given base, which defaults to 10. The string s must consist\n"
! "of one or more digits, possibly preceded by a sign. If base\n"
! "is 0, it is chosen from the leading characters of s, 0 for\n"
! "octal, 0x or 0X for hexadecimal. If base is 16, a preceding\n"
! "0x or 0X is accepted. A trailing L or l is not accepted,\n"
! "unless base is 0.";
static PyObject *
***************
*** 788,791 ****
--- 805,809 ----
char buffer[256]; /* For errors */
+ WARN;
if (!PyArg_ParseTuple(args, "s|i:atol", &s, &base))
return NULL;
***************
*** 820,826 ****
static char atof__doc__[] =
! "atof(s) -> float\n\
! \n\
! Return the floating point number represented by the string s.";
static PyObject *
--- 838,844 ----
static char atof__doc__[] =
! "atof(s) -> float\n"
! "\n"
! "Return the floating point number represented by the string s.";
static PyObject *
***************
*** 832,835 ****
--- 850,854 ----
char buffer[256]; /* For errors */
+ WARN;
if (!PyArg_ParseTuple(args, "s:atof", &s))
return NULL;
***************
*** 861,869 ****
static char maketrans__doc__[] =
! "maketrans(frm, to) -> string\n\
! \n\
! Return a translation table (a string of 256 bytes long)\n\
! suitable for use in string.translate. The strings frm and to\n\
! must be of the same length.";
static PyObject *
--- 880,888 ----
static char maketrans__doc__[] =
! "maketrans(frm, to) -> string\n"
! "\n"
! "Return a translation table (a string of 256 bytes long)\n"
! "suitable for use in string.translate. The strings frm and to\n"
! "must be of the same length.";
static PyObject *
***************
*** 897,906 ****
static char translate__doc__[] =
! "translate(s,table [,deletechars]) -> string\n\
! \n\
! Return a copy of the string s, where all characters occurring\n\
! in the optional argument deletechars are removed, and the\n\
! remaining characters have been mapped through the given\n\
! translation table, which must be a string of length 256.";
static PyObject *
--- 916,925 ----
static char translate__doc__[] =
! "translate(s,table [,deletechars]) -> string\n"
! "\n"
! "Return a copy of the string s, where all characters occurring\n"
! "in the optional argument deletechars are removed, and the\n"
! "remaining characters have been mapped through the given\n"
! "translation table, which must be a string of length 256.";
static PyObject *
***************
*** 915,918 ****
--- 934,938 ----
int trans_table[256];
+ WARN;
if (!PyArg_ParseTuple(args, "St#|t#:translate", &input_obj,
&table1, &tablen, &del_table, &dellen))
***************
*** 983,987 ****
MEM, the function returns -1.
*/
! static int mymemfind(char *mem, int len, char *pat, int pat_len)
{
register int ii;
--- 1003,1008 ----
MEM, the function returns -1.
*/
! static int
! mymemfind(const char *mem, int len, const char *pat, int pat_len)
{
register int ii;
***************
*** 1007,1011 ****
mem=11111 and pat==11 also return 2.
*/
! static int mymemcnt(char *mem, int len, char *pat, int pat_len)
{
register int offset = 0;
--- 1028,1033 ----
mem=11111 and pat==11 also return 2.
*/
! static int
! mymemcnt(const char *mem, int len, const char *pat, int pat_len)
{
register int offset = 0;
***************
*** 1042,1046 ****
NULL if an error occurred.
*/
! static char *mymemreplace(char *str, int len, char *pat, int pat_len, char *sub, int sub_len, int count, int *out_len)
{
char *out_s;
--- 1064,1073 ----
NULL if an error occurred.
*/
! static char *
! mymemreplace(const char *str, int len, /* input string */
! const char *pat, int pat_len, /* pattern string to find */
! const char *sub, int sub_len, /* substitution string */
! int count, /* number of replacements */
! int *out_len)
{
char *out_s;
***************
*** 1053,1104 ****
/* find length of output string */
nfound = mymemcnt(str, len, pat, pat_len);
! if (count > 0)
! nfound = nfound > count ? count : nfound;
if (nfound == 0)
goto return_same;
new_len = len + nfound*(sub_len - pat_len);
! new_s = (char *)PyMem_MALLOC(new_len);
! if (new_s == NULL) return NULL;
*out_len = new_len;
- out_s = new_s;
-
- while (len > 0) {
- /* find index of next instance of pattern */
- offset = mymemfind(str, len, pat, pat_len);
- /* if not found, break out of loop */
- if (offset == -1) break;
-
- /* copy non matching part of input string */
- memcpy(new_s, str, offset); /* copy part of str before pat */
- str += offset + pat_len; /* move str past pattern */
- len -= offset + pat_len; /* reduce length of str remaining */
-
- /* copy substitute into the output string */
- new_s += offset; /* move new_s to dest for sub string */
- memcpy(new_s, sub, sub_len); /* copy substring into new_s */
- new_s += sub_len; /* offset new_s past sub string */
-
- /* break when we've done count replacements */
- if (--count == 0) break;
- }
- /* copy any remaining values into output string */
- if (len > 0)
- memcpy(new_s, str, len);
return out_s;
return_same:
*out_len = -1;
! return str;
}
static char replace__doc__[] =
! "replace (str, old, new[, maxsplit]) -> string\n\
! \n\
! Return a copy of string str with all occurrences of substring\n\
! old replaced by new. If the optional argument maxsplit is\n\
! given, only the first maxsplit occurrences are replaced.";
static PyObject *
--- 1080,1140 ----
/* find length of output string */
nfound = mymemcnt(str, len, pat, pat_len);
! if (count < 0)
! count = INT_MAX;
! else if (nfound > count)
! nfound = count;
if (nfound == 0)
goto return_same;
+
new_len = len + nfound*(sub_len - pat_len);
+ if (new_len == 0) {
+ /* Have to allocate something for the caller to free(). */
+ out_s = (char *)PyMem_MALLOC(1);
+ if (out_s == NULL)
+ return NULL;
+ out_s[0] = '0円';
+ }
+ else {
+ assert(new_len > 0);
+ new_s = (char *)PyMem_MALLOC(new_len);
+ if (new_s == NULL)
+ return NULL;
+ out_s = new_s;
! for (; count > 0 && len > 0; --count) {
! /* find index of next instance of pattern */
! offset = mymemfind(str, len, pat, pat_len);
! if (offset == -1)
! break;
+ /* copy non matching part of input string */
+ memcpy(new_s, str, offset);
+ str += offset + pat_len;
+ len -= offset + pat_len;
+
+ /* copy substitute into the output string */
+ new_s += offset;
+ memcpy(new_s, sub, sub_len);
+ new_s += sub_len;
+ }
+ /* copy any remaining values into output string */
+ if (len > 0)
+ memcpy(new_s, str, len);
+ }
*out_len = new_len;
return out_s;
return_same:
*out_len = -1;
! return (char *)str; /* cast away const */
}
static char replace__doc__[] =
! "replace (str, old, new[, maxsplit]) -> string\n"
! "\n"
! "Return a copy of string str with all occurrences of substring\n"
! "old replaced by new. If the optional argument maxsplit is\n"
! "given, only the first maxsplit occurrences are replaced.";
static PyObject *
***************
*** 1107,1113 ****
char *str, *pat,*sub,*new_s;
int len,pat_len,sub_len,out_len;
! int count = 0;
PyObject *new;
if (!PyArg_ParseTuple(args, "t#t#t#|i:replace",
&str, &len, &pat, &pat_len, &sub, &sub_len,
--- 1143,1150 ----
char *str, *pat,*sub,*new_s;
int len,pat_len,sub_len,out_len;
! int count = -1;
PyObject *new;
+ WARN;
if (!PyArg_ParseTuple(args, "t#t#t#|i:replace",
&str, &len, &pat, &pat_len, &sub, &sub_len,
***************
*** 1118,1121 ****
--- 1155,1164 ----
return NULL;
}
+ /* CAUTION: strop treats a replace count of 0 as infinity, unlke
+ * current (2.1) string.py and string methods. Preserve this for
+ * ... well, hard to say for what <wink>.
+ */
+ if (count == 0)
+ count = -1;
new_s = mymemreplace(str,len,pat,pat_len,sub,sub_len,count,&out_len);
if (new_s == NULL) {
***************
*** 1140,1185 ****
static PyMethodDef
strop_methods[] = {
! {"atof", strop_atof,
! METH_VARARGS, atof__doc__},
! {"atoi", strop_atoi,
! METH_VARARGS, atoi__doc__},
! {"atol", strop_atol,
! METH_VARARGS, atol__doc__},
! {"capitalize", strop_capitalize,
! METH_OLDARGS, capitalize__doc__},
! {"count", strop_count,
! METH_VARARGS, count__doc__},
! {"expandtabs", strop_expandtabs,
! METH_VARARGS, expandtabs__doc__},
! {"find", strop_find,
! METH_VARARGS, find__doc__},
! {"join", strop_joinfields,
! METH_VARARGS, joinfields__doc__},
! {"joinfields", strop_joinfields,
! METH_VARARGS, joinfields__doc__},
! {"lstrip", strop_lstrip,
! METH_OLDARGS, lstrip__doc__},
! {"lower", strop_lower,
! METH_OLDARGS, lower__doc__},
! {"maketrans", strop_maketrans,
! METH_VARARGS, maketrans__doc__},
! {"replace", strop_replace,
! METH_VARARGS, replace__doc__},
! {"rfind", strop_rfind,
! METH_VARARGS, rfind__doc__},
! {"rstrip", strop_rstrip,
! METH_OLDARGS, rstrip__doc__},
! {"split", strop_splitfields,
! METH_VARARGS, splitfields__doc__},
! {"splitfields", strop_splitfields,
! METH_VARARGS, splitfields__doc__},
! {"strip", strop_strip,
! METH_OLDARGS, strip__doc__},
! {"swapcase", strop_swapcase,
! METH_OLDARGS, swapcase__doc__},
! {"translate", strop_translate,
! METH_VARARGS, translate__doc__},
! {"upper", strop_upper,
! METH_OLDARGS, upper__doc__},
{NULL, NULL} /* sentinel */
};
--- 1183,1207 ----
static PyMethodDef
strop_methods[] = {
! {"atof", strop_atof, METH_VARARGS, atof__doc__},
! {"atoi", strop_atoi, METH_VARARGS, atoi__doc__},
! {"atol", strop_atol, METH_VARARGS, atol__doc__},
! {"capitalize", strop_capitalize, METH_OLDARGS, capitalize__doc__},
! {"count", strop_count, METH_VARARGS, count__doc__},
! {"expandtabs", strop_expandtabs, METH_VARARGS, expandtabs__doc__},
! {"find", strop_find, METH_VARARGS, find__doc__},
! {"join", strop_joinfields, METH_VARARGS, joinfields__doc__},
! {"joinfields", strop_joinfields, METH_VARARGS, joinfields__doc__},
! {"lstrip", strop_lstrip, METH_OLDARGS, lstrip__doc__},
! {"lower", strop_lower, METH_OLDARGS, lower__doc__},
! {"maketrans", strop_maketrans, METH_VARARGS, maketrans__doc__},
! {"replace", strop_replace, METH_VARARGS, replace__doc__},
! {"rfind", strop_rfind, METH_VARARGS, rfind__doc__},
! {"rstrip", strop_rstrip, METH_OLDARGS, rstrip__doc__},
! {"split", strop_splitfields, METH_VARARGS, splitfields__doc__},
! {"splitfields", strop_splitfields, METH_VARARGS, splitfields__doc__},
! {"strip", strop_strip, METH_OLDARGS, strip__doc__},
! {"swapcase", strop_swapcase, METH_OLDARGS, swapcase__doc__},
! {"translate", strop_translate, METH_VARARGS, translate__doc__},
! {"upper", strop_upper, METH_OLDARGS, upper__doc__},
{NULL, NULL} /* sentinel */
};
Index: structmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/structmodule.c,v
retrieving revision 2.42
retrieving revision 2.42.4.1
diff -C2 -r2.42 -r2.42.4.1
*** structmodule.c 2001年04月08日 23:39:38 2.42
--- structmodule.c 2001年07月07日 22:55:29 2.42.4.1
***************
*** 10,19 ****
and also as format strings to describe the layout of data in the C struct.\n\
\n\
! The optional first format char indicates byte ordering and alignment:\n\
! @: native w/native alignment(default)\n\
! =: native w/standard alignment\n\
! <: little-endian, std. alignment\n\
! >: big-endian, std. alignment\n\
! !: network, std (same as >)\n\
\n\
The remaining chars indicate types of args and must match exactly;\n\
--- 10,19 ----
and also as format strings to describe the layout of data in the C struct.\n\
\n\
! The optional first format char indicates byte order, size and alignment:\n\
! @: native order, size & alignment (default)\n\
! =: native order, std. size & alignment\n\
! <: little-endian, std. size & alignment\n\
! >: big-endian, std. size & alignment\n\
! !: same as >\n\
\n\
The remaining chars indicate types of args and must match exactly;\n\
***************
*** 23,29 ****
l:long; L:unsigned long; f:float; d:double.\n\
Special cases (preceding decimal count indicates length):\n\
! s:string (array of char); p: pascal string (w. count byte).\n\
Special case (only available in native format):\n\
P:an integer type that is wide enough to hold a pointer.\n\
Whitespace between formats is ignored.\n\
\n\
--- 23,31 ----
l:long; L:unsigned long; f:float; d:double.\n\
Special cases (preceding decimal count indicates length):\n\
! s:string (array of char); p: pascal string (with count byte).\n\
Special case (only available in native format):\n\
P:an integer type that is wide enough to hold a pointer.\n\
+ Special case (not in native mode unless 'long long' in platform C):\n\
+ q:long long; Q:unsigned long long\n\
Whitespace between formats is ignored.\n\
\n\
***************
*** 45,49 ****
/*
** XXXX We have a problem here. There are no unique alignment rules
! ** on the PowerPC mac.
*/
#ifdef __powerc
--- 47,51 ----
/*
** XXXX We have a problem here. There are no unique alignment rules
! ** on the PowerPC mac.
*/
#ifdef __powerc
***************
*** 66,69 ****
--- 68,78 ----
#define VOID_P_ALIGN (sizeof(s_void_p) - sizeof(void *))
+ /* We can't support q and Q in native mode unless the compiler does;
+ in std mode, they're 8 bytes on all platforms. */
+ #ifdef HAVE_LONG_LONG
+ typedef struct { char c; LONG_LONG x; } s_long_long;
+ #define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(LONG_LONG))
+ #endif
+
#define STRINGIFY(x) #x
***************
*** 72,75 ****
--- 81,112 ----
#endif
+ /* Helper to get a PyLongObject by hook or by crook. Caller should decref. */
+
+ static PyObject *
+ get_pylong(PyObject *v)
+ {
+ PyNumberMethods *m;
+
+ assert(v != NULL);
+ if (PyInt_Check(v))
+ return PyLong_FromLong(PyInt_AS_LONG(v));
+ if (PyLong_Check(v)) {
+ Py_INCREF(v);
+ return v;
+ }
+ m = v->ob_type->tp_as_number;
+ if (m != NULL && m->nb_long != NULL) {
+ v = m->nb_long(v);
+ if (v == NULL)
+ return NULL;
+ if (PyLong_Check(v))
+ return v;
+ Py_DECREF(v);
+ }
+ PyErr_SetString(StructError,
+ "cannot convert argument to long");
+ return NULL;
+ }
+
/* Helper routine to get a Python integer and raise the appropriate error
if it isn't one */
***************
*** 107,111 ****
--- 144,189 ----
}
+ #ifdef HAVE_LONG_LONG
+
+ /* Same, but handling native long long. */
+ static int
+ get_longlong(PyObject *v, LONG_LONG *p)
+ {
+ LONG_LONG x;
+
+ v = get_pylong(v);
+ if (v == NULL)
+ return -1;
+ assert(PyLong_Check(v));
+ x = PyLong_AsLongLong(v);
+ Py_DECREF(v);
+ if (x == (LONG_LONG)-1 && PyErr_Occurred())
+ return -1;
+ *p = x;
+ return 0;
+ }
+
+ /* Same, but handling native unsigned long long. */
+
+ static int
+ get_ulonglong(PyObject *v, unsigned LONG_LONG *p)
+ {
+ unsigned LONG_LONG x;
+
+ v = get_pylong(v);
+ if (v == NULL)
+ return -1;
+ assert(PyLong_Check(v));
+ x = PyLong_AsUnsignedLongLong(v);
+ Py_DECREF(v);
+ if (x == (unsigned LONG_LONG)-1 && PyErr_Occurred())
+ return -1;
+ *p = x;
+ return 0;
+ }
+
+ #endif
+
/* Floating point helpers */
***************
*** 396,399 ****
--- 474,488 ----
} formatdef;
+ /* A large number of small routines follow, with names of the form
+
+ [bln][up]_TYPE
+
+ [bln] distiguishes among big-endian, little-endian and native.
+ [pu] distiguishes between pack (to struct) and unpack (from struct).
+ TYPE is one of char, byte, ubyte, etc.
+ */
+
+ /* Native mode routines. ****************************************************/
+
static PyObject *
nu_char(const char *p, const formatdef *f)
***************
*** 451,454 ****
--- 540,561 ----
}
+ /* Native mode doesn't support q or Q unless the platform C supports
+ long long (or, on Windows, __int64). */
+
+ #ifdef HAVE_LONG_LONG
+
+ static PyObject *
+ nu_longlong(const char *p, const formatdef *f)
+ {
+ return PyLong_FromLongLong(*(LONG_LONG *)p);
+ }
+
+ static PyObject *
+ nu_ulonglong(const char *p, const formatdef *f)
+ {
+ return PyLong_FromUnsignedLongLong(*(unsigned LONG_LONG *)p);
+ }
+ #endif
+
static PyObject *
nu_float(const char *p, const formatdef *f)
***************
*** 586,590 ****
--- 693,720 ----
}
+ #ifdef HAVE_LONG_LONG
+
static int
+ np_longlong(char *p, PyObject *v, const formatdef *f)
+ {
+ LONG_LONG x;
+ if (get_longlong(v, &x) < 0)
+ return -1;
+ * (LONG_LONG *)p = x;
+ return 0;
+ }
+
+ static int
+ np_ulonglong(char *p, PyObject *v, const formatdef *f)
+ {
+ unsigned LONG_LONG x;
+ if (get_ulonglong(v, &x) < 0)
+ return -1;
+ * (unsigned LONG_LONG *)p = x;
+ return 0;
+ }
+ #endif
+
+ static int
np_float(char *p, PyObject *v, const formatdef *f)
{
***************
*** 643,649 ****
--- 773,785 ----
{'d', sizeof(double), DOUBLE_ALIGN, nu_double, np_double},
{'P', sizeof(void *), VOID_P_ALIGN, nu_void_p, np_void_p},
+ #ifdef HAVE_LONG_LONG
+ {'q', sizeof(LONG_LONG), LONG_LONG_ALIGN, nu_longlong, np_longlong},
+ {'Q', sizeof(LONG_LONG), LONG_LONG_ALIGN, nu_ulonglong,np_ulonglong},
+ #endif
{0}
};
+ /* Big-endian routines. *****************************************************/
+
static PyObject *
bu_int(const char *p, const formatdef *f)
***************
*** 675,678 ****
--- 811,832 ----
static PyObject *
+ bu_longlong(const char *p, const formatdef *f)
+ {
+ return _PyLong_FromByteArray((const unsigned char *)p,
+ 8,
+ 0, /* little-endian */
+ 1 /* signed */);
+ }
+
+ static PyObject *
+ bu_ulonglong(const char *p, const formatdef *f)
+ {
+ return _PyLong_FromByteArray((const unsigned char *)p,
+ 8,
+ 0, /* little-endian */
+ 0 /* signed */);
+ }
+
+ static PyObject *
bu_float(const char *p, const formatdef *f)
{
***************
*** 717,720 ****
--- 871,906 ----
static int
+ bp_longlong(char *p, PyObject *v, const formatdef *f)
+ {
+ int res;
+ v = get_pylong(v);
+ if (v == NULL)
+ return -1;
+ res = _PyLong_AsByteArray((PyLongObject *)v,
+ (unsigned char *)p,
+ 8,
+ 0, /* little_endian */
+ 1 /* signed */);
+ Py_DECREF(v);
+ return res;
+ }
+
+ static int
+ bp_ulonglong(char *p, PyObject *v, const formatdef *f)
+ {
+ int res;
+ v = get_pylong(v);
+ if (v == NULL)
+ return -1;
+ res = _PyLong_AsByteArray((PyLongObject *)v,
+ (unsigned char *)p,
+ 8,
+ 0, /* little_endian */
+ 0 /* signed */);
+ Py_DECREF(v);
+ return res;
+ }
+
+ static int
bp_float(char *p, PyObject *v, const formatdef *f)
{
***************
*** 753,756 ****
--- 939,944 ----
{'l', 4, 0, bu_int, bp_int},
{'L', 4, 0, bu_uint, bp_uint},
+ {'q', 8, 0, bu_longlong, bp_longlong},
+ {'Q', 8, 0, bu_ulonglong, bp_ulonglong},
{'f', 4, 0, bu_float, bp_float},
{'d', 8, 0, bu_double, bp_double},
***************
*** 758,761 ****
--- 946,951 ----
};
+ /* Little-endian routines. *****************************************************/
+
static PyObject *
lu_int(const char *p, const formatdef *f)
***************
*** 787,790 ****
--- 977,998 ----
static PyObject *
+ lu_longlong(const char *p, const formatdef *f)
+ {
+ return _PyLong_FromByteArray((const unsigned char *)p,
+ 8,
+ 1, /* little-endian */
+ 1 /* signed */);
+ }
+
+ static PyObject *
+ lu_ulonglong(const char *p, const formatdef *f)
+ {
+ return _PyLong_FromByteArray((const unsigned char *)p,
+ 8,
+ 1, /* little-endian */
+ 0 /* signed */);
+ }
+
+ static PyObject *
lu_float(const char *p, const formatdef *f)
{
***************
*** 829,832 ****
--- 1037,1072 ----
static int
+ lp_longlong(char *p, PyObject *v, const formatdef *f)
+ {
+ int res;
+ v = get_pylong(v);
+ if (v == NULL)
+ return -1;
+ res = _PyLong_AsByteArray((PyLongObject*)v,
+ (unsigned char *)p,
+ 8,
+ 1, /* little_endian */
+ 1 /* signed */);
+ Py_DECREF(v);
+ return res;
+ }
+
+ static int
+ lp_ulonglong(char *p, PyObject *v, const formatdef *f)
+ {
+ int res;
+ v = get_pylong(v);
+ if (v == NULL)
+ return -1;
+ res = _PyLong_AsByteArray((PyLongObject*)v,
+ (unsigned char *)p,
+ 8,
+ 1, /* little_endian */
+ 0 /* signed */);
+ Py_DECREF(v);
+ return res;
+ }
+
+ static int
lp_float(char *p, PyObject *v, const formatdef *f)
{
***************
*** 865,868 ****
--- 1105,1110 ----
{'l', 4, 0, lu_int, lp_int},
{'L', 4, 0, lu_uint, lp_uint},
+ {'q', 8, 0, lu_longlong, lp_longlong},
+ {'Q', 8, 0, lu_ulonglong, lp_ulonglong},
{'f', 4, 0, lu_float, lp_float},
{'d', 8, 0, lu_double, lp_double},
***************
*** 961,965 ****
else
num = 1;
!
e = getentry(c, f);
if (e == NULL)
--- 1203,1207 ----
else
num = 1;
!
e = getentry(c, f);
if (e == NULL)
***************
*** 1021,1025 ****
(n = PyTuple_Size(args)) < 1)
{
! PyErr_SetString(PyExc_TypeError,
"struct.pack requires at least one argument");
return NULL;
--- 1263,1267 ----
(n = PyTuple_Size(args)) < 1)
{
! PyErr_SetString(PyExc_TypeError,
"struct.pack requires at least one argument");
return NULL;
Index: termios.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/termios.c,v
retrieving revision 2.24
retrieving revision 2.24.4.1
diff -C2 -r2.24 -r2.24.4.1
*** termios.c 2001年04月11日 20:57:57 2.24
--- termios.c 2001年07月07日 22:55:30 2.24.4.1
***************
*** 6,42 ****
#include <termios.h>
! /* XXX Some systems need this to get all the symbols, while
! this breaks for others.
#include <sys/ioctl.h>
- */
static char termios__doc__[] = "\
This module provides an interface to the Posix calls for tty I/O control.\n\
For a complete description of these calls, see the Posix or Unix manual\n\
pages. It is only available for those Unix versions that support Posix\n\
! termios style tty I/O control (and then only if configured at installation\n\
! time).\n\
\n\
All functions in this module take a file descriptor fd as their first\n\
! argument. This must be an integer file descriptor, such as returned by\n\
! sys.stdin.fileno().";
!
!
! #ifdef __BEOS__
! #include <unistd.h>
! #endif
- #define BAD "bad termios argument"
-
static PyObject *TermiosError;
! /* termios = tcgetattr(fd)
! termios is
! [iflag, oflag, cflag, lflag, ispeed, ospeed, [cc[0], ..., cc[NCCS]]]
! Return the attributes of the terminal device. */
static char termios_tcgetattr__doc__[] = "\
tcgetattr(fd) -> list_of_attrs\n\
Get the tty attributes for file descriptor fd, as follows:\n\
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
--- 6,55 ----
#include <termios.h>
! #ifdef __osf__
! /* On OSF, sys/ioctl.h requires that struct termio already be defined,
! * so this needs to be included first on that platform. */
! #include <termio.h>
! #endif
#include <sys/ioctl.h>
+ #ifdef __BEOS__
+ #include <unistd.h>
+ #endif
+
+ /* HP-UX requires that this be included to pick up MDCD, MCTS, MDSR,
+ * MDTR, MRI, and MRTS (appearantly used internally by some things
+ * defined as macros; these are not used here directly).
+ */
+ #ifdef HAVE_SYS_MODEM_H
+ #include <sys/modem.h>
+ #endif
+
static char termios__doc__[] = "\
This module provides an interface to the Posix calls for tty I/O control.\n\
For a complete description of these calls, see the Posix or Unix manual\n\
pages. It is only available for those Unix versions that support Posix\n\
! termios style tty I/O control.\n\
\n\
All functions in this module take a file descriptor fd as their first\n\
! argument. This can be an integer file descriptor, such as returned by\n\
! sys.stdin.fileno(), or a file object, such as sys.stdin itself.";
static PyObject *TermiosError;
! static int fdconv(PyObject* obj, void* p)
! {
! int fd;
! fd = PyObject_AsFileDescriptor(obj);
! if (fd >= 0) {
! *(int*)p = fd;
! return 1;
! }
! return 0;
! }
static char termios_tcgetattr__doc__[] = "\
tcgetattr(fd) -> list_of_attrs\n\
+ \n\
Get the tty attributes for file descriptor fd, as follows:\n\
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc] where cc is a list\n\
***************
*** 58,62 ****
char ch;
! if (!PyArg_Parse(args, "i", &fd))
return NULL;
--- 71,76 ----
char ch;
! if (!PyArg_ParseTuple(args, "O&:tcgetattr",
! fdconv, (void*)&fd))
return NULL;
***************
*** 112,120 ****
}
- /* tcsetattr(fd, when, termios)
- Set the attributes of the terminal device. */
-
static char termios_tcsetattr__doc__[] = "\
tcsetattr(fd, when, attributes) -> None\n\
Set the tty attributes for file descriptor fd.\n\
The attributes to be set are taken from the attributes argument, which\n\
--- 126,132 ----
}
static char termios_tcsetattr__doc__[] = "\
tcsetattr(fd, when, attributes) -> None\n\
+ \n\
Set the tty attributes for file descriptor fd.\n\
The attributes to be set are taken from the attributes argument, which\n\
***************
*** 134,141 ****
int i;
! if (!PyArg_Parse(args, "(iiO)", &fd, &when, &term))
return NULL;
if (!PyList_Check(term) || PyList_Size(term) != 7) {
! PyErr_SetString(PyExc_TypeError, BAD);
return NULL;
}
--- 146,155 ----
int i;
! if (!PyArg_ParseTuple(args, "O&iO:tcsetattr",
! fdconv, &fd, &when, &term))
return NULL;
if (!PyList_Check(term) || PyList_Size(term) != 7) {
! PyErr_SetString(PyExc_TypeError,
! "tcsetattr, arg 3: must be 7 element list");
return NULL;
}
***************
*** 155,159 ****
if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
! PyErr_SetString(PyExc_TypeError, BAD);
return NULL;
}
--- 169,175 ----
if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
! PyErr_Format(PyExc_TypeError,
! "tcsetattr: attributes[6] must be %d element list",
! NCCS);
return NULL;
}
***************
*** 167,171 ****
mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
else {
! PyErr_SetString(PyExc_TypeError, BAD);
return NULL;
}
--- 183,188 ----
mode.c_cc[i] = (cc_t) PyInt_AsLong(v);
else {
! PyErr_SetString(PyExc_TypeError,
! "tcsetattr: elements of attributes must be characters or integers");
return NULL;
}
***************
*** 183,194 ****
}
- /* tcsendbreak(fd, duration)
- Generate a break condition. */
-
static char termios_tcsendbreak__doc__[] = "\
tcsendbreak(fd, duration) -> None\n\
Send a break on file descriptor fd.\n\
! A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration \n\
! has a system dependent meaning. ";
static PyObject *
--- 200,209 ----
}
static char termios_tcsendbreak__doc__[] = "\
tcsendbreak(fd, duration) -> None\n\
+ \n\
Send a break on file descriptor fd.\n\
! A zero duration sends a break for 0.25-0.5 seconds; a nonzero duration\n\
! has a system dependent meaning.";
static PyObject *
***************
*** 197,201 ****
int fd, duration;
! if (!PyArg_Parse(args, "(ii)", &fd, &duration))
return NULL;
if (tcsendbreak(fd, duration) == -1)
--- 212,217 ----
int fd, duration;
! if (!PyArg_ParseTuple(args, "O&i:tcsendbreak",
! fdconv, &fd, &duration))
return NULL;
if (tcsendbreak(fd, duration) == -1)
***************
*** 206,216 ****
}
- /* tcdrain(fd)
- Wait until all queued output to the terminal has been
- transmitted. */
-
static char termios_tcdrain__doc__[] = "\
tcdrain(fd) -> None\n\
! Wait until all output written to file descriptor fd has been transmitted. ";
static PyObject *
--- 222,229 ----
}
static char termios_tcdrain__doc__[] = "\
tcdrain(fd) -> None\n\
! \n\
! Wait until all output written to file descriptor fd has been transmitted.";
static PyObject *
***************
*** 219,223 ****
int fd;
! if (!PyArg_Parse(args, "i", &fd))
return NULL;
if (tcdrain(fd) == -1)
--- 232,237 ----
int fd;
! if (!PyArg_ParseTuple(args, "O&:tcdrain",
! fdconv, &fd))
return NULL;
if (tcdrain(fd) == -1)
***************
*** 228,237 ****
}
- /* tcflush(fd, queue)
- Clear the input and/or output queues associated with
- the terminal. */
-
static char termios_tcflush__doc__[] = "\
tcflush(fd, queue) -> None\n\
Discard queued data on file descriptor fd.\n\
The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
--- 242,248 ----
}
static char termios_tcflush__doc__[] = "\
tcflush(fd, queue) -> None\n\
+ \n\
Discard queued data on file descriptor fd.\n\
The queue selector specifies which queue: termios.TCIFLUSH for the input\n\
***************
*** 244,248 ****
int fd, queue;
! if (!PyArg_Parse(args, "(ii)", &fd, &queue))
return NULL;
if (tcflush(fd, queue) == -1)
--- 255,260 ----
int fd, queue;
! if (!PyArg_ParseTuple(args, "O&i:tcflush",
! fdconv, &fd, &queue))
return NULL;
if (tcflush(fd, queue) == -1)
***************
*** 253,262 ****
}
- /* tcflow(fd, action)
- Perform operations relating to XON/XOFF flow control on
- the terminal. */
-
static char termios_tcflow__doc__[] = "\
tcflow(fd, action) -> None\n\
Suspend or resume input or output on file descriptor fd.\n\
The action argument can be termios.TCOOFF to suspend output,\n\
--- 265,271 ----
}
static char termios_tcflow__doc__[] = "\
tcflow(fd, action) -> None\n\
+ \n\
Suspend or resume input or output on file descriptor fd.\n\
The action argument can be termios.TCOOFF to suspend output,\n\
***************
*** 269,273 ****
int fd, action;
! if (!PyArg_Parse(args, "(ii)", &fd, &action))
return NULL;
if (tcflow(fd, action) == -1)
--- 278,283 ----
int fd, action;
! if (!PyArg_ParseTuple(args, "O&i:tcflow",
! fdconv, &fd, &action))
return NULL;
if (tcflow(fd, action) == -1)
***************
*** 281,295 ****
{
{"tcgetattr", termios_tcgetattr,
! METH_OLDARGS, termios_tcgetattr__doc__},
{"tcsetattr", termios_tcsetattr,
! METH_OLDARGS, termios_tcsetattr__doc__},
{"tcsendbreak", termios_tcsendbreak,
! METH_OLDARGS, termios_tcsendbreak__doc__},
{"tcdrain", termios_tcdrain,
! METH_OLDARGS, termios_tcdrain__doc__},
{"tcflush", termios_tcflush,
! METH_OLDARGS, termios_tcflush__doc__},
{"tcflow", termios_tcflow,
! METH_OLDARGS, termios_tcflow__doc__},
{NULL, NULL}
};
--- 291,305 ----
{
{"tcgetattr", termios_tcgetattr,
! METH_VARARGS, termios_tcgetattr__doc__},
{"tcsetattr", termios_tcsetattr,
! METH_VARARGS, termios_tcsetattr__doc__},
{"tcsendbreak", termios_tcsendbreak,
! METH_VARARGS, termios_tcsendbreak__doc__},
{"tcdrain", termios_tcdrain,
! METH_VARARGS, termios_tcdrain__doc__},
{"tcflush", termios_tcflush,
! METH_VARARGS, termios_tcflush__doc__},
{"tcflow", termios_tcflow,
! METH_VARARGS, termios_tcflow__doc__},
{NULL, NULL}
};
***************
*** 370,374 ****
--- 380,386 ----
{"IXANY", IXANY},
{"IXOFF", IXOFF},
+ #ifdef IMAXBEL
{"IMAXBEL", IMAXBEL},
+ #endif
/* struct termios.c_oflag constants */
***************
*** 496,505 ****
--- 508,523 ----
{"ECHOK", ECHOK},
{"ECHONL", ECHONL},
+ #ifdef ECHOCTL
{"ECHOCTL", ECHOCTL},
+ #endif
#ifdef ECHOPRT
{"ECHOPRT", ECHOPRT},
#endif
+ #ifdef ECHOKE
{"ECHOKE", ECHOKE},
+ #endif
+ #ifdef FLUSHO
{"FLUSHO", FLUSHO},
+ #endif
{"NOFLSH", NOFLSH},
{"TOSTOP", TOSTOP},
***************
*** 527,534 ****
--- 545,560 ----
{"VSUSP", VSUSP},
{"VEOL", VEOL},
+ #ifdef VREPRINT
{"VREPRINT", VREPRINT},
+ #endif
+ #ifdef VDISCARD
{"VDISCARD", VDISCARD},
+ #endif
+ #ifdef VWERASE
{"VWERASE", VWERASE},
+ #endif
+ #ifdef VLNEXT
{"VLNEXT", VLNEXT},
+ #endif
{"VEOL2", VEOL2},
Index: timemodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/timemodule.c,v
retrieving revision 2.110
retrieving revision 2.110.4.1
diff -C2 -r2.110 -r2.110.4.1
*** timemodule.c 2001年04月10日 22:07:07 2.110
--- timemodule.c 2001年07月07日 22:55:30 2.110.4.1
***************
*** 42,50 ****
#ifdef MS_WINDOWS
#include <windows.h>
! #ifdef MS_WIN16
/* These overrides not needed for Win32 */
#define timezone _timezone
#define tzname _tzname
#define daylight _daylight
#define altzone _altzone
#endif /* MS_WIN16 */
--- 42,52 ----
#ifdef MS_WINDOWS
#include <windows.h>
! #if defined(MS_WIN16) || defined(__BORLANDC__)
/* These overrides not needed for Win32 */
#define timezone _timezone
#define tzname _tzname
#define daylight _daylight
+ #endif /* MS_WIN16 || __BORLANDC__ */
+ #ifdef MS_WIN16
#define altzone _altzone
#endif /* MS_WIN16 */
***************
*** 52,56 ****
#endif /* !__WATCOMC__ || __QNX__ */
! #if defined(MS_WIN32) && !defined(MS_WIN64)
/* Win32 has better clock replacement
XXX Win64 does not yet, but might when the platform matures. */
--- 54,58 ----
#endif /* !__WATCOMC__ || __QNX__ */
! #if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__)
/* Win32 has better clock replacement
XXX Win64 does not yet, but might when the platform matures. */
***************
*** 147,151 ****
#endif /* HAVE_CLOCK */
! #if defined(MS_WIN32) && !defined(MS_WIN64)
/* Due to Mark Hammond */
static PyObject *
--- 149,153 ----
#endif /* HAVE_CLOCK */
! #if defined(MS_WIN32) && !defined(MS_WIN64) && !defined(__BORLANDC__)
/* Due to Mark Hammond */
static PyObject *
Index: xreadlinesmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/xreadlinesmodule.c,v
retrieving revision 1.5
retrieving revision 1.5.4.1
diff -C2 -r1.5 -r1.5.4.1
*** xreadlinesmodule.c 2001年03月23日 18:30:19 1.5
--- xreadlinesmodule.c 2001年07月07日 22:55:30 1.5.4.1
***************
*** 55,65 ****
static PyObject *
! xreadlines_item(PyXReadlinesObject *a, int i)
{
- if (i != a->abslineno) {
- PyErr_SetString(PyExc_RuntimeError,
- "xreadlines object accessed out of order");
- return NULL;
- }
if (a->lineno >= a->lineslen) {
Py_XDECREF(a->lines);
--- 55,60 ----
static PyObject *
! xreadlines_common(PyXReadlinesObject *a)
{
if (a->lineno >= a->lineslen) {
Py_XDECREF(a->lines);
***************
*** 76,79 ****
--- 71,129 ----
}
+ static PyObject *
+ xreadlines_item(PyXReadlinesObject *a, int i)
+ {
+ if (i != a->abslineno) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "xreadlines object accessed out of order");
+ return NULL;
+ }
+ return xreadlines_common(a);
+ }
+
+ static PyObject *
+ xreadlines_getiter(PyXReadlinesObject *a)
+ {
+ Py_INCREF(a);
+ return (PyObject *)a;
+ }
+
+ static PyObject *
+ xreadlines_iternext(PyXReadlinesObject *a)
+ {
+ PyObject *res;
+
+ res = xreadlines_common(a);
+ if (res == NULL && PyErr_ExceptionMatches(PyExc_IndexError))
+ PyErr_Clear();
+ return res;
+ }
+
+ static PyObject *
+ xreadlines_next(PyXReadlinesObject *a, PyObject *args)
+ {
+ PyObject *res;
+
+ if (!PyArg_ParseTuple(args, ""))
+ return NULL;
+ res = xreadlines_common(a);
+ if (res == NULL && PyErr_ExceptionMatches(PyExc_IndexError))
+ PyErr_SetObject(PyExc_StopIteration, Py_None);
+ return res;
+ }
+
+ static char next_doc[] = "x.next() -> the next line or raise StopIteration";
+
+ static PyMethodDef xreadlines_methods[] = {
+ {"next", (PyCFunction)xreadlines_next, METH_VARARGS, next_doc},
+ {NULL, NULL}
+ };
+
+ static PyObject *
+ xreadlines_getattr(PyObject *a, char *name)
+ {
+ return Py_FindMethod(xreadlines_methods, a, name);
+ }
+
static PySequenceMethods xreadlines_as_sequence = {
0, /*sq_length*/
***************
*** 89,112 ****
sizeof(PyXReadlinesObject) + PyGC_HEAD_SIZE,
0,
! (destructor)xreadlines_dealloc, /*tp_dealloc*/
! 0, /*tp_print*/
! 0, /*tp_getattr*/
! 0, /*tp_setattr*/
! 0, /*tp_compare*/
! 0, /*tp_repr*/
! 0, /*tp_as_number*/
! &xreadlines_as_sequence, /*tp_as_sequence*/
! 0, /*tp_as_mapping*/
! 0, /*tp_hash*/
! 0, /*tp_call*/
! 0, /*tp_str*/
! 0, /*tp_getattro*/
! 0, /*tp_setattro*/
! 0, /*tp_as_buffer*/
! Py_TPFLAGS_DEFAULT, /*tp_flags*/
! 0, /* tp_doc */
};
! static PyMethodDef xreadlines_methods[] = {
{"xreadlines", xreadlines, METH_VARARGS, xreadlines_doc},
{NULL, NULL}
--- 139,168 ----
sizeof(PyXReadlinesObject) + PyGC_HEAD_SIZE,
0,
! (destructor)xreadlines_dealloc, /* tp_dealloc */
! 0, /* tp_print */
! xreadlines_getattr, /* tp_getattr */
! 0, /* tp_setattr */
! 0, /* tp_compare */
! 0, /* tp_repr */
! 0, /* tp_as_number */
! &xreadlines_as_sequence, /* tp_as_sequence */
! 0, /* tp_as_mapping */
! 0, /* tp_hash */
! 0, /* tp_call */
! 0, /* tp_str */
! 0, /* tp_getattro */
! 0, /* tp_setattro */
! 0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT, /* tp_flags */
! 0, /* tp_doc */
! 0, /* tp_traverse */
! 0, /* tp_clear */
! 0, /* tp_richcompare */
! 0, /* tp_weaklistoffset */
! (getiterfunc)xreadlines_getiter, /* tp_iter */
! (iternextfunc)xreadlines_iternext, /* tp_iternext */
};
! static PyMethodDef xreadlines_functions[] = {
{"xreadlines", xreadlines, METH_VARARGS, xreadlines_doc},
{NULL, NULL}
***************
*** 119,122 ****
XReadlinesObject_Type.ob_type = &PyType_Type;
! m = Py_InitModule("xreadlines", xreadlines_methods);
}
--- 175,178 ----
XReadlinesObject_Type.ob_type = &PyType_Type;
! m = Py_InitModule("xreadlines", xreadlines_functions);
}