[Python-checkins] python/dist/src/Modules _hotshot.c,1.30,1.31 getbuildinfo.c,2.8,2.9 getpath.c,1.42,1.43 main.c,1.70,1.71 posixmodule.c,2.273,2.274 pwdmodule.c,1.36,1.37 socketmodule.c,1.246,1.247

loewis@users.sourceforge.net loewis@users.sourceforge.net
Fri, 06 Dec 2002 04:49:27 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv11610/Modules

Modified Files:
	_hotshot.c getbuildinfo.c getpath.c main.c posixmodule.c 
	pwdmodule.c socketmodule.c 
Log Message:
Patch #614055: Support OpenVMS.


Index: _hotshot.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_hotshot.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** _hotshot.c	30 Sep 2002 16:19:48 -0000	1.30
--- _hotshot.c	6 Dec 2002 12:48:49 -0000	1.31
***************
*** 948,952 ****
  #endif
      }
! #if defined(MS_WINDOWS) || defined(macintosh) || defined(PYOS_OS2)
      rusage_diff = -1;
  #else
--- 948,953 ----
  #endif
      }
! #if defined(MS_WINDOWS) || defined(macintosh) || defined(PYOS_OS2) || \
!     defined(__VMS)
      rusage_diff = -1;
  #else

Index: getbuildinfo.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/getbuildinfo.c,v
retrieving revision 2.8
retrieving revision 2.9
diff -C2 -d -r2.8 -r2.9
*** getbuildinfo.c	4 Dec 2001 01:11:32 -0000	2.8
--- getbuildinfo.c	6 Dec 2002 12:48:49 -0000	2.9
***************
*** 29,32 ****
--- 29,81 ----
  #endif
  
+ #ifdef __VMS
+ #  ifdef __DECC
+ #    pragma extern_model save
+ #    pragma extern_model strict_refdef
+ extern long ctl$gl_imghdrbf;
+ #    pragma extern_model restore
+ #  endif
+ 
+ #  ifdef __ALPHA
+ #    define EIHD$L_IMGIDOFF 24
+ #    define EIHI$Q_LINKTIME  8
+ #    define _IMGIDOFF EIHD$L_IMGIDOFF
+ #    define _LINKTIME EIHI$Q_LINKTIME
+ #  else
+ #    define IHD$W_IMGIDOFF  6
+ #    define IHI$Q_LINKTIME 56
+ #    define _IMGIDOFF IHD$W_IMGIDOFF
+ #    define _LINKTIME IHI$Q_LINKTIME
+ #  endif /* __VMS */
+ 
+ long*
+ vms__get_linktime (void)
+ {
+ 	long* al_imghdrbf;
+ 	unsigned short* aw_imgidoff;
+ 	unsigned short	  w_imgidoff;
+ 	long* aq_linktime;
+ 	unsigned char* ab_ihi;
+ 
+ 	al_imghdrbf = &ctl$gl_imghdrbf;
+ 
+ 	al_imghdrbf = (long *)*al_imghdrbf;
+ 	al_imghdrbf = (long *)*al_imghdrbf;
+ 
+ 	aw_imgidoff = (unsigned short *)
+ 		((unsigned char *)al_imghdrbf + _IMGIDOFF);
+ 
+ 	w_imgidoff = *aw_imgidoff;
+ 
+ 	ab_ihi = (unsigned char *)al_imghdrbf + w_imgidoff;
+ 
+ 	aq_linktime = (long *) (ab_ihi + _LINKTIME);
+ 
+ 	return aq_linktime;
+ } /* vms__get_linktime (void) */
+ extern void vms__cvt_v2u_time (long * aq_vmstime, time_t * al_unixtime);
+ 			    /* input		, output */
+ #endif /* __VMS */
+ 
  
  const char *
***************
*** 34,39 ****
--- 83,97 ----
  {
  	static char buildinfo[50];
+ #ifdef __VMS
+ 	time_t l_unixtime;
+ 
+ 	vms__cvt_v2u_time(vms__get_linktime (), &l_unixtime );
+ 
+ 	memset(buildinfo, 0, 40);
+ 	sprintf(buildinfo, "#%d, %.24s", BUILD, ctime (&l_unixtime));
+ #else
  	PyOS_snprintf(buildinfo, sizeof(buildinfo),
  		      "#%d, %.20s, %.9s", BUILD, DATE, TIME);
+ #endif
  	return buildinfo;
  }

