OLD | NEW |
1 /* Time module */ | 1 /* Time module */ |
2 | 2 |
3 #include "Python.h" | 3 #include "Python.h" |
4 #include "_time.h" | 4 #include "_time.h" |
5 | 5 |
6 #include <ctype.h> | 6 #include <ctype.h> |
7 | 7 |
8 #ifdef HAVE_SYS_TYPES_H | 8 #ifdef HAVE_SYS_TYPES_H |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #endif /* HAVE_SYS_TYPES_H */ | 10 #endif /* HAVE_SYS_TYPES_H */ |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "pythread.h" | 22 #include "pythread.h" |
23 | 23 |
24 #if defined(__BORLANDC__) | 24 #if defined(__BORLANDC__) |
25 /* These overrides not needed for Win32 */ | 25 /* These overrides not needed for Win32 */ |
26 #define timezone _timezone | 26 #define timezone _timezone |
27 #define tzname _tzname | 27 #define tzname _tzname |
28 #define daylight _daylight | 28 #define daylight _daylight |
29 #endif /* __BORLANDC__ */ | 29 #endif /* __BORLANDC__ */ |
30 #endif /* MS_WINDOWS */ | 30 #endif /* MS_WINDOWS */ |
31 #endif /* !__WATCOMC__ || __QNX__ */ | 31 #endif /* !__WATCOMC__ || __QNX__ */ |
32 | |
33 #if defined(HAVE_MBCS) | |
34 # define TZNAME_ENCODING "mbcs" | |
35 #else | |
36 # define TZNAME_ENCODING "utf-8" | |
37 #endif | |
38 | 32 |
39 #if defined(PYOS_OS2) | 33 #if defined(PYOS_OS2) |
40 #define INCL_DOS | 34 #define INCL_DOS |
41 #define INCL_ERRORS | 35 #define INCL_ERRORS |
42 #include <os2.h> | 36 #include <os2.h> |
43 #endif | 37 #endif |
44 | 38 |
45 #if defined(PYCC_VACPP) | 39 #if defined(PYCC_VACPP) |
46 #include <sys/time.h> | 40 #include <sys/time.h> |
47 #endif | 41 #endif |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 else if (buf.tm_isdst > 1) | 479 else if (buf.tm_isdst > 1) |
486 buf.tm_isdst = 1; | 480 buf.tm_isdst = 1; |
487 | 481 |
488 #ifdef HAVE_WCSFTIME | 482 #ifdef HAVE_WCSFTIME |
489 format = PyUnicode_AsWideCharString(format_arg, NULL); | 483 format = PyUnicode_AsWideCharString(format_arg, NULL); |
490 if (format == NULL) | 484 if (format == NULL) |
491 return NULL; | 485 return NULL; |
492 fmt = format; | 486 fmt = format; |
493 #else | 487 #else |
494 /* Convert the unicode string to an ascii one */ | 488 /* Convert the unicode string to an ascii one */ |
495 format = PyUnicode_AsEncodedString(format_arg, TZNAME_ENCODING, NULL); | 489 format = PyUnicode_EncodeFSDefault(format_arg); |
496 if (format == NULL) | 490 if (format == NULL) |
497 return NULL; | 491 return NULL; |
498 fmt = PyBytes_AS_STRING(format); | 492 fmt = PyBytes_AS_STRING(format); |
499 #endif | 493 #endif |
500 | 494 |
501 #if defined(MS_WINDOWS) | 495 #if defined(MS_WINDOWS) |
502 /* check that the format string contains only valid directives */ | 496 /* check that the format string contains only valid directives */ |
503 for(outbuf = strchr(fmt, '%'); | 497 for(outbuf = strchr(fmt, '%'); |
504 outbuf != NULL; | 498 outbuf != NULL; |
505 outbuf = strchr(outbuf+2, '%')) | 499 outbuf = strchr(outbuf+2, '%')) |
(...skipping 23 matching lines...) Expand all Loading... |
529 buflen = format_time(outbuf, i, fmt, &buf); | 523 buflen = format_time(outbuf, i, fmt, &buf); |
530 if (buflen > 0 || i >= 256 * fmtlen) { | 524 if (buflen > 0 || i >= 256 * fmtlen) { |
531 /* If the buffer is 256 times as long as the format, | 525 /* If the buffer is 256 times as long as the format, |
532 it's probably not failing for lack of room! | 526 it's probably not failing for lack of room! |
533 More likely, the format yields an empty result, | 527 More likely, the format yields an empty result, |
534 e.g. an empty format, or %Z when the timezone | 528 e.g. an empty format, or %Z when the timezone |
535 is unknown. */ | 529 is unknown. */ |
536 #ifdef HAVE_WCSFTIME | 530 #ifdef HAVE_WCSFTIME |
537 ret = PyUnicode_FromWideChar(outbuf, buflen); | 531 ret = PyUnicode_FromWideChar(outbuf, buflen); |
538 #else | 532 #else |
539 ret = PyUnicode_Decode(outbuf, buflen, | 533 ret = PyUnicode_DecodeFSDefaultAndSize(outbuf, buflen); |
540 TZNAME_ENCODING, NULL); | |
541 #endif | 534 #endif |
542 PyMem_Free(outbuf); | 535 PyMem_Free(outbuf); |
543 break; | 536 break; |
544 } | 537 } |
545 PyMem_Free(outbuf); | 538 PyMem_Free(outbuf); |
546 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) | 539 #if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__) |
547 /* VisualStudio .NET 2005 does this properly */ | 540 /* VisualStudio .NET 2005 does this properly */ |
548 if (buflen == 0 && errno == EINVAL) { | 541 if (buflen == 0 && errno == EINVAL) { |
549 PyErr_SetString(PyExc_ValueError, "Invalid format string"); | 542 PyErr_SetString(PyExc_ValueError, "Invalid format string"); |
550 break; | 543 break; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 #ifdef HAVE_ALTZONE | 755 #ifdef HAVE_ALTZONE |
763 PyModule_AddIntConstant(m, "altzone", altzone); | 756 PyModule_AddIntConstant(m, "altzone", altzone); |
764 #else | 757 #else |
765 #ifdef PYOS_OS2 | 758 #ifdef PYOS_OS2 |
766 PyModule_AddIntConstant(m, "altzone", _timezone-3600); | 759 PyModule_AddIntConstant(m, "altzone", _timezone-3600); |
767 #else /* !PYOS_OS2 */ | 760 #else /* !PYOS_OS2 */ |
768 PyModule_AddIntConstant(m, "altzone", timezone-3600); | 761 PyModule_AddIntConstant(m, "altzone", timezone-3600); |
769 #endif /* PYOS_OS2 */ | 762 #endif /* PYOS_OS2 */ |
770 #endif | 763 #endif |
771 PyModule_AddIntConstant(m, "daylight", daylight); | 764 PyModule_AddIntConstant(m, "daylight", daylight); |
772 otz0 = PyUnicode_Decode(tzname[0], strlen(tzname[0]), TZNAME_ENCODING, NULL)
; | 765 otz0 = PyUnicode_DecodeFSDefaultAndSize(tzname[0], strlen(tzname[0])); |
773 otz1 = PyUnicode_Decode(tzname[1], strlen(tzname[1]), TZNAME_ENCODING, NULL)
; | 766 otz1 = PyUnicode_DecodeFSDefaultAndSize(tzname[1], strlen(tzname[1])); |
774 PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1)); | 767 PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1)); |
775 #else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/ | 768 #else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/ |
776 #ifdef HAVE_STRUCT_TM_TM_ZONE | 769 #ifdef HAVE_STRUCT_TM_TM_ZONE |
777 { | 770 { |
778 #define YEAR ((time_t)((365 * 24 + 6) * 3600)) | 771 #define YEAR ((time_t)((365 * 24 + 6) * 3600)) |
779 time_t t; | 772 time_t t; |
780 struct tm *p; | 773 struct tm *p; |
781 long janzone, julyzone; | 774 long janzone, julyzone; |
782 char janname[10], julyname[10]; | 775 char janname[10], julyname[10]; |
783 t = (time((time_t *)0) / YEAR) * YEAR; | 776 t = (time((time_t *)0) / YEAR) * YEAR; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 Py_END_ALLOW_THREADS | 1034 Py_END_ALLOW_THREADS |
1042 #else | 1035 #else |
1043 /* XXX Can't interrupt this sleep */ | 1036 /* XXX Can't interrupt this sleep */ |
1044 Py_BEGIN_ALLOW_THREADS | 1037 Py_BEGIN_ALLOW_THREADS |
1045 sleep((int)secs); | 1038 sleep((int)secs); |
1046 Py_END_ALLOW_THREADS | 1039 Py_END_ALLOW_THREADS |
1047 #endif | 1040 #endif |
1048 | 1041 |
1049 return 0; | 1042 return 0; |
1050 } | 1043 } |
OLD | NEW |