Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0fedb37

Browse files
Issue #18393: Remove use of deprecated API on OSX
The "Gestalt" function on OSX is deprecated (starting with OSX 10.8), remove its usage from the stdlib. The patch removes a number of private functions and a private module, but does not change the public API. The removed code was effectively dead, the platform module has used other code to fetch the OSX version for years and could only use on the Gestalt-based code as a fallback. That fallback can only trigger on broken OSX installs (that is, someone has removed parts of the system install)
1 parent 7f93b36 commit 0fedb37

4 files changed

Lines changed: 5 additions & 151 deletions

File tree

Lib/platform.py

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -634,62 +634,6 @@ def win32_ver(release='',version='',csd='',ptype=''):
634634
RegCloseKey(keyCurVer)
635635
return release,version,csd,ptype
636636

637-
def _mac_ver_lookup(selectors,default=None):
638-
639-
from _gestalt import gestalt
640-
l = []
641-
append = l.append
642-
for selector in selectors:
643-
try:
644-
append(gestalt(selector))
645-
except (RuntimeError, OSError):
646-
append(default)
647-
return l
648-
649-
def _bcd2str(bcd):
650-
651-
return hex(bcd)[2:]
652-
653-
def _mac_ver_gestalt():
654-
"""
655-
Thanks to Mark R. Levinson for mailing documentation links and
656-
code examples for this function. Documentation for the
657-
gestalt() API is available online at:
658-
659-
http://www.rgaros.nl/gestalt/
660-
"""
661-
# Check whether the version info module is available
662-
try:
663-
import _gestalt
664-
except ImportError:
665-
return None
666-
# Get the infos
667-
sysv, sysa = _mac_ver_lookup(('sysv','sysa'))
668-
# Decode the infos
669-
if sysv:
670-
major = (sysv & 0xFF00) >> 8
671-
minor = (sysv & 0x00F0) >> 4
672-
patch = (sysv & 0x000F)
673-
674-
if (major, minor) >= (10, 4):
675-
# the 'sysv' gestald cannot return patchlevels
676-
# higher than 9. Apple introduced 3 new
677-
# gestalt codes in 10.4 to deal with this
678-
# issue (needed because patch levels can
679-
# run higher than 9, such as 10.4.11)
680-
major,minor,patch = _mac_ver_lookup(('sys1','sys2','sys3'))
681-
release = '%i.%i.%i' %(major, minor, patch)
682-
else:
683-
release = '%s.%i.%i' % (_bcd2str(major),minor,patch)
684-
685-
if sysa:
686-
machine = {0x1: '68k',
687-
0x2: 'PowerPC',
688-
0xa: 'i386'}.get(sysa,'')
689-
690-
versioninfo=('', '', '')
691-
return release,versioninfo,machine
692-
693637
def _mac_ver_xml():
694638
fn = '/System/Library/CoreServices/SystemVersion.plist'
695639
if not os.path.exists(fn):
@@ -705,7 +649,7 @@ def _mac_ver_xml():
705649
versioninfo=('', '', '')
706650
machine = os.uname().machine
707651
if machine in ('ppc', 'Power Macintosh'):
708-
# for compatibility with the gestalt based code
652+
# Cannonical name
709653
machine = 'PowerPC'
710654

711655
return release,versioninfo,machine
@@ -727,12 +671,6 @@ def mac_ver(release='',versioninfo=('','',''),machine=''):
727671
if info is not None:
728672
return info
729673

730-
# If that doesn't work for some reason fall back to reading the
731-
# information using gestalt calls.
732-
info = _mac_ver_gestalt()
733-
if info is not None:
734-
return info
735-
736674
# If that also doesn't work return the default values
737675
return release,versioninfo,machine
738676

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ Core and Builtins
156156
Library
157157
-------
158158

159+
- Issue #18393: The private module _gestalt and private functions platform._mac_ver_gestalt,
160+
platform._mac_ver_lookup and platform._bcd2str have been removed. This does not
161+
affect the public interface of the platform module.
162+
159163
- Issue #17482: functools.update_wrapper (and functools.wraps) now set the
160164
__wrapped__ attribute correctly even if the underlying function has a
161165
__wrapped__ attribute set.

Modules/_gestalt.c

Lines changed: 0 additions & 84 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,6 @@ class db_found(Exception): pass
15191519
missing.append('ossaudiodev')
15201520

15211521
if host_platform == 'darwin':
1522-
exts.append(
1523-
Extension('_gestalt', ['_gestalt.c'],
1524-
extra_link_args=['-framework', 'Carbon'])
1525-
)
15261522
exts.append(
15271523
Extension('_scproxy', ['_scproxy.c'],
15281524
extra_link_args=[

0 commit comments

Comments
 (0)