Index: getpath.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/getpath.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -C2 -d -r1.42 -r1.43
*** getpath.c	13 Sep 2002 14:35:56 -0000	1.42
--- getpath.c	6 Dec 2002 12:48:50 -0000	1.43
***************
*** 93,97 ****
--- 93,101 ----
  
  #ifndef VERSION
+ #if defined(__VMS)
+ #define VERSION "2_1"
+ #else
  #define VERSION "2.1"
+ #endif
  #endif
  

Index: main.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/main.c,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** main.c	17 Oct 2002 20:37:50 -0000	1.70
--- main.c	6 Dec 2002 12:48:50 -0000	1.71
***************
*** 5,8 ****
--- 5,13 ----
  #include "compile.h" /* For CO_FUTURE_DIVISION */
  
+ #ifdef __VMS
+ extern int PyVMS_init(int* pvi_argc, char*** pvi_argv);
+ extern PyObject* pyvms_gr_empty_string;
+ #endif
+ 
  #if defined(MS_WINDOWS) || defined(__CYGWIN__)
  #include <fcntl.h>
***************
*** 99,103 ****
--- 104,119 ----
  		fprintf(f, usage_4, DELIM, DELIM, PYTHONHOMEHELP);
  	}
+ #if defined(__VMS)
+ 	if (exitcode == 0) {
+ 		/* suppress 'error' message */
+ 		exit(1);
+ 	}
+ 	else {
+ 		/* STS$M_INHIB_MSG + SS$_ABORT */
+ 		exit(0x1000002c);
+ 	}
+ #else
  	exit(exitcode);
+ #endif
  	/*NOTREACHED*/
  }
***************
*** 146,150 ****
--- 162,171 ----
  			fprintf(stderr, "%s: can't open file '%s'\n",
  				argv[0], filename);
+ #if defined(__VMS)
+ 			/* STS$M_INHIB_MSG + SS$_ABORT */
+ 			exit(0x1000002c);
+ #else
  			exit(2);
+ #endif
  		}
  	}
***************
*** 339,350 ****
--- 360,407 ----
  		/* Leave stderr alone - it should be unbuffered anyway. */
    	}
+ #ifdef __VMS
+ 	else {
+ 		setvbuf (stdout, (char *)NULL, _IOLBF, BUFSIZ);
+ 	}
+ #endif /* __VMS */
  
  	Py_SetProgramName(argv[0]);
+ #ifdef __VMS
+ 	PyVMS_init(&argc, &argv);
+ #endif
  	Py_Initialize();
  
+ #ifdef __VMS
+ 	/* create an empty string object */
+ 	pyvms_gr_empty_string = Py_BuildValue("s#", Py_None, (unsigned int)0);
+ #endif
+ 
  	if (Py_VerboseFlag ||
  	    (command == NULL && filename == NULL && stdin_is_interactive))
+ #ifndef __VMS
  		fprintf(stderr, "Python %s on %s\n%s\n",
  			Py_GetVersion(), Py_GetPlatform(), COPYRIGHT);
