Skip to content

Python3 Open PR#5

Open
arpitn30 wants to merge 20 commits intomasterfrom
testpy3
Open

Python3 Open PR#5
arpitn30 wants to merge 20 commits intomasterfrom
testpy3

Conversation

@arpitn30
Copy link
Copy Markdown
Owner

@arpitn30 arpitn30 commented Jul 7, 2017

Kodi code ported to Python3 with system dependencies updated accordingly

Description

The following changes have been made to the code -

  • PyString has been changed to PyUnicode and PyBytes accordingly.
  • PyInt has been changed to PyLong since former is no longer supported.
  • Obsolete Py_TPFLAGS have been removed or updated
  • Compare has been completely replaced in favor of RichCompare
  • Module Initialization has been updated
    • Py_InitModule has been replaced with PyModule_Create
    • PyModuleDef added
    • Added PyImport_AppendInittab to add modules to the import modules list
    • Updated swig/CMakeLists to add Python Binding directly to Core Library
  • Changed charset from char to wchar_t due to new functions using the latter
  • Replaced PyFile_AsFile, now removed with a custom function
  • Updated GIL acquisition and release statements
  • Updated Windows package lists and directory paths to new dependency package structure
  • Updated Python Package and Library versions
  • Updated Posix native files and added patches wherever necessary (Patches might need to be removed when the mirrors are updated to Python3)
  • Removed outdated and added new patches to target Python directory
  • Updated Makefiles, dependencies and added patches for specific platforms

Motivation and Context

It helps the add-on developers to code in Python3

How Has This Been Tested?

Yes, this has been tested on Jenkins and on Windows, Linux, and Android using add-ons ported to Python3

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the Code guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the CONTRIBUTING document
  • I have added tests to cover my change
  • All new and existing tests passed

#include "interfaces/python/AddonPythonInvoker.h"
#include "interfaces/python/PythonInvoker.h"

PyThreadState* savestate;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be a meber of CPythonInvoker, XBPython or something similar

Copy link
Copy Markdown
Owner Author

@arpitn30 arpitn30 Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it was a temporary measure until a replacement to transfer the value of threadstate from XBPython to Pythoninvoker since paxxi said it wouldn't be a good idea to use global variables.
@Rechi

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the functions savestate is used in don't share a common class (neither heirarchial), the option other than gloabl variable would be to define the variable static in CPythonInvoker

@arpitn30 arpitn30 force-pushed the testpy3 branch 2 times, most recently from c52da26 to 3bfd92d Compare July 11, 2017 14:19
return NULL;
struct module_state *st = GETSTATE(module);

st->error = PyErr_NewException((char *)"${module.@name}.Error", NULL, NULL);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be removed, I only suggested it for testing but it doesn't do what I thought

@arpitn30 arpitn30 force-pushed the testpy3 branch 3 times, most recently from 4a2d9fb to 3f9df23 Compare July 11, 2017 15:58
Comment thread xbmc/interfaces/python/swig.cpp Outdated
else // If pobject is of type Bytes
{
buf = PyString_AsString(pObject);
buf = PyUnicode_AsUTF8(pObject);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get crashes with a nullptr exception here

Comment thread xbmc/interfaces/python/swig.cpp Outdated
if (utf8_pyString)
{
buf = PyString_AsString(utf8_pyString);
buf = PyUnicode_AsUTF8(utf8_pyString);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get crashes with a nullptr exception here

Py_DECREF(utf8_pyString);
return;
}
buf = PyUnicode_AsUTF8(pObject);
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rechi Can you check if this works correctly?
According to the documentation, this function should encode the PyObject as UTF-8 and return the pointer to the string so wouldn't need another function to encode.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have tested that already during getting the crash and it worked

@arpitn30 arpitn30 force-pushed the testpy3 branch 9 times, most recently from eca0976 to 0d2d6ef Compare July 22, 2017 09:25
@arpitn30 arpitn30 force-pushed the testpy3 branch 6 times, most recently from ea87963 to 31aba04 Compare July 30, 2017 23:55
Comment thread tools/depends/target/Makefile Outdated
pythonmodule-pycryptodome: python36 pythonmodule-setuptools
pythonmodule-pil: $(ZLIB) libjpeg-turbo libpng freetype2 python36 pythonmodule-setuptools
pythonmodule-setuptools: python36
>>>>>>> Changed Tools/Depends MakeFiles
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase error


.installed-$(PLATFORM): $(LIBDYLIB)
cd $(PLATFORM); $(MAKE) install
cd $(PLATFORM); $(MAKE) regen-grammar
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a build command, not an install command

@arpitn30 arpitn30 force-pushed the testpy3 branch 3 times, most recently from 1b2fb4e to f340592 Compare August 2, 2017 06:46
@arpitn30 arpitn30 force-pushed the testpy3 branch 10 times, most recently from 1137526 to 8e23580 Compare August 25, 2017 12:57
Rechi and others added 20 commits March 5, 2019 22:00
* Updated all the files from old function names to new function names as
  given in pydocs - http://py3c.readthedocs.io/en/latest/reference.html
* changed char to wchar_t
* File pointer (FILE *) updated
* Updated ob_type to be called by multi layered PyObject
* Removed tp_compare since it's depreciated
* Updated definitions for InitModule
* Updated the Python3 Android Script
* Updated the GIL acquisition and release statements
* Updated module initialization from init<module> to PyInit_<module> and added the new modules to built-in library through PyImport_AppendInitTab
* Charset Conversion From char To wchar_t
* Updated Python WSGI Invoker
In Python 3.7 Py_Initialize() now acuires the GIL that leads to
a deadlock with the subsequent PyEval_AcquireLock() call.

This should fix xbmc#14885.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants