Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Doc/library/_thread.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,16 @@ This module defines the following constants and functions:
Its value may be used to uniquely identify this particular thread system-wide
(until the thread terminates, after which the value may be recycled by the OS).

.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD.
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris.

.. versionadded:: 3.8

.. versionchanged:: 3.13
Added support for GNU/kFreeBSD.

.. versionchanged:: next
Added support for Solaris.


.. function:: stack_size([size])

Expand Down
5 changes: 4 additions & 1 deletion Doc/library/threading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ This module defines the following functions:
Its value may be used to uniquely identify this particular thread system-wide
(until the thread terminates, after which the value may be recycled by the OS).

.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD.
.. availability:: Windows, FreeBSD, Linux, macOS, OpenBSD, NetBSD, AIX, DragonFlyBSD, GNU/kFreeBSD, Solaris.

.. versionadded:: 3.8

.. versionchanged:: 3.13
Added support for GNU/kFreeBSD.

.. versionchanged:: next
Added support for Solaris.


.. function:: enumerate()

Expand Down
3 changes: 2 additions & 1 deletion Include/pythread.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ PyAPI_FUNC(unsigned long) PyThread_get_thread_ident(void);
#if (defined(__APPLE__) || defined(__linux__) || defined(_WIN32) \
|| defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
|| defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(__DragonFly__) || defined(_AIX))
|| defined(__DragonFly__) || defined(_AIX) \
|| (defined(__sun__) && SIZEOF_LONG >= 8))
#define PY_HAVE_THREAD_NATIVE_ID
PyAPI_FUNC(unsigned long) PyThread_get_thread_native_id(void);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Lib/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def formatweekday(self, day, width):
"""
Returns a formatted week day name.
"""
if width >= 9:
if width >= max(map(len, day_name)):
names = day_name
else:
names = day_abbr
Expand Down
46 changes: 46 additions & 0 deletions Lib/test/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,52 @@ def test_locale_calendar_formatweekday(self):
except locale.Error:
raise unittest.SkipTest('cannot set the en_US locale')

# These locales have weekday names all shorter than English's longest
# 'Wednesday'. They should not be abbreviated unnecessarily
@support.run_with_locales("LC_ALL",
'Chinese', 'zh_CN.UTF-8',
'French', 'fr_FR.UTF-8',
'Norwegian', 'nb_NO.UTF-8',
'Malay', 'ms_MY.UTF8'
)
def test_locale_calendar_short_weekday_names(self):
names = (datetime.date(2001, 1, i+1).strftime('%A') for i in range(7))
max_length = max(map(len, names))
if max_length >= 9:
self.skipTest('weekday names are too long')

def get_weekday_names(width):
return calendar.TextCalendar().formatweekheader(width).split()

# Weekday names should not be abbreviated if the width is sufficient
self.assertEqual(
get_weekday_names(max_length),
get_weekday_names(max_length + 10)
)

# Any width shorter than necessary should produce abbreviations
self.assertNotEqual(
get_weekday_names(max_length),
get_weekday_names(max_length - 1)
)

# These locales have a weekday name longer than 'Wednesday'
# They should be properly abbreviated rather than truncated
@support.run_with_locales("LC_ALL",
'Portuguese', 'pt_PT.UTF-8',
'German', 'de_DE.UTF-8',
'Russian', 'ru_RU.UTF-8',
)
def test_locale_calendar_long_weekday_names(self):
names = (datetime.date(2001, 1, i+1).strftime('%A') for i in range(7))
max_length = max(map(len, names))
if max_length <= 9:
self.skipTest('weekday names are too short')

def get_weekday_names(width):
return calendar.TextCalendar().formatweekheader(width).split()
self.assertEqual(get_weekday_names(4), get_weekday_names(9))

def test_locale_calendar_formatmonthname(self):
try:
# formatmonthname uses the same month names regardless of the width argument.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Calendar uses the lengths of the locale's weekdays to decide if the width
requires abbreviation.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add :func:`threading.get_native_id` support for Illumos/Solaris. Patch by
Yüce Tekol.
4 changes: 4 additions & 0 deletions Python/thread_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
# include <lwp.h> /* _lwp_self() */
#elif defined(__DragonFly__)
# include <sys/lwp.h> /* lwp_gettid() */
#elif defined(__sun__) && SIZEOF_LONG >= 8
# include <thread.h>
#endif

/* The POSIX spec requires that use of pthread_attr_setstacksize
Expand Down Expand Up @@ -399,6 +401,8 @@ PyThread_get_thread_native_id(void)
#elif defined(__DragonFly__)
lwpid_t native_id;
native_id = lwp_gettid();
#elif defined(__sun__) && SIZEOF_LONG >= 8
unsigned long native_id = (unsigned long)getpid() << 32 | thr_self();
#endif
return (unsigned long) native_id;
}
Expand Down
Loading