[Python-checkins] CVS: python/dist/src/Python import.c,2.132,2.133

Guido van Rossum python-dev@python.org
Mon, 1 May 2000 16:19:11 -0400 (EDT)


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

Modified Files:
	import.c 
Log Message:
Marc-Andre Lemburg:

Changed all references to the MAGIC constant to use a global
pyc_magic instead. This global is initially set to MAGIC, but can be
changed by the _PyImport_Init() function to provide for
special features implemented in the compiler which are settable
using command line switches and affect the way PYC files are
generated.

Currently this change is only done for the -U flag.


Index: import.c
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Python/import.c,v
retrieving revision 2.132
retrieving revision 2.133
diff -C2 -r2.132 -r2.133
*** import.c	2000/05/01 17:36:58	2.132
--- import.c	2000/05/01 20:19:08	2.133
***************
*** 87,90 ****
--- 87,95 ----
  #define MAGIC (50428 | ((long)'\r'<<16) | ((long)'\n'<<24))
  
+ /* Magic word as global; note that _PyImport_Init() can change the
+    value of this global to accomodate for alterations of how the
+    compiler works which are enabled by command line switches. */
+ static long pyc_magic = MAGIC;
+ 
  /* See _PyImport_FixupExtension() below */
  static PyObject *extensions = NULL;
***************
*** 136,139 ****
--- 141,151 ----
  		}
  	}
+ 
+ 	if (Py_UnicodeFlag) {
+ 		/* Fix the pyc_magic so that byte compiled code created
+ 		   using the all-Unicode method doesn't interfere with
+ 		   code created in normal operation mode. */
+ 		pyc_magic = MAGIC + 1;
+ 	}
  }
  
***************
*** 367,371 ****
  PyImport_GetMagicNumber()
  {
! 	return MAGIC;
  }
  
--- 379,383 ----
  PyImport_GetMagicNumber()
  {
! 	return pyc_magic;
  }
  
***************
*** 573,577 ****
  		return NULL;
  	magic = PyMarshal_ReadLongFromFile(fp);
! 	if (magic != MAGIC) {
  		if (Py_VerboseFlag)
  			PySys_WriteStderr("# %s has bad magic\n", cpathname);
--- 585,589 ----
  		return NULL;
  	magic = PyMarshal_ReadLongFromFile(fp);
! 	if (magic != pyc_magic) {
  		if (Py_VerboseFlag)
  			PySys_WriteStderr("# %s has bad magic\n", cpathname);
***************
*** 628,632 ****
  
  	magic = PyMarshal_ReadLongFromFile(fp);
! 	if (magic != MAGIC) {
  		PyErr_Format(PyExc_ImportError,
  			     "Bad magic number in %.200s", cpathname);
--- 640,644 ----
  
  	magic = PyMarshal_ReadLongFromFile(fp);
! 	if (magic != pyc_magic) {
  		PyErr_Format(PyExc_ImportError,
  			     "Bad magic number in %.200s", cpathname);
***************
*** 686,690 ****
  		return;
  	}
! 	PyMarshal_WriteLongToFile(MAGIC, fp);
  	/* First write a 0 for mtime */
  	PyMarshal_WriteLongToFile(0L, fp);
--- 698,702 ----
  		return;
  	}
! 	PyMarshal_WriteLongToFile(pyc_magic, fp);
  	/* First write a 0 for mtime */
  	PyMarshal_WriteLongToFile(0L, fp);
***************
*** 1954,1961 ****
  	if (!PyArg_ParseTuple(args, ":get_magic"))
  		return NULL;
! 	buf[0] = (char) ((MAGIC >>  0) & 0xff);
! 	buf[1] = (char) ((MAGIC >>  8) & 0xff);
! 	buf[2] = (char) ((MAGIC >> 16) & 0xff);
! 	buf[3] = (char) ((MAGIC >> 24) & 0xff);
  
  	return PyString_FromStringAndSize(buf, 4);
--- 1966,1973 ----
  	if (!PyArg_ParseTuple(args, ":get_magic"))
  		return NULL;
! 	buf[0] = (char) ((pyc_magic >>  0) & 0xff);
! 	buf[1] = (char) ((pyc_magic >>  8) & 0xff);
! 	buf[2] = (char) ((pyc_magic >> 16) & 0xff);
! 	buf[3] = (char) ((pyc_magic >> 24) & 0xff);
  
  	return PyString_FromStringAndSize(buf, 4);