Mercurial > cpython-lru_cache-weakref
comparison Python/sysmodule.c @ 47527:52294af4b663 legacy-trunk
This reverts r63675 based on the discussion in this thread:
http://mail.python.org/pipermail/python-dev/2008-June/079988.html
Python 2.6 should stick with PyString_* in its codebase. The PyBytes_* names
in the spirit of 3.0 are available via a #define only. See the email thread.
| author | Gregory P. Smith <greg@mad-scientist.com> |
|---|---|
| date | Mon, 09 Jun 2008 04:58:54 +0000 |
| parents | a65f095b27f3 |
| children | 0738119c1ef8 |
comparison
equal
deleted
inserted
replaced
| 47526:246a802637ad | 47527:52294af4b663 |
|---|---|
| 227 #ifdef Py_USING_UNICODE | 227 #ifdef Py_USING_UNICODE |
| 228 | 228 |
| 229 static PyObject * | 229 static PyObject * |
| 230 sys_getdefaultencoding(PyObject *self) | 230 sys_getdefaultencoding(PyObject *self) |
| 231 { | 231 { |
| 232 return PyBytes_FromString(PyUnicode_GetDefaultEncoding()); | 232 return PyString_FromString(PyUnicode_GetDefaultEncoding()); |
| 233 } | 233 } |
| 234 | 234 |
| 235 PyDoc_STRVAR(getdefaultencoding_doc, | 235 PyDoc_STRVAR(getdefaultencoding_doc, |
| 236 "getdefaultencoding() -> string\n\ | 236 "getdefaultencoding() -> string\n\ |
| 237 \n\ | 237 \n\ |
| 259 | 259 |
| 260 static PyObject * | 260 static PyObject * |
| 261 sys_getfilesystemencoding(PyObject *self) | 261 sys_getfilesystemencoding(PyObject *self) |
| 262 { | 262 { |
| 263 if (Py_FileSystemDefaultEncoding) | 263 if (Py_FileSystemDefaultEncoding) |
| 264 return PyBytes_FromString(Py_FileSystemDefaultEncoding); | 264 return PyString_FromString(Py_FileSystemDefaultEncoding); |
| 265 Py_INCREF(Py_None); | 265 Py_INCREF(Py_None); |
| 266 return Py_None; | 266 return Py_None; |
| 267 } | 267 } |
| 268 | 268 |
| 269 PyDoc_STRVAR(getfilesystemencoding_doc, | 269 PyDoc_STRVAR(getfilesystemencoding_doc, |
| 288 "c_call", "c_exception", "c_return"}; | 288 "c_call", "c_exception", "c_return"}; |
| 289 PyObject *name; | 289 PyObject *name; |
| 290 int i; | 290 int i; |
| 291 for (i = 0; i < 7; ++i) { | 291 for (i = 0; i < 7; ++i) { |
| 292 if (whatstrings[i] == NULL) { | 292 if (whatstrings[i] == NULL) { |
| 293 name = PyBytes_InternFromString(whatnames[i]); | 293 name = PyString_InternFromString(whatnames[i]); |
| 294 if (name == NULL) | 294 if (name == NULL) |
| 295 return -1; | 295 return -1; |
| 296 whatstrings[i] = name; | 296 whatstrings[i] = name; |
| 297 } | 297 } |
| 298 } | 298 } |
| 929 PyObject *list = PyList_New(0); | 929 PyObject *list = PyList_New(0); |
| 930 int i; | 930 int i; |
| 931 if (list == NULL) | 931 if (list == NULL) |
| 932 return NULL; | 932 return NULL; |
| 933 for (i = 0; PyImport_Inittab[i].name != NULL; i++) { | 933 for (i = 0; PyImport_Inittab[i].name != NULL; i++) { |
| 934 PyObject *name = PyBytes_FromString( | 934 PyObject *name = PyString_FromString( |
| 935 PyImport_Inittab[i].name); | 935 PyImport_Inittab[i].name); |
| 936 if (name == NULL) | 936 if (name == NULL) |
| 937 break; | 937 break; |
| 938 PyList_Append(list, name); | 938 PyList_Append(list, name); |
| 939 Py_DECREF(name); | 939 Py_DECREF(name); |
| 969 Py_XDECREF(warnoptions); | 969 Py_XDECREF(warnoptions); |
| 970 warnoptions = PyList_New(0); | 970 warnoptions = PyList_New(0); |
| 971 if (warnoptions == NULL) | 971 if (warnoptions == NULL) |
| 972 return; | 972 return; |
| 973 } | 973 } |
| 974 str = PyBytes_FromString(s); | 974 str = PyString_FromString(s); |
| 975 if (str != NULL) { | 975 if (str != NULL) { |
| 976 PyList_Append(warnoptions, str); | 976 PyList_Append(warnoptions, str); |
| 977 Py_DECREF(str); | 977 Py_DECREF(str); |
| 978 } | 978 } |
| 979 } | 979 } |
| 1325 Py_XDECREF(sysin); | 1325 Py_XDECREF(sysin); |
| 1326 Py_XDECREF(sysout); | 1326 Py_XDECREF(sysout); |
| 1327 Py_XDECREF(syserr); | 1327 Py_XDECREF(syserr); |
| 1328 | 1328 |
| 1329 SET_SYS_FROM_STRING("version", | 1329 SET_SYS_FROM_STRING("version", |
| 1330 PyBytes_FromString(Py_GetVersion())); | 1330 PyString_FromString(Py_GetVersion())); |
| 1331 SET_SYS_FROM_STRING("hexversion", | 1331 SET_SYS_FROM_STRING("hexversion", |
| 1332 PyInt_FromLong(PY_VERSION_HEX)); | 1332 PyInt_FromLong(PY_VERSION_HEX)); |
| 1333 svnversion_init(); | 1333 svnversion_init(); |
| 1334 SET_SYS_FROM_STRING("subversion", | 1334 SET_SYS_FROM_STRING("subversion", |
| 1335 Py_BuildValue("(ssz)", "CPython", branch, | 1335 Py_BuildValue("(ssz)", "CPython", branch, |
| 1356 PY_MICRO_VERSION, s, | 1356 PY_MICRO_VERSION, s, |
| 1357 PY_RELEASE_SERIAL)); | 1357 PY_RELEASE_SERIAL)); |
| 1358 SET_SYS_FROM_STRING("api_version", | 1358 SET_SYS_FROM_STRING("api_version", |
| 1359 PyInt_FromLong(PYTHON_API_VERSION)); | 1359 PyInt_FromLong(PYTHON_API_VERSION)); |
| 1360 SET_SYS_FROM_STRING("copyright", | 1360 SET_SYS_FROM_STRING("copyright", |
| 1361 PyBytes_FromString(Py_GetCopyright())); | 1361 PyString_FromString(Py_GetCopyright())); |
| 1362 SET_SYS_FROM_STRING("platform", | 1362 SET_SYS_FROM_STRING("platform", |
| 1363 PyBytes_FromString(Py_GetPlatform())); | 1363 PyString_FromString(Py_GetPlatform())); |
| 1364 SET_SYS_FROM_STRING("executable", | 1364 SET_SYS_FROM_STRING("executable", |
| 1365 PyBytes_FromString(Py_GetProgramFullPath())); | 1365 PyString_FromString(Py_GetProgramFullPath())); |
| 1366 SET_SYS_FROM_STRING("prefix", | 1366 SET_SYS_FROM_STRING("prefix", |
| 1367 PyBytes_FromString(Py_GetPrefix())); | 1367 PyString_FromString(Py_GetPrefix())); |
| 1368 SET_SYS_FROM_STRING("exec_prefix", | 1368 SET_SYS_FROM_STRING("exec_prefix", |
| 1369 PyBytes_FromString(Py_GetExecPrefix())); | 1369 PyString_FromString(Py_GetExecPrefix())); |
| 1370 SET_SYS_FROM_STRING("maxsize", | 1370 SET_SYS_FROM_STRING("maxsize", |
| 1371 PyInt_FromSsize_t(PY_SSIZE_T_MAX)); | 1371 PyInt_FromSsize_t(PY_SSIZE_T_MAX)); |
| 1372 SET_SYS_FROM_STRING("maxint", | 1372 SET_SYS_FROM_STRING("maxint", |
| 1373 PyInt_FromLong(PyInt_GetMax())); | 1373 PyInt_FromLong(PyInt_GetMax())); |
| 1374 SET_SYS_FROM_STRING("py3kwarning", | 1374 SET_SYS_FROM_STRING("py3kwarning", |
| 1391 if (s[0] == 0) | 1391 if (s[0] == 0) |
| 1392 value = "big"; | 1392 value = "big"; |
| 1393 else | 1393 else |
| 1394 value = "little"; | 1394 value = "little"; |
| 1395 SET_SYS_FROM_STRING("byteorder", | 1395 SET_SYS_FROM_STRING("byteorder", |
| 1396 PyBytes_FromString(value)); | 1396 PyString_FromString(value)); |
| 1397 } | 1397 } |
| 1398 #ifdef MS_COREDLL | 1398 #ifdef MS_COREDLL |
| 1399 SET_SYS_FROM_STRING("dllhandle", | 1399 SET_SYS_FROM_STRING("dllhandle", |
| 1400 PyLong_FromVoidPtr(PyWin_DLLhModule)); | 1400 PyLong_FromVoidPtr(PyWin_DLLhModule)); |
| 1401 SET_SYS_FROM_STRING("winver", | 1401 SET_SYS_FROM_STRING("winver", |
| 1402 PyBytes_FromString(PyWin_DLLVersionString)); | 1402 PyString_FromString(PyWin_DLLVersionString)); |
| 1403 #endif | 1403 #endif |
| 1404 if (warnoptions == NULL) { | 1404 if (warnoptions == NULL) { |
| 1405 warnoptions = PyList_New(0); | 1405 warnoptions = PyList_New(0); |
| 1406 } | 1406 } |
| 1407 else { | 1407 else { |
| 1442 return NULL; | 1442 return NULL; |
| 1443 for (i = 0; ; i++) { | 1443 for (i = 0; ; i++) { |
| 1444 p = strchr(path, delim); | 1444 p = strchr(path, delim); |
| 1445 if (p == NULL) | 1445 if (p == NULL) |
| 1446 p = strchr(path, '\0'); /* End of string */ | 1446 p = strchr(path, '\0'); /* End of string */ |
| 1447 w = PyBytes_FromStringAndSize(path, (Py_ssize_t) (p - path)); | 1447 w = PyString_FromStringAndSize(path, (Py_ssize_t) (p - path)); |
| 1448 if (w == NULL) { | 1448 if (w == NULL) { |
| 1449 Py_DECREF(v); | 1449 Py_DECREF(v); |
| 1450 return NULL; | 1450 return NULL; |
| 1451 } | 1451 } |
| 1452 PyList_SetItem(v, i, w); | 1452 PyList_SetItem(v, i, w); |
| 1487 | 1487 |
| 1488 /* argv[0] is the script pathname if known */ | 1488 /* argv[0] is the script pathname if known */ |
| 1489 if (i == 0) { | 1489 if (i == 0) { |
| 1490 char* fn = decc$translate_vms(argv[0]); | 1490 char* fn = decc$translate_vms(argv[0]); |
| 1491 if ((fn == (char *)0) || fn == (char *)-1) | 1491 if ((fn == (char *)0) || fn == (char *)-1) |
| 1492 v = PyBytes_FromString(argv[0]); | 1492 v = PyString_FromString(argv[0]); |
| 1493 else | 1493 else |
| 1494 v = PyBytes_FromString( | 1494 v = PyString_FromString( |
| 1495 decc$translate_vms(argv[0])); | 1495 decc$translate_vms(argv[0])); |
| 1496 } else | 1496 } else |
| 1497 v = PyBytes_FromString(argv[i]); | 1497 v = PyString_FromString(argv[i]); |
| 1498 #else | 1498 #else |
| 1499 PyObject *v = PyBytes_FromString(argv[i]); | 1499 PyObject *v = PyString_FromString(argv[i]); |
| 1500 #endif | 1500 #endif |
| 1501 if (v == NULL) { | 1501 if (v == NULL) { |
| 1502 Py_DECREF(av); | 1502 Py_DECREF(av); |
| 1503 av = NULL; | 1503 av = NULL; |
| 1504 break; | 1504 break; |
| 1598 if (n > 1) | 1598 if (n > 1) |
| 1599 n--; /* Drop trailing separator */ | 1599 n--; /* Drop trailing separator */ |
| 1600 #endif /* Unix */ | 1600 #endif /* Unix */ |
| 1601 } | 1601 } |
| 1602 #endif /* All others */ | 1602 #endif /* All others */ |
| 1603 a = PyBytes_FromStringAndSize(argv0, n); | 1603 a = PyString_FromStringAndSize(argv0, n); |
| 1604 if (a == NULL) | 1604 if (a == NULL) |
| 1605 Py_FatalError("no mem for sys.path insertion"); | 1605 Py_FatalError("no mem for sys.path insertion"); |
| 1606 if (PyList_Insert(path, 0, a) < 0) | 1606 if (PyList_Insert(path, 0, a) < 0) |
| 1607 Py_FatalError("sys.path.insert(0) failed"); | 1607 Py_FatalError("sys.path.insert(0) failed"); |
| 1608 Py_DECREF(a); | 1608 Py_DECREF(a); |
