mercurial/parsers.c
changeset 20159 96b2dd77c85d
parent 20155 21dafd8546d1
child 20169 507919a34c5b
equal deleted inserted replaced
20156:28fe5abc906f 20159:96b2dd77c85d
  1939 		PyObject_GC_UnTrack(nullentry);
  1939 		PyObject_GC_UnTrack(nullentry);
  1940 
  1940 
  1941 	dirstate_unset = Py_BuildValue("ciii", 'n', 0, -1, -1);
  1941 	dirstate_unset = Py_BuildValue("ciii", 'n', 0, -1, -1);
  1942 }
  1942 }
  1943 
  1943 
  1944 static int check_python_version()
       
  1945 {
       
  1946 	PyObject *sys = PyImport_ImportModule("sys");
       
  1947 	PyObject *hexversion = PyObject_GetAttrString(sys, "hexversion");
       
  1948 	long version = PyInt_AsLong(hexversion);
       
  1949 	/* sys.hexversion is a 32-bit number by default, so the -1 case
       
  1950 	 * should only occur in unusual circumstances (e.g. if sys.hexversion
       
  1951 	 * is manually set to an invalid value). */
       
  1952 	if ((version == -1) || (version >> 16 != PY_VERSION_HEX >> 16)) {
       
  1953 		PyErr_Format(PyExc_ImportError, "Python minor version mismatch: "
       
  1954 			"The Mercurial extension modules were compiled with Python "
       
  1955 			PY_VERSION ", but Mercurial is currently using Python with "
       
  1956 			"sys.hexversion=%ld: Python %s\n at: %s", version,
       
  1957 			Py_GetVersion(), Py_GetProgramFullPath());
       
  1958 		return -1;
       
  1959 	}
       
  1960 	return 0;
       
  1961 }
       
  1962 
       
  1963 #ifdef IS_PY3K
  1944 #ifdef IS_PY3K
  1964 static struct PyModuleDef parsers_module = {
  1945 static struct PyModuleDef parsers_module = {
  1965 	PyModuleDef_HEAD_INIT,
  1946 	PyModuleDef_HEAD_INIT,
  1966 	"parsers",
  1947 	"parsers",
  1967 	parsers_doc,
  1948 	parsers_doc,
  1969 	methods
  1950 	methods
  1970 };
  1951 };
  1971 
  1952 
  1972 PyMODINIT_FUNC PyInit_parsers(void)
  1953 PyMODINIT_FUNC PyInit_parsers(void)
  1973 {
  1954 {
  1974 	if (check_python_version() == -1)
       
  1975 		return;
       
  1976 	PyObject *mod = PyModule_Create(&parsers_module);
  1955 	PyObject *mod = PyModule_Create(&parsers_module);
  1977 	module_init(mod);
  1956 	module_init(mod);
  1978 	return mod;
  1957 	return mod;
  1979 }
  1958 }
  1980 #else
  1959 #else
  1981 PyMODINIT_FUNC initparsers(void)
  1960 PyMODINIT_FUNC initparsers(void)
  1982 {
  1961 {
  1983 	if (check_python_version() == -1)
       
  1984 		return;
       
  1985 	PyObject *mod = Py_InitModule3("parsers", methods, parsers_doc);
  1962 	PyObject *mod = Py_InitModule3("parsers", methods, parsers_doc);
  1986 	module_init(mod);
  1963 	module_init(mod);
  1987 }
  1964 }
  1988 #endif
  1965 #endif