[Python-checkins] CVS: python/dist/src/Modules socketmodule.c,1.97,1.98

Guido van Rossum python-dev@python.org
Fri, 24 Mar 2000 15:56:59 -0500 (EST)


Update of /projects/cvsroot/python/dist/src/Modules
In directory eric:/projects/python/develop/guido/src/Modules

Modified Files:
	socketmodule.c 
Log Message:
Fix all routines to use PyArg_ParseTuple(), and add ":name" to the
argument format strings.

THIS WILL PROBABLY BREAK LOTS OF CODE!!!

Also fixed a bogus string in an error message in getsockaddrlen().


Index: socketmodule.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.97
retrieving revision 1.98
diff -C2 -r1.97 -r1.98
*** socketmodule.c	2000/03/07 14:05:16	1.97
--- socketmodule.c	2000/03/24 20:56:56	1.98
***************
*** 644,648 ****
  
  	default:
! 		PyErr_SetString(PySocket_Error, "getsockaddrarg: bad family");
  		return 0;
  
--- 644,648 ----
  
  	default:
! 		PyErr_SetString(PySocket_Error, "getsockaddrlen: bad family");
  		return 0;
  
***************
*** 662,666 ****
  	PyObject *res = NULL;
  
! 	if (!PyArg_NoArgs(args))
  		return NULL;
  	if (!getsockaddrlen(s, &addrlen))
--- 662,666 ----
  	PyObject *res = NULL;
  
! 	if (!PyArg_ParseTuple(args, ":accept"))
  		return NULL;
  	if (!getsockaddrlen(s, &addrlen))
***************
*** 711,715 ****
  	int delay_flag;
  #endif
! 	if (!PyArg_Parse(args, "i", &block))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 711,715 ----
  	int delay_flag;
  #endif
! 	if (!PyArg_ParseTuple(args, "i:setblocking", &block))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 764,768 ****
  	int flag;
  
! 	if (PyArg_Parse(args, "(iii)", &level, &optname, &flag)) {
  		buf = (char *) &flag;
  		buflen = sizeof flag;
--- 764,769 ----
  	int flag;
  
! 	if (PyArg_ParseTuple(args, "iii:setsockopt",
! 			     &level, &optname, &flag)) {
  		buf = (char *) &flag;
  		buflen = sizeof flag;
***************
*** 770,775 ****
  	else {
  		PyErr_Clear();
! 		if (!PyArg_Parse(args, "(iis#)", &level, &optname,
! 				 &buf, &buflen))
  			return NULL;
  	}
--- 771,776 ----
  	else {
  		PyErr_Clear();
! 		if (!PyArg_ParseTuple(args, "iis#:setsockopt",
! 				      &level, &optname, &buf, &buflen))
  			return NULL;
  	}
***************
*** 808,812 ****
  #else
  
! 	if (!PyArg_ParseTuple(args, "ii|i", &level, &optname, &buflen))
  		return NULL;
  	
--- 809,814 ----
  #else
  
! 	if (!PyArg_ParseTuple(args, "ii|i:getsockopt",
! 			      &level, &optname, &buflen))
  		return NULL;
  	
***************
*** 855,859 ****
  	int addrlen;
  	int res;
! 	if (!getsockaddrarg(s, args, &addr, &addrlen))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 857,864 ----
  	int addrlen;
  	int res;
! 	PyObject *addro;
! 	if (!PyArg_ParseTuple(args, "O:bind", &addro))
! 		return NULL;
! 	if (!getsockaddrarg(s, addro, &addr, &addrlen))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 880,884 ****
  BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
  {
! 	if (!PyArg_NoArgs(args))
  		return NULL;
  	if (s->sock_fd != -1) {
--- 885,889 ----
  BUILD_FUNC_DEF_2(PySocketSock_close,PySocketSockObject *,s, PyObject *,args)
  {
! 	if (!PyArg_ParseTuple(args, ":close"))
  		return NULL;
  	if (s->sock_fd != -1) {
***************
*** 906,911 ****
  	int addrlen;
  	int res;
! 	if (!getsockaddrarg(s, args, &addr, &addrlen))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
  	res = connect(s->sock_fd, addr, addrlen);
--- 911,919 ----
  	int addrlen;
  	int res;
! 	PyObject *addro;
! 	if (!PyArg_ParseTuple(args, "O:connect", &addro))
  		return NULL;
+ 	if (!getsockaddrarg(s, addro, &addr, &addrlen))
+ 		return NULL;
  	Py_BEGIN_ALLOW_THREADS
  	res = connect(s->sock_fd, addr, addrlen);
***************
*** 932,936 ****
  	int addrlen;
  	int res;
! 	if (!getsockaddrarg(s, args, &addr, &addrlen))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 940,947 ----
  	int addrlen;
  	int res;
! 	PyObject *addro;
! 	if (!PyArg_ParseTuple(args, "O:connect_ex", &addro))
! 		return NULL;
! 	if (!getsockaddrarg(s, addro, &addr, &addrlen))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 954,958 ****
  BUILD_FUNC_DEF_2(PySocketSock_fileno,PySocketSockObject *,s, PyObject *,args)
  {
! 	if (!PyArg_NoArgs(args))
  		return NULL;
  	return PyInt_FromLong((long) s->sock_fd);
--- 965,969 ----
  BUILD_FUNC_DEF_2(PySocketSock_fileno,PySocketSockObject *,s, PyObject *,args)
  {
! 	if (!PyArg_ParseTuple(args, ":fileno"))
  		return NULL;
  	return PyInt_FromLong((long) s->sock_fd);
***************
*** 973,977 ****
  	int newfd;
  	PyObject *sock;
! 	if (!PyArg_NoArgs(args))
  		return NULL;
  	newfd = dup(s->sock_fd);
--- 984,988 ----
  	int newfd;
  	PyObject *sock;
! 	if (!PyArg_ParseTuple(args, ":dup"))
  		return NULL;
  	newfd = dup(s->sock_fd);
***************
*** 1002,1006 ****
  	char addrbuf[256];
  	int addrlen, res;
! 	if (!PyArg_NoArgs(args))
  		return NULL;
  	if (!getsockaddrlen(s, &addrlen))
--- 1013,1017 ----
  	char addrbuf[256];
  	int addrlen, res;
! 	if (!PyArg_ParseTuple(args, ":getsockname"))
  		return NULL;
  	if (!getsockaddrlen(s, &addrlen))
***************
*** 1030,1034 ****
  	char addrbuf[256];
  	int addrlen, res;
! 	if (!PyArg_NoArgs(args))
  		return NULL;
  	if (!getsockaddrlen(s, &addrlen))
--- 1041,1045 ----
  	char addrbuf[256];
  	int addrlen, res;
! 	if (!PyArg_ParseTuple(args, ":getpeername"))
  		return NULL;
  	if (!getsockaddrlen(s, &addrlen))
***************
*** 1058,1062 ****
  	int backlog;
  	int res;
! 	if (!PyArg_Parse(args, "i", &backlog))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 1069,1073 ----
  	int backlog;
  	int res;
! 	if (!PyArg_ParseTuple(args, "i:listen", &backlog))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 1246,1252 ****
  	int addrlen, len, n, flags;
  	flags = 0;
! 	if (!PyArg_Parse(args, "(s#O)", &buf, &len, &addro)) {
  		PyErr_Clear();
! 		if (!PyArg_Parse(args, "(s#iO)", &buf, &len, &flags, &addro))
  			return NULL;
  	}
--- 1257,1264 ----
  	int addrlen, len, n, flags;
  	flags = 0;
! 	if (!PyArg_ParseTuple(args, "s#O:sendto", &buf, &len, &addro)) {
  		PyErr_Clear();
! 		if (!PyArg_ParseTuple(args, "s#iO:sendto",
! 				      &buf, &len, &flags, &addro))
  			return NULL;
  	}
***************
*** 1275,1279 ****
  	int how;
  	int res;
! 	if (!PyArg_Parse(args, "i", &how))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 1287,1291 ----
  	int how;
  	int res;
! 	if (!PyArg_ParseTuple(args, "i:shutdown", &how))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 1296,1324 ****
  
  static PyMethodDef PySocketSock_methods[] = {
! 	{"accept",		(PyCFunction)PySocketSock_accept, 0,
  				accept_doc},
! 	{"bind",		(PyCFunction)PySocketSock_bind, 0,
  				bind_doc},
! 	{"close",		(PyCFunction)PySocketSock_close, 0,
  				close_doc},
! 	{"connect",		(PyCFunction)PySocketSock_connect, 0,
  				connect_doc},
! 	{"connect_ex",		(PyCFunction)PySocketSock_connect_ex, 0,
  				connect_ex_doc},
  #ifndef NO_DUP
! 	{"dup",			(PyCFunction)PySocketSock_dup, 0,
  				dup_doc},
  #endif
! 	{"fileno",		(PyCFunction)PySocketSock_fileno, 0,
  				fileno_doc},
  #ifdef HAVE_GETPEERNAME
! 	{"getpeername",		(PyCFunction)PySocketSock_getpeername, 0,
  				getpeername_doc},
  #endif
! 	{"getsockname",		(PyCFunction)PySocketSock_getsockname, 0,
  				getsockname_doc},
  	{"getsockopt",		(PyCFunction)PySocketSock_getsockopt, 1,
  				getsockopt_doc},
! 	{"listen",		(PyCFunction)PySocketSock_listen, 0,
  				listen_doc},
  #ifndef NO_DUP
--- 1308,1336 ----
  
  static PyMethodDef PySocketSock_methods[] = {
! 	{"accept",		(PyCFunction)PySocketSock_accept, 1,
  				accept_doc},
! 	{"bind",		(PyCFunction)PySocketSock_bind, 1,
  				bind_doc},
! 	{"close",		(PyCFunction)PySocketSock_close, 1,
  				close_doc},
! 	{"connect",		(PyCFunction)PySocketSock_connect, 1,
  				connect_doc},
! 	{"connect_ex",		(PyCFunction)PySocketSock_connect_ex, 1,
  				connect_ex_doc},
  #ifndef NO_DUP
! 	{"dup",			(PyCFunction)PySocketSock_dup, 1,
  				dup_doc},
  #endif
! 	{"fileno",		(PyCFunction)PySocketSock_fileno, 1,
  				fileno_doc},
  #ifdef HAVE_GETPEERNAME
! 	{"getpeername",		(PyCFunction)PySocketSock_getpeername, 1,
  				getpeername_doc},
  #endif
! 	{"getsockname",		(PyCFunction)PySocketSock_getsockname, 1,
  				getsockname_doc},
  	{"getsockopt",		(PyCFunction)PySocketSock_getsockopt, 1,
  				getsockopt_doc},
! 	{"listen",		(PyCFunction)PySocketSock_listen, 1,
  				listen_doc},
  #ifndef NO_DUP
***************
*** 1332,1342 ****
  	{"send",		(PyCFunction)PySocketSock_send, 1,
  				send_doc},
! 	{"sendto",		(PyCFunction)PySocketSock_sendto, 0,
  				sendto_doc},
! 	{"setblocking",		(PyCFunction)PySocketSock_setblocking, 0,
  				setblocking_doc},
! 	{"setsockopt",		(PyCFunction)PySocketSock_setsockopt, 0,
  				setsockopt_doc},
! 	{"shutdown",		(PyCFunction)PySocketSock_shutdown, 0,
  				shutdown_doc},
  	{NULL,			NULL}		/* sentinel */
--- 1344,1354 ----
  	{"send",		(PyCFunction)PySocketSock_send, 1,
  				send_doc},
! 	{"sendto",		(PyCFunction)PySocketSock_sendto, 1,
  				sendto_doc},
! 	{"setblocking",		(PyCFunction)PySocketSock_setblocking, 1,
  				setblocking_doc},
! 	{"setsockopt",		(PyCFunction)PySocketSock_setsockopt, 1,
  				setsockopt_doc},
! 	{"shutdown",		(PyCFunction)PySocketSock_shutdown, 1,
  				shutdown_doc},
  	{NULL,			NULL}		/* sentinel */
***************
*** 1403,1407 ****
  	char buf[1024];
  	int res;
! 	if (!PyArg_NoArgs(args))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 1415,1419 ----
  	char buf[1024];
  	int res;
! 	if (!PyArg_ParseTuple(args, ":gethostname"))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 1428,1432 ****
  	char *name;
  	struct sockaddr_in addrbuf;
! 	if (!PyArg_Parse(args, "s", &name))
  		return NULL;
  	if (setipaddr(name, &addrbuf) < 0)
--- 1440,1444 ----
  	char *name;
  	struct sockaddr_in addrbuf;
! 	if (!PyArg_ParseTuple(args, "s:gethostbyname", &name))
  		return NULL;
  	if (setipaddr(name, &addrbuf) < 0)
***************
*** 1519,1523 ****
  #endif
  #endif /* HAVE_GETHOSTBYNAME_R */
! 	if (!PyArg_Parse(args, "s", &name))
  		return NULL;
  	if (setipaddr(name, &addr) < 0)
--- 1531,1535 ----
  #endif
  #endif /* HAVE_GETHOSTBYNAME_R */
! 	if (!PyArg_ParseTuple(args, "s:gethostbyname_ex", &name))
  		return NULL;
  	if (setipaddr(name, &addr) < 0)
***************
*** 1579,1583 ****
  #endif /* HAVE_GETHOSTBYNAME_R */
  
! 	if (!PyArg_Parse(args, "s", &ip_num))
  		return NULL;
  	if (setipaddr(ip_num, &addr) < 0)
--- 1591,1595 ----
  #endif /* HAVE_GETHOSTBYNAME_R */
  
! 	if (!PyArg_ParseTuple(args, "s:gethostbyaddr", &ip_num))
  		return NULL;
  	if (setipaddr(ip_num, &addr) < 0)
***************
*** 1635,1639 ****
  	char *name, *proto;
  	struct servent *sp;
! 	if (!PyArg_Parse(args, "(ss)", &name, &proto))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 1647,1651 ----
  	char *name, *proto;
  	struct servent *sp;
! 	if (!PyArg_ParseTuple(args, "ss:getservbyname", &name, &proto))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 1669,1673 ****
  	return NULL;
  #else
! 	if (!PyArg_Parse(args, "s", &name))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
--- 1681,1685 ----
  	return NULL;
  #else
! 	if (!PyArg_ParseTuple(args, "s:getprotobyname", &name))
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
***************
*** 1748,1752 ****
  	PySocketSockObject *s;
  	int fd, family, type, proto = 0;
! 	if (!PyArg_ParseTuple(args, "iii|i:fromfd", &fd, &family, &type, &proto))
  		return NULL;
  	/* Dup the fd so it and the socket can be closed independently */
--- 1760,1765 ----
  	PySocketSockObject *s;
  	int fd, family, type, proto = 0;
! 	if (!PyArg_ParseTuple(args, "iii|i:fromfd",
! 			      &fd, &family, &type, &proto))
  		return NULL;
  	/* Dup the fd so it and the socket can be closed independently */
***************
*** 1777,1781 ****
  	int x1, x2;
  
! 	if (!PyArg_Parse(args, "i", &x1)) {
  		return NULL;
  	}
--- 1790,1794 ----
  	int x1, x2;
  
! 	if (!PyArg_ParseTuple(args, "i:ntohs", &x1)) {
  		return NULL;
  	}
***************
*** 1795,1799 ****
  	int x1, x2;
  
! 	if (!PyArg_Parse(args, "i", &x1)) {
  		return NULL;
  	}
--- 1808,1812 ----
  	int x1, x2;
  
! 	if (!PyArg_ParseTuple(args, "i:ntohl", &x1)) {
  		return NULL;
  	}
***************
*** 1813,1817 ****
  	int x1, x2;
  
! 	if (!PyArg_Parse(args, "i", &x1)) {
  		return NULL;
  	}
--- 1826,1830 ----
  	int x1, x2;
  
! 	if (!PyArg_ParseTuple(args, "i:htons", &x1)) {
  		return NULL;
  	}
***************
*** 1831,1835 ****
  	int x1, x2;
  
! 	if (!PyArg_Parse(args, "i", &x1)) {
  		return NULL;
  	}
--- 1844,1848 ----
  	int x1, x2;
  
! 	if (!PyArg_ParseTuple(args, "i:htonl", &x1)) {
  		return NULL;
  	}
***************
*** 1867,1871 ****
  	long packed_addr;
  
! 	if (!PyArg_Parse(args, "s", &ip_addr)) {
  		return NULL;
  	}
--- 1880,1884 ----
  	long packed_addr;
  
! 	if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) {
  		return NULL;
  	}
***************
*** 1898,1902 ****
  	struct in_addr packed_addr;
  
! 	if (!PyArg_Parse(args, "s#", &packed_str, &addr_len)) {
  		return NULL;
  	}
--- 1911,1915 ----
  	struct in_addr packed_addr;
  
! 	if (!PyArg_ParseTuple(args, "s#:inet_ntoa", &packed_str, &addr_len)) {
  		return NULL;
  	}
***************
*** 2152,2171 ****
  
  static PyMethodDef PySocket_methods[] = {
! 	{"gethostbyname",	PySocket_gethostbyname, 0, gethostbyname_doc},
! 	{"gethostbyname_ex",	PySocket_gethostbyname_ex, 0, ghbn_ex_doc},
! 	{"gethostbyaddr",	PySocket_gethostbyaddr, 0, gethostbyaddr_doc},
! 	{"gethostname",		PySocket_gethostname, 0, gethostname_doc},
! 	{"getservbyname",	PySocket_getservbyname, 0, getservbyname_doc},
! 	{"getprotobyname",	PySocket_getprotobyname, 0,getprotobyname_doc},
  	{"socket",		PySocket_socket, 1, socket_doc},
  #ifndef NO_DUP
  	{"fromfd",		PySocket_fromfd, 1, fromfd_doc},
  #endif
! 	{"ntohs",		PySocket_ntohs, 0, ntohs_doc},
! 	{"ntohl",		PySocket_ntohl, 0, ntohl_doc},
! 	{"htons",		PySocket_htons, 0, htons_doc},
! 	{"htonl",		PySocket_htonl, 0, htonl_doc},
! 	{"inet_aton",		PySocket_inet_aton, 0, inet_aton_doc},
! 	{"inet_ntoa",		PySocket_inet_ntoa, 0, inet_ntoa_doc},
  #ifdef USE_SSL
  	{"ssl",			PySocket_ssl, 1, ssl_doc},
--- 2165,2184 ----
  
  static PyMethodDef PySocket_methods[] = {
! 	{"gethostbyname",	PySocket_gethostbyname, 1, gethostbyname_doc},
! 	{"gethostbyname_ex",	PySocket_gethostbyname_ex, 1, ghbn_ex_doc},
! 	{"gethostbyaddr",	PySocket_gethostbyaddr, 1, gethostbyaddr_doc},
! 	{"gethostname",		PySocket_gethostname, 1, gethostname_doc},
! 	{"getservbyname",	PySocket_getservbyname, 1, getservbyname_doc},
! 	{"getprotobyname",	PySocket_getprotobyname, 1,getprotobyname_doc},
  	{"socket",		PySocket_socket, 1, socket_doc},
  #ifndef NO_DUP
  	{"fromfd",		PySocket_fromfd, 1, fromfd_doc},
  #endif
! 	{"ntohs",		PySocket_ntohs, 1, ntohs_doc},
! 	{"ntohl",		PySocket_ntohl, 1, ntohl_doc},
! 	{"htons",		PySocket_htons, 1, htons_doc},
! 	{"htonl",		PySocket_htonl, 1, htonl_doc},
! 	{"inet_aton",		PySocket_inet_aton, 1, inet_aton_doc},
! 	{"inet_ntoa",		PySocket_inet_ntoa, 1, inet_ntoa_doc},
  #ifdef USE_SSL
  	{"ssl",			PySocket_ssl, 1, ssl_doc},