This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyUnicode functions are not exported by python 2 in Ubuntu
Type: crash Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: benjamin.peterson, pyscripter, vstinner, zach.ware
Priority: normal Keywords:

Created on 2019-10-07 16:09 by pyscripter, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (9)
msg354105 - (view) Author: PyScripter (pyscripter) Date: 2019-10-07 16:09
As per title PyUnicode functions, such as PyUnicode_FromWideChar, are not exported on Ubuntu and possibly other Linux systems.  This is a show stopper for embedded Python.

To confirm:

>>> import ctypes
>>> hasattr(ctypes.pythonapi, "PyUnicode_FromWideChar")

It should return True, but it returns False.  

I have tested with the default Ubuntu python 2.7.15 and with compiled python 2.7.16.

Note that the problem does not exist in python3 and also python 2.7 and 3.x in Windows.  So it is only python 2.7 in Ubuntu.
msg354106 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-10-07 16:14
Given that 2.7 is reaching end-of-life in a single-digit number of months, I doubt anything will be changed here.  I'll leave it up to Benjamin to make that determination, though.
msg354108 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-07 16:20
> hasattr(ctypes.pythonapi, "PyUnicode_FromWideChar")

Python 2 has a surprising ABI. The function names depending on the Unicode implementation:

PyUnicodeUCS2_FromWideChar on Windows, PyUnicodeUCS4_FromWideChar on other platforms.

Enjoy the ugly https://github.com/python/cpython/blob/2.7/Include/unicodeobject.h

And say hello to the new compact Unicode strings, PEP 393, implemented in Python 3.3, which unified that!
https://www.python.org/dev/peps/pep-0393/
msg354109 - (view) Author: PyScripter (pyscripter) Date: 2019-10-07 16:29
To Victor:

Neither of PyUnicodeUCS2_FromWideChar or PyUnicodeUCS4_FromWideChar is exported.

>>> import ctypes
>>> hasattr(ctypes.pythonapi, "PyUnicode_FromWideChar")
>>> hasattr(ctypes.pythonapi, "PyUnicodeUSC4_FromWideChar")
>>> hasattr(ctypes.pythonapi, "PyUnicodeUSC2_FromWideChar")

all return false on Ubuntu.
msg354111 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-07 16:31
ctypes.pythonapi is kind of magic. I'm not sure if hasattr() is supposed to work on it. But that works for me:

$ python2
Python 2.7.16 (default, Apr 30 2019, 15:54:43) 
>>> import ctypes
>>> ctypes.pythonapi.PyUnicodeUCS4_FromWideChar
<_FuncPtr object at 0x7f1b9c155ef0>
msg354112 - (view) Author: PyScripter (pyscripter) Date: 2019-10-07 16:32
I meant PyUnicodeUCS4_FromWideChar PyUnicodeUCS2_FromWideChar.
msg354113 - (view) Author: PyScripter (pyscripter) Date: 2019-10-07 16:33
Is this on Ubuntu?
msg354114 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-07 16:33
> Is this on Ubuntu?

No, only Fedora. If the issue is specific to Ubuntu, report it to the Ubuntu bug tracker.
msg354115 - (view) Author: PyScripter (pyscripter) Date: 2019-10-07 16:36
>>> sys.version
'2.7.16 (default, Oct  7 2019, 17:16:30) \n[GCC 7.4.0]'
>>> ctypes.pythonapi.PyUnicodeUCS4_FromWideChar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 379, in __getattr__
    func = self.__getitem__(name)
  File "/usr/local/lib/python2.7/ctypes/__init__.py", line 384, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: python2.7: undefined symbol: PyUnicodeUCS4_FromWideChar
>>>
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82579
2019-10-07 16:36:30pyscriptersetmessages: + msg354115
2019-10-07 16:33:43vstinnersetmessages: + msg354114
2019-10-07 16:33:03pyscriptersetmessages: + msg354113
2019-10-07 16:32:13pyscriptersetmessages: + msg354112
2019-10-07 16:31:32vstinnersetmessages: + msg354111
2019-10-07 16:29:07pyscriptersetmessages: + msg354109
2019-10-07 16:20:43vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg354108

resolution: not a bug
stage: resolved
2019-10-07 16:14:17zach.waresetnosy: + zach.ware, benjamin.peterson
messages: + msg354106
2019-10-07 16:09:58pyscriptercreate