diff --git a/Modules/config.c.in b/Modules/config.c.in index b2ca0eb8ff5..7e679613c9e 100644 --- a/Modules/config.c.in +++ b/Modules/config.c.in @@ -136,6 +136,9 @@ extern void initamoeba(); #ifdef USE_AUDIO extern void initaudio(); #endif +#ifdef USE_AUDIOOP +extern void initaudioop(); +#endif #ifdef USE_CD extern void initcd(); #endif @@ -242,6 +245,10 @@ struct { {"audio", initaudio}, #endif +#ifdef USE_AUDIOOP + {"audioop", initaudioop}, +#endif + #ifdef USE_CD {"cd", initcd}, #endif diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index b1ab96d717d..bb451ebfe6c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -57,6 +57,8 @@ Socket methods: - s.getsockopt(level, optname) --> flag - s.bind(sockaddr) --> None - s.connect(sockaddr) --> None +- s.getsockname() --> sockaddr +- s.getpeername() --> sockaddr - s.listen(n) --> None - s.makefile(mode) --> file object - s.recv(nbytes) --> string @@ -564,6 +566,50 @@ sock_fileno(s, args) } +/* s.getsockname() method */ + +static object * +sock_getsockname(s, args) + sockobject *s; + object *args; +{ + char addrbuf[256]; + int addrlen, res; + if (!getnoarg(args)) + return NULL; + if (!getsockaddrlen(s, &addrlen)) + return NULL; + BGN_SAVE + res = getsockname(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); + END_SAVE + if (res < 0) + return socket_error(); + return makesockaddr((struct sockaddr *) addrbuf, addrlen); +} + + +/* s.getpeername() method */ + +static object * +sock_getpeername(s, args) + sockobject *s; + object *args; +{ + char addrbuf[256]; + int addrlen, res; + if (!getnoarg(args)) + return NULL; + if (!getsockaddrlen(s, &addrlen)) + return NULL; + BGN_SAVE + res = getpeername(s->sock_fd, (struct sockaddr *) addrbuf, &addrlen); + END_SAVE + if (res < 0) + return socket_error(); + return makesockaddr((struct sockaddr *) addrbuf, addrlen); +} + + /* s.listen(n) method */ static object * @@ -753,6 +799,8 @@ static struct methodlist sock_methods[] = { {"close", sock_close}, {"connect", sock_connect}, {"fileno", sock_fileno}, + {"getsockname", sock_getsockname}, + {"getpeername", sock_getpeername}, {"listen", sock_listen}, {"makefile", sock_makefile}, {"recv", sock_recv}, diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index 835c7dbfce0..f00cfc78b50 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -112,6 +112,70 @@ strop_splitfields(self, args) } +static object * +strop_joinfields(self, args) + object *self; /* Not used */ + object *args; +{ + object *seq, *item, *res; + object * (*getitem) FPROTO((object *, int)); + char *sep, *p; + int seplen, seqlen, reslen, itemlen, i; + + if (!getargs(args, "(Os#)", &seq, &sep, &seplen)) + return NULL; + if (is_listobject(seq)) { + getitem = getlistitem; + seqlen = getlistsize(seq); + } + else if (is_tupleobject(seq)) { + getitem = gettupleitem; + seqlen = gettuplesize(seq); + } + else { + err_setstr(TypeError, "first argument must be list/tuple"); + return NULL; + } + reslen = 0; + for (i = 0; i < seqlen; i++) { + item = getitem(seq, i); + if (!is_stringobject(item)) { + err_setstr(TypeError, + "first argument must be list/tuple of strings"); + return NULL; + } + if (i > 0) + reslen = reslen + seplen; + reslen = reslen + getstringsize(item); + } + if (seqlen == 1) { + /* Optimization if there's only one item */ + item = getitem(seq, 0); + INCREF(item); + return item; + } + res = newsizedstringobject((char *)NULL, reslen); + if (res == NULL) + return NULL; + p = getstringvalue(res); + for (i = 0; i < seqlen; i++) { + item = getitem(seq, i); + if (i > 0) { + memcpy(p, sep, seplen); + p += seplen; + } + itemlen = getstringsize(item); + memcpy(p, getstringvalue(item), itemlen); + p += itemlen; + } + if (p != getstringvalue(res) + reslen) { + err_setstr(SystemError, "strop.joinfields: assertion failed"); + return NULL; + } + return res; +} + + static object * strop_index(self, args) object *self; /* Not used */ @@ -290,6 +354,7 @@ strop_swapcase(self, args) static struct methodlist strop_methods[] = { {"index", strop_index}, + {"joinfields", strop_joinfields}, {"lower", strop_lower}, {"split", strop_split}, {"splitfields", strop_splitfields}, diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 18fae5ca75e..a6e02bed2d6 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -601,13 +601,42 @@ builtin_reload(self, v) return reload_module(v); } +static object * +builtin_repr(self, v) + object *self; + object *v; +{ + if (v == NULL) { + err_badarg(); + return NULL; + } + return reprobject(v); +} + +static object * +builtin_str(self, v) + object *self; + object *v; +{ + if (v == NULL) { + err_badarg(); + return NULL; + } + if (is_stringobject(v)) { + INCREF(v); + return v; + } + else + return reprobject(v); +} + static object * builtin_type(self, v) object *self; object *v; { if (v == NULL) { - err_setstr(TypeError, "type() requres an argument"); + err_setstr(TypeError, "type() requires an argument"); return NULL; } v = (object *)v->ob_type; @@ -642,7 +671,9 @@ static struct methodlist builtin_methods[] = { {"range", builtin_range}, {"raw_input", builtin_raw_input}, {"reload", builtin_reload}, + {"repr", builtin_repr}, {"setattr", builtin_setattr}, + {"str", builtin_str}, {"type", builtin_type}, {NULL, NULL}, };