+ #else
+ 		fprintf(stderr, "Python %s on %s %s (%s_float)\n%s\n",
+ 			Py_GetVersion(), Py_GetPlatform(),
+ #  ifdef __ALPHA
+ 			"Alpha",
+ #  else
+ 			"VAX",
+ #  endif
+ #  if __IEEE_FLOAT
+ 			"T",
+ #  else
+ #    if __D_FLOAT
+ 			"D",
+ #    else
+ #      if __G_FLOAT
+ 			"G",
+ #      endif /* __G_FLOAT */
+ #    endif /* __D_FLOAT */
+ #  endif /* __IEEE_FLOAT */
+ 			COPYRIGHT); /* << @@ defined above in this file */
+ /*			Py_GetCopyright()); */
+ #endif /* __VMS */
  
  	if (command != NULL) {

Index: posixmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/posixmodule.c,v
retrieving revision 2.273
retrieving revision 2.274
diff -C2 -d -r2.273 -r2.274
*** posixmodule.c	21 Nov 2002 23:52:35 -0000	2.273
--- posixmodule.c	6 Dec 2002 12:48:50 -0000	2.274
***************
*** 17,20 ****
--- 17,47 ----
  #include "structseq.h"
  
+ #if defined(__VMS)
+ #    include <ctype.h>			/* tolower() */
+ #    include <descrip.h>		/* string descriptors */
+ #    include <dvidef.h>			/* DVI$_name */
+ #    include <file.h>			/* -> O_RDWR */
+ #    include <jpidef.h>			/* JPI$_name */
+ #    include <lib$routines.h>		/* LIB$name */
+ #    include <ots$routines.h>		/* OTS$name */
+ #    include <ssdef.h>			/* SS$_name */
+ #    include <unixio.h>
+ #    include <unixlib.h>
+ #    include <stat.h>
+ /* ----- */
+ /* DECC on Alpha does redefine these already */
+ #    ifndef shell$from_vms
+ #        define shell$from_vms(_p1_,_p2_,_p3_) decc$from_vms(_p1_,_p2_,_p3_)
+ #    endif
+ #    ifndef shell$translate_vms
+ #        define shell$translate_vms(_p1_) decc$translate_vms(_p1_)
+ #    endif
+ #    ifndef shell$to_vms
+ #        define shell$to_vms(_p1_,_p2_,_p3_,_p4_,_p5_) \
+ 		decc$to_vms(_p1_,_p2_,_p3_,_p4_,_p5_)
+ #    endif
+ #    include <wait.h>			/* define wait() */
+ #endif /* defined(__VMS) */
+ 
  PyDoc_STRVAR(posix__doc__,
  "This module provides access to operating system functionality that is\n\
***************
*** 95,100 ****
  #define HAVE_CWAIT	1
  #else
! #if defined(PYOS_OS2) && defined(PYCC_GCC)
! /* Everything needed is defined in PC/os2emx/pyconfig.h */
  #else			/* all other compilers */
  /* Unix functions that the configure script doesn't check for */
--- 122,127 ----
  #define HAVE_CWAIT	1
  #else
! #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)
! /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
  #else			/* all other compilers */
  /* Unix functions that the configure script doesn't check for */
***************
*** 305,308 ****
--- 332,527 ----
  #endif /* !_MSC_VER */
  
+ #if defined(__VMS)
+ static char psxmod_gt_psxpath[1026];
+ 
+ static int 
+ psxmod_from_vms_action (char *spec)
+ {
+ 	(void)strcpy(psxmod_gt_psxpath, spec);
+ 	return 1;
+ }
+ 
+ /* Return a dictionary corresponding to the VMS 'environment table' */
+ static char* at_home = "HOME";
+ static char* at_path = "PATH";
+ 
+ static char psxmod_t_command [] = "SYS$COMMAND";
+ /* add some values to provide a similar environment like POSIX */
+ void
+ psmmod_add_posix_env(PyObject *d)
+ {
+ 	/* -------------------- */
+ 	struct dsc$descriptor_s r_device_name;
+ 	long l_devbufsiz;
+ 	long l_tt_page;
+ 	long l_item_code;
+ 	long l_status;
+ 	PyObject *o;
+ 	struct dsc$descriptor_s r_resultant_string;
+ 	char t_resultant_string[13]; /* enough space for username (12)+ '\0' */
+ 	char *at_resultant_string;
+ 	short int w_resultant_length;
+ 
+ 	/* set up string descriptor */
+ 	r_device_name.dsc$w_length  = strlen(psxmod_t_command);
+ 	r_device_name.dsc$b_dtype = DSC$K_DTYPE_T;
+ 	r_device_name.dsc$b_class = DSC$K_CLASS_S;
+ 	r_device_name.dsc$a_pointer = &psxmod_t_command[0];
+ 
+ 	/* -------------------- */
+ 	/* COLUMNS = $getdvi("SYS$COMMAND","DEVBUFSIZ") */
+ 	l_item_code = DVI$_DEVBUFSIZ;	
+ 	l_status = lib$getdvi(&l_item_code,
+ 			      0,		/* [channel]	 */
+ 			      &r_device_name,
+ 			      &l_devbufsiz,	/* integer-value */
+ 			      0,		/* resultant_string */
+ 			      0);		/* resultant_length */
+ 	if (l_status == SS$_NORMAL) {
+ 		/* create a string object here to comply with POSIX */
+ 
+ 		/* set up string descriptor */
+ 		r_resultant_string.dsc$w_length  =
+ 		    (sizeof(t_resultant_string) - 1); /* ommit '\0' at end */
+ 		r_resultant_string.dsc$b_dtype   = DSC$K_DTYPE_T;
+ 		r_resultant_string.dsc$b_class   = DSC$K_CLASS_S;
+ 		r_resultant_string.dsc$a_pointer = &t_resultant_string[0];
+ 
+ 		/* Convert Signed Integer to Decimal Text */
+ 		l_status = ots$cvt_l_ti(&l_devbufsiz, &r_resultant_string, 1,
+ 					4, 0);
+ 		if (l_status == SS$_NORMAL) {
+ 			/* terminate string for 'C'-style */
+ 			t_resultant_string[sizeof(t_resultant_string)-1] = '\0';
+ 			/* string appears as: '      value' -- skip ' ' */
+ 			at_resultant_string = &t_resultant_string[0];
+ 			while ((*at_resultant_string == ' ' ) && 
+ 		       	       (*at_resultant_string != '\0')) {
+ 				at_resultant_string++;	/* skip prefix spaces */
+ 			}
+ 
+ 			o = Py_BuildValue("s", at_resultant_string);
+ 			if (o != NULL) {
+ 				(void) PyDict_SetItemString(d, "COLUMNS", o);
+ 				Py_DECREF(o);
+ 			}
+ 		} /* (l_status = ots$cvt_l_ti() == SS$_NORMAL) */
+ 	} /* (l_status = lib$getdvi(DVI$_DEVBUFSIZ) == SS$_NORMAL) */
+ 	/* LINES = $getdvi("SYS$COMMAND","TT_PAGE") */
+ 	l_item_code = DVI$_TT_PAGE;
+ 	l_status = lib$getdvi(&l_item_code,
+ 			      0,		/* [channel]	 */
+ 			      &r_device_name,
+ 		              &l_tt_page,	/* integer-value */
+ 			      0,		/* resultant_string */
+ 			      0);		/* resultant_length */
+ 	if (l_status == SS$_NORMAL) {
+ 		/* create a string object here to comply with POSIX */
+ 
+ 		/* set up string descriptor */
+ 		r_resultant_string.dsc$w_length  =
+ 		    (sizeof(t_resultant_string) - 1); /* ommit '\0' at end */
+ 		r_resultant_string.dsc$b_dtype   = DSC$K_DTYPE_T;
+ 		r_resultant_string.dsc$b_class   = DSC$K_CLASS_S;
+ 		r_resultant_string.dsc$a_pointer = &t_resultant_string[0];
+ 
+ 		/* Convert Signed Integer to Decimal Text */
+ 		l_status = ots$cvt_l_ti(&l_tt_page, &r_resultant_string,
+ 					1, 4, 0);
+ 		if (l_status == SS$_NORMAL) {
+ 			/* terminate string for 'C'-style */
+ 		    	t_resultant_string[sizeof(t_resultant_string)-1] = '\0';
+ 		    	/* string appears as: '      value' -- skip ' ' */
+ 		    	at_resultant_string = &t_resultant_string[0];
+ 		    	while ((*at_resultant_string == ' ' ) && 
+ 			       (*at_resultant_string != '\0')) {
+ 				at_resultant_string++; /* skip prefix spaces */
+ 			}
+ 
+ 		    	o = Py_BuildValue("s", at_resultant_string);
+ 		    	if (o != NULL) {
+ 				(void)PyDict_SetItemString(d, "LINES", o);
+ 				Py_DECREF(o);
+ 			}
+ 		} /* (l_status = ots$cvt_l_ti() == SS$_NORMAL) */
+ 	} /* (l_status = lib$getdvi(DVI$_TT_PAGE) == SS$_NORMAL) */
+ 	/* else -- ignore error */
+ 
+ 	/* LOGNAME = $getjpi(0,"USERNAME") */
+ 	l_item_code = JPI$_USERNAME;
+ 
+ 	/* set up string descriptor */
+ 	r_resultant_string.dsc$w_length  =
+ 		    (sizeof(t_resultant_string) - 1); /* ommit '\0' at end */
+ 	r_resultant_string.dsc$b_dtype   = DSC$K_DTYPE_T;
+ 	r_resultant_string.dsc$b_class   = DSC$K_CLASS_S;
+ 	r_resultant_string.dsc$a_pointer = &t_resultant_string[0];
+ 
+ 	l_status = lib$getjpi(&l_item_code, 0, 0, 0,
+ 			      &r_resultant_string, &w_resultant_length);
+ 	if (l_status == SS$_NORMAL){
+ 		t_resultant_string[w_resultant_length] = '\0';
+ 
+ 		/* remove any trailing spaces by replacing 1st one with '\0' */
+ 		at_resultant_string = &t_resultant_string[0];
+ 		while ((*at_resultant_string != ' ' ) &&
+ 		       (*at_resultant_string != '\0')) {
+ 			/* lowercase for compatibility with POSIX */
+ 			*at_resultant_string = tolower(*at_resultant_string);
+ 			at_resultant_string++;	/* skip non-blank */
+ 		}
+ 		*at_resultant_string = '\0';	/* terminate */
+ 
+ 		o = Py_BuildValue("s", &t_resultant_string[0]);
+ 		if (o != NULL) {
+ 			(void) PyDict_SetItemString(d, "LOGNAME", o);
+ 			(void) PyDict_SetItemString(d, "USERNAME", o);
+ 			Py_DECREF(o);
+ 		}
+ 	} /* (l_status == SS$_NORMAL) */
+ 
+ 	/* OS = "OpenVMS" */
+ 	o = PyString_FromString ("OpenVMS");
+ 	if (o != NULL) {
+ 		(void)PyDict_SetItemString(d, "OS", o);
+ 		Py_DECREF(o);
+ 	}
+ }
+ 
+ /* @@ posix env:
+ COLUMNS=80	$ write sys$output f$getdvi("SYS$COMMAND","DEVBUFSIZ")
+ LINES=47	$ write sys$output f$getdvi("SYS$COMMAND","TT_PAGE")
+ LOGNAME=zessin	$ write sys$output f$edit(f$getjpi(0,"username"), -
+ 			"collapse,lowercase")
+ OS=OpenVMS
+ PS1=HERE $
+ 
+ TZ=CET-1:00CET DST,M3.5.0/2:00,M10.5.0/3:00
+ 		$ write sys$output f$trnlnm("POSIX$DEFAULT_TZ")
+ 			"CET-1:00CET DST-2:00,M3.5.0/2:00,M10.5.0/3:00"
+ 		$ write sys$output f$trnlnm("UCX$TZ")
+ 			"MET-1MET_DST-2,M3.5.0/2,M10.5.0/3"
+ PAGER=more
+ TERM=vt300_series
+ SHELL=/bin/sh
+ HOME=/dka100/user/zessin
+ _=/bin/env
+ 
+ >>> for v in os.environ.items():
+ ...   print v
+ ...
+ ('HOME', '/user_here/zessin')
+ ('COLUMNS', '80')
+ ('LINES', '24')
+ ('PATH', '/python_disk/python/python-1_5_2/vms')
+ ('OS', 'OpenVMS')
+ ('USER', 'ZESSIN')
+ ('LOGNAME', 'zessin')
+ ('TERM', 'vt300-80')
+ ('USERNAME', 'zessin')
+ >>>
+ */
+ #endif /* __VMS */
+ 
  static PyObject *
  convertenviron(void)
***************
*** 331,335 ****
--- 550,566 ----
  			continue;
  		}
+ #if defined(__VMS)
+ 		if ((strncmp(at_home, *e, sizeof(at_home)) == 0) ||
+ 		    (strncmp(at_path, *e, sizeof(at_path)) == 0)) {
+ 			(void)shell$from_vms(p+1, psxmod_from_vms_action, 0);
+ 			/* 0 = no wildcard expansion */
+ 			v = PyString_FromString(psxmod_gt_psxpath);
+ 		}
+ 		else {
+ 			v = PyString_FromString(p+1);
+ 		}
+ #else
  		v = PyString_FromString(p+1);
+ #endif
  		if (v == NULL) {
  			PyErr_Clear();
***************
*** 344,347 ****
--- 575,581 ----
  		Py_DECREF(v);
  	}
+ #if defined(__VMS)
+         psmmod_add_posix_env(d);
+ #endif /* defined(__VMS) */
  #if defined(PYOS_OS2)
      {
***************
*** 896,900 ****
--- 1130,1138 ----
  posix_do_stat(PyObject *self, PyObject *args, 
  	      char *format,
+ #ifdef __VMS
+ 	      int (*statfunc)(const char *, STRUCT_STAT *, ...),
+ #else
  	      int (*statfunc)(const char *, STRUCT_STAT *),
+ #endif
  	      char *wformat,
  	      int (*wstatfunc)(const Py_UNICODE *, STRUCT_STAT *))
***************
*** 1049,1053 ****
--- 1287,1301 ----
  		return NULL;
  
+ #if defined(__VMS)
+ 	/* DECC V5.0 - only about FD= 0 @@ try getname()+$getdvi(dvi$_devnam) */
+ 	if (id == 0) {
+ 		ret = ttyname();
+ 	}
+ 	else {
+ 		ret = NULL;
+ 	}
+ #else
  	ret = ttyname(id);
+ #endif
  	if (ret == NULL)
  		return(posix_error());
***************
*** 1093,1098 ****
--- 1341,1351 ----
  	return posix_1str(args, "et:chdir", _chdir2, NULL, NULL);
  #else
+ #ifdef __VMS
+ 	return posix_1str(args, "et:chdir", (int (*)(const char *))chdir, 
+ 			  NULL, NULL);
+ #else
  	return posix_1str(args, "et:chdir", chdir, NULL, NULL);
  #endif
+ #endif
  }
  
***************
*** 1248,1253 ****
--- 1501,1511 ----
  	res = _getcwd2(buf, sizeof buf);
  #else
+ #if defined(__VMS)
+ 	/* 0 = force Unix-style path if in the VMS DCL environment! */
+ 	res = getcwd(buf, sizeof buf, 0);
+ #else
  	res = getcwd(buf, sizeof buf);
  #endif
+ #endif
  	Py_END_ALLOW_THREADS
  	if (res == NULL)
***************
*** 5116,5120 ****
--- 5374,5382 ----
  		return NULL;
  	Py_BEGIN_ALLOW_THREADS
+ #if defined(__VMS)
+ 	res = pipe(fds,0,2100); /* bigger mailbox quota than 512 */
+ #else
  	res = pipe(fds);
+ #endif
  	Py_END_ALLOW_THREADS
  	if (res != 0)

Index: pwdmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/pwdmodule.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** pwdmodule.c	17 Sep 2002 09:34:06 -0000	1.36
--- pwdmodule.c	6 Dec 2002 12:48:51 -0000	1.37
***************
*** 68,75 ****
--- 68,83 ----
  
  	SETS(setIndex++, p->pw_name);
+ #ifdef __VMS
+ 	SETS(setIndex++, "");
+ #else
  	SETS(setIndex++, p->pw_passwd);
+ #endif
  	SETI(setIndex++, p->pw_uid);
  	SETI(setIndex++, p->pw_gid);
+ #ifdef __VMS
+ 	SETS(setIndex++, "");
+ #else
  	SETS(setIndex++, p->pw_gecos);
+ #endif
  	SETS(setIndex++, p->pw_dir);
  	SETS(setIndex++, p->pw_shell);

Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.246
retrieving revision 1.247
diff -C2 -d -r1.246 -r1.247
*** socketmodule.c	2 Nov 2002 19:55:21 -0000	1.246
--- socketmodule.c	6 Dec 2002 12:48:51 -0000	1.247
***************
*** 149,152 ****
--- 149,161 ----
  #endif
  
+ #if defined(__VMS) && ! defined(_SOCKADDR_LEN)
+ #   ifdef getaddrinfo
+ #      undef getaddrinfo
+ #   endif
+ #  include "TCPIP_IOCTL_ROUTINE"
+ #else
+ #  include <ioctl.h>
+ #endif
+ 
  #if defined(PYOS_OS2)
  # define  INCL_DOS
***************
*** 271,274 ****
--- 280,288 ----
  #endif
  
+ #ifdef __VMS
+ /* TCP/IP Services for VMS uses a maximum send/revc buffer length of 65535 */
+ #define SEGMENT_SIZE 65535
+ #endif
+ 
  /* XXX There's a problem here: *static* functions are not supposed to have
     a Py prefix (or use CapitalizedWords).  Later... */
***************
*** 486,490 ****
  	block = !block;
  	ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block));
