This is an archive of the discontinued LLVM Phabricator instance.

Fix Python 3 language issues and add an explicit check for Python version == 2.
ClosedPublic

Authored by jbcoe on Jan 13 2017, 8:37 AM.

Details

Summary

Python bindings cannot support Python 3 without work being done to fix Unicode c-string conversion.

This was attempted in https://reviews.llvm.org/D26082. That patch was reverted due to memory access issues on Linux.

This revision fixes enough language compatibility issues for the clang module to be loaded and raise an error if the Python version is not 2.

Diff Detail

Event Timeline

jbcoe updated this revision to Diff 84313.Jan 13 2017, 8:37 AM
jbcoe retitled this revision from to Fix Python 3 language issues and add an explicit check for Python version == 2..
jbcoe updated this object.
jbcoe added reviewers: rengolin, compnerd.

Adding the two reviewers that were on the original patch for safety.

jbcoe updated this revision to Diff 84324.Jan 13 2017, 9:16 AM
jbcoe edited edge metadata.

Fix typo in comment.

jbcoe updated this object.Jan 16 2017, 9:45 AM

Ping. Would be good to decide this for 4.0 RC1

compnerd edited edge metadata.Jan 16 2017, 1:52 PM

The change beyond the one comment looks good. Its unfortunate that the the string handling in python forces us to prevent the module from being loaded in python3. I mentioned one approach to @jbcoe that I think could work:

We run 2to3 on the source and install both with a suffixed name, switching the imported version based on sys.version[0].

bindings/python/clang/__init__.py
27

ouch ... this makes my head hurt. Is this even supported? *If* it works, I think it may be an accident of the lexer/parser implementation in python. Please rewrite this as:

import sys
if sys.version_info[0] != 2:
  raise Exception("only python 2 is supported.")
jbcoe updated this revision to Diff 84599.Jan 16 2017, 2:42 PM
jbcoe marked an inline comment as done.

Fix whitespace errors induced by comment formatting.

Jonathan,

After this is approved and committed, please create a bug in bugzilla against the 4.0 back-ports (and CC me), so that Hans can collect it into the release.

thanks,
--renato

compnerd accepted this revision.Jan 17 2017, 7:43 AM
This revision is now accepted and ready to land.Jan 17 2017, 7:43 AM
This revision was automatically updated to reflect the committed changes.