! #else /* !PYOS_OS2 */
  	delay_flag = fcntl(s->sock_fd, F_GETFL, 0);
  	if (block)
--- 500,507 ----
  	block = !block;
  	ioctl(s->sock_fd, FIONBIO, (caddr_t)&block, sizeof(block));
! #elif defined(__VMS)
! 	block = !block;
! 	ioctl(s->sock_fd, FIONBIO, (char *)&block);
! #else  /* !PYOS_OS2 && !_VMS */
  	delay_flag = fcntl(s->sock_fd, F_GETFL, 0);
  	if (block)
***************
*** 1224,1228 ****
--- 1241,1249 ----
  		return PyInt_FromLong(flag);
  	}
+ #ifdef __VMS
+ 	if (buflen > 1024) {
+ #else
  	if (buflen <= 0 || buflen > 1024) {
+ #endif
  		PyErr_SetString(socket_error,
  				"getsockopt buflen out of range");
***************
*** 1561,1567 ****
--- 1582,1602 ----
  	FILE *fp;
  	PyObject *f;
+ #ifdef __VMS
+ 	char *mode_r = "r";
+ 	char *mode_w = "w";
+ #endif
  
  	if (!PyArg_ParseTuple(args, "|si:makefile", &mode, &bufsize))
  		return NULL;
+ #ifdef __VMS
+ 	if (strcmp(mode,"rb") == 0) {
+ 	    mode = mode_r;
+ 	}
+ 	else {
+ 		if (strcmp(mode,"wb") == 0) {
+ 			mode = mode_w;
+ 		}
+ 	}
+ #endif
  #ifdef MS_WIN32
  	if (((fd = _open_osfhandle(s->sock_fd, _O_BINARY)) < 0) ||
***************
*** 1602,1605 ****
--- 1637,1644 ----
  	int len, n, flags = 0;
  	PyObject *buf;
+ #ifdef __VMS
+ 	int read_length;
+ 	char *read_buf;
+ #endif
  
  	if (!PyArg_ParseTuple(args, "i|i:recv", &len, &flags))
***************
*** 1616,1619 ****
--- 1655,1659 ----
  		return NULL;
  
+ #ifndef __VMS
  	Py_BEGIN_ALLOW_THREADS
  	internal_select(s, 0);
***************
*** 1627,1630 ****
--- 1667,1706 ----
  	if (n != len)
  		_PyString_Resize(&buf, n);
+ #else
+ 	read_buf = PyString_AsString(buf);
+ 	read_length = len;
+ 	while (read_length != 0) {
+ 		unsigned int segment;
+ 
+ 		segment = read_length /SEGMENT_SIZE;
+ 		if (segment != 0) {
+ 			segment = SEGMENT_SIZE;
+ 		}
+ 		else {
+ 			segment = read_length;
+ 		}
+ 
+ 		Py_BEGIN_ALLOW_THREADS
+  	  	internal_select(s, 0);
+ 		n = recv(s->sock_fd, read_buf, segment, flags);
+ 		Py_END_ALLOW_THREADS
+ 
+ 		if (n < 0) {
+ 			Py_DECREF(buf);
+ 			return s->errorhandler();
+ 		}
+ 		if (n != read_length) {
+ 			read_buf += n;
+ 			break;
+ 		}
+ 
+ 		read_length -= segment;
+ 		read_buf += segment;
+ 	}
+ 	if (_PyString_Resize(&buf, (read_buf - PyString_AsString(buf))) < 0)
+ 	{
+ 	    return NULL;
+ 	}
+ #endif /* !__VMS */
  	return buf;
  }
***************
*** 1708,1715 ****
--- 1784,1795 ----
  	char *buf;
  	int len, n, flags = 0;
+ #ifdef __VMS
+ 	int send_length;
+ #endif
  
  	if (!PyArg_ParseTuple(args, "s#|i:send", &buf, &len, &flags))
  		return NULL;
  
+ #ifndef __VMS
  	Py_BEGIN_ALLOW_THREADS
  	internal_select(s, 1);
***************
*** 1719,1722 ****
--- 1799,1827 ----
  	if (n < 0)
  		return s->errorhandler();
+ #else
+ 	/* Divide packet into smaller segments for	*/
+ 	/*  TCP/IP Services for OpenVMS			*/
+ 	send_length = len;
+ 	while (send_length != 0) {
+ 		unsigned int segment;
+ 
+ 		segment = send_length / SEGMENT_SIZE;
+ 		if (segment != 0) {
+ 			segment = SEGMENT_SIZE;
+ 		}
+ 		else {
+ 			segment = send_length;
+ 		}
+ 		Py_BEGIN_ALLOW_THREADS
+ 		internal_select(s, 1);
+ 		n = send(s->sock_fd, buf, segment, flags);
+ 		Py_END_ALLOW_THREADS
+ 		if (n < 0) {
+ 			return s->errorhandler();
+ 		}
+ 		send_length -= segment;
+ 		buf += segment;
+ 	} /* end while */
+ #endif /* !__VMS */
  	return PyInt_FromLong((long)n);
  }