code-google-com / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

Python 3 support #157

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Do you plan to add Python 3 support?

I’m trying to compile it OSX (failed) and I got a few compile errors.
These are missing PyBuffer_Check and PyBuffer_New methods.

According to http://docs.python.org/2/c-api/buffer.html PyBuffer is deprecated 
in favour of new C Buffer API: http://docs.python.org/3.3/c-api/buffer.html

So I wonder if it’s possible to change old PyBuffer* calls with new ones to 
make PyV8 work with Python 3?
I’m not a C/C++ programmer so I don’t know which new buffer methods should 
be used.

Thanks!

Original issue reported on code.google.com by serge....@gmail.com on 31 Jan 2013 at 10:37

GoogleCodeExporter commented 9 years ago

Original comment by flier...@gmail.com on 1 Feb 2013 at 1:56

GoogleCodeExporter commented 9 years ago
I have switch to use the new buffer API for Python 3.x, please verify it with 
SVN trunk code after r483

Original comment by flier...@gmail.com on 3 Feb 2013 at 9:09

GoogleCodeExporter commented 9 years ago
Still unable to compile :( Here’s what I did (OSX 10.8), step-by-step:

1. Installed Python 3
2. Installed `distribute` (http://pypi.python.org/pypi/distribute), fork of 
`setuptools` for Python 3: `curl -O 
http://python-distribute.org/distribute_setup.py && python distribute_setup.py`
3. Replaced bundled `ez_setup.py` with newer version that supports Python 3
4. Builded Boost for Python 3
5. Tried to compile latest version of PyV8 with Python 3: `python3 setup.py 
build`

Got these errors:

src/Utils.cpp:44:7: error: use of undeclared identifier 'PyString_CheckExact'
  if (PyString_CheckExact(str.ptr()))
      ^
src/Utils.cpp:46:40: error: use of undeclared identifier 'PyString_AS_STRING'
    return scope.Close(v8::String::New(PyString_AS_STRING(str.ptr()), PyString_GET_SIZE(str.ptr())));  
                                       ^
src/Utils.cpp:110:37: error: value of type '_Py_atomic_address' is not 
contextually convertible to 'bool'
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
                                    ^~~~~~~~~~~~~~~~~~~~~~
src/Utils.cpp:110:34: error: invalid operands to binary expression ('bool' and 
'_Py_atomic_address')
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
         ~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~
src/Utils.cpp:110:97: error: invalid operands to binary expression 
('PyThreadState *' (aka '_ts *') and '_Py_atomic_address')
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~

Original comment by serge....@gmail.com on 3 Feb 2013 at 12:37

GoogleCodeExporter commented 9 years ago
A small update: in (2) I’ve installed `distribute` with `python3 
distribute_setup.py`

Original comment by serge....@gmail.com on 3 Feb 2013 at 12:41

GoogleCodeExporter commented 9 years ago
PyString_* changed to PyBytes_* or something like that if I recall correctly

Original comment by ndudfi...@gmail.com on 3 Feb 2013 at 12:42

GoogleCodeExporter commented 9 years ago
-      msg = PyString_AS_STRING(val);
+      msg = PyByteArray_AS_STRING(val);

Seems I still have the folder from a few months back

It's PyByteArray now

Original comment by ndudfi...@gmail.com on 3 Feb 2013 at 1:44

GoogleCodeExporter commented 9 years ago
@flier

I tried building with Python 3.3 a month or so back, but I didn't make sure it 
was even build with 2.7 at the time. I was getting some errors about needing to 
implement some virtual functions. 

Do you have a known working revision of V8 that will work with PyV8 `HEAD` I 
can try again with ?

Original comment by ndudfi...@gmail.com on 3 Feb 2013 at 2:35

GoogleCodeExporter commented 9 years ago
Please try the SVN trunk code, I will setup a Python 3.x environment later, 
thanks

Original comment by flier...@gmail.com on 4 Feb 2013 at 2:29

GoogleCodeExporter commented 9 years ago
Still no luck, I receive the same compilation error:

src/Utils.cpp:44:7: error: use of undeclared identifier 'PyString_CheckExact'
  if (PyString_CheckExact(str.ptr()))
      ^
src/Utils.cpp:46:40: error: use of undeclared identifier 'PyString_AS_STRING'
    return scope.Close(v8::String::New(PyString_AS_STRING(str.ptr()), PyString_GET_SIZE(str.ptr())));  
                                       ^
src/Utils.cpp:110:37: error: value of type '_Py_atomic_address' is not 
contextually convertible to 'bool'
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
                                    ^~~~~~~~~~~~~~~~~~~~~~
src/Utils.cpp:110:34: error: invalid operands to binary expression ('bool' and 
'_Py_atomic_address')
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
         ~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~
src/Utils.cpp:110:97: error: invalid operands to binary expression 
('PyThreadState *' (aka '_ts *') and '_Py_atomic_address')
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~

Original comment by serge....@gmail.com on 4 Feb 2013 at 6:30

GoogleCodeExporter commented 9 years ago
I'm working on it, please use the SVN trunk code for Python 3.x, thanks

Original comment by flier...@gmail.com on 4 Feb 2013 at 1:22

GoogleCodeExporter commented 9 years ago
 _PyThreadState_Current  is a simple struct wrapping a (void *) in Python 3.

Tweaking a few changes here and there related to that it builds but it still 
fails the tests.

➜  lib.linux-x86_64-3.3  python3.3 PyV8.py 
PyV8.py:2328: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(AST.NodeType.Block, stmt.type)
PyV8.py:2330: DeprecationWarning: Please use assertTrue instead.
  self.assert_(stmt.initializerBlock)
........................EF....F..........................
======================================================================
ERROR: testArray (__main__.TestWrapper)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "PyV8.py", line 1450, in testArray
    self.assert_(ctxt.eval('array3[9] === undefined'))
  File "/usr/lib/python3.3/unittest/case.py", line 1140, in deprecated_func
    DeprecationWarning, 2)
IndexError: list index out of range

======================================================================
FAIL: testAutoConverter (__main__.TestWrapper)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "PyV8.py", line 1055, in testAutoConverter
    self.assert_("var_i" in attrs)
AssertionError: False is not true

======================================================================
FAIL: testDestructor (__main__.TestWrapper)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "PyV8.py", line 1688, in testDestructor
    self.assertFalse(owner.deleted)
AssertionError: True is not false

----------------------------------------------------------------------
Ran 57 tests in 2.155s

FAILED (failures=2, errors=1)

Original comment by ndudfi...@gmail.com on 5 Feb 2013 at 2:24

GoogleCodeExporter commented 9 years ago
I’m still unable to compile it:

src/Utils.cpp:110:37: error: value of type '_Py_atomic_address' is not 
contextually convertible to 'bool'
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
                                    ^~~~~~~~~~~~~~~~~~~~~~
src/Utils.cpp:110:34: error: invalid operands to binary expression ('bool' and 
'_Py_atomic_address')
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
         ~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~
src/Utils.cpp:110:97: error: invalid operands to binary expression 
('PyThreadState *' (aka '_ts *') and '_Py_atomic_address')
  while (CLocker::IsPreemption() && _PyThreadState_Current && ::PyGILState_GetThisThreadState() != ::_PyThreadState_Current)
                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~

Original comment by serge....@gmail.com on 5 Feb 2013 at 9:01

GoogleCodeExporter commented 9 years ago
which version of your Python? I can build pyv8 with Python 3.1 on debian system

Original comment by flier...@gmail.com on 5 Feb 2013 at 9:10

GoogleCodeExporter commented 9 years ago
I’m using Python 3.3

This version is vital for me because I’m using PyV8 as a part of my Emmet 
plugin for upcoming Sublime Text 3 editor 
http://www.sublimetext.com/blog/articles/sublime-text-3-beta which uses Python 
3.3

Emmet is very popular plugin for current ST2 editor, more that 90 000 downloads 
(check out http://wbond.net/sublime_packages/community#sort-installs) so 
there’s lots of people who’s waiting for Py3 support :)

Original comment by serge....@gmail.com on 5 Feb 2013 at 9:17

GoogleCodeExporter commented 9 years ago
got it, I will install a Python 3.3 and try again :)

Original comment by flier...@gmail.com on 5 Feb 2013 at 9:19

GoogleCodeExporter commented 9 years ago
Now, most of test cases could pass Python 3.3, I will fix the remaining issues 
later

Original comment by flier...@gmail.com on 5 Feb 2013 at 12:53

GoogleCodeExporter commented 9 years ago
@Flier

I just svn update/revert, then built again.  

Still getting the same failing tests in comment I made previous.

Is so close :) !

Original comment by ndudfi...@gmail.com on 5 Feb 2013 at 1:04

GoogleCodeExporter commented 9 years ago
Cloud you `rm -rf build` and try again? I have built pyv8 on a debian 6 system.

flier@debian6-x64:~/pyv8$ uname -a
Linux debian6-x64 2.6.32-5-amd64 #1 SMP Sun Sep 23 10:07:46 UTC 2012 x86_64 
GNU/Linux

flier@debian6-x64:~/pyv8$ python3 -V
Python 3.3.0

flier@debian6-x64:~/pyv8$ ll /usr/local/lib/*libboost_python*
-rw-r--r-- 1 root staff 729968 Feb  5 19:01 /usr/local/lib/libboost_python3.a
lrwxrwxrwx 1 root staff     26 Feb  5 19:01 /usr/local/lib/libboost_python3.so 
-> libboost_python3.so.1.52.0
-rwxr-xr-x 1 root staff 429207 Feb  5 19:01 
/usr/local/lib/libboost_python3.so.1.52.0
-rw-r--r-- 1 root staff 729968 Feb  5 19:01 /usr/local/lib/libboost_python.a
lrwxrwxrwx 1 root staff     25 Feb  5 19:01 /usr/local/lib/libboost_python.so 
-> libboost_python.so.1.52.0
-rwxr-xr-x 1 root staff 429207 Feb  5 19:01 
/usr/local/lib/libboost_python.so.1.52.0

flier@debian6-x64:~/pyv8$ pwd
/home/flier/pyv8

flier@debian6-x64:~/pyv8/build/lib.linux-x86_64-3.3$ python3 PyV8.py 
........................EF....F..........................

Original comment by flier...@gmail.com on 5 Feb 2013 at 1:08

GoogleCodeExporter commented 9 years ago
I’ve successfully built it on OSX 10.8, thanks!
I’m going to try it in plugin soon.

Original comment by serge....@gmail.com on 5 Feb 2013 at 1:10

GoogleCodeExporter commented 9 years ago
Thanks, there are still some failed test cases, I will check it tomorrow :)

Please submit a new issue to follow up, if you found anything wrong in Python 
3.x

Original comment by flier...@gmail.com on 5 Feb 2013 at 1:12

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@Flier
@Serge

Thanks for ur time we are all appreciated 
Please note when emmet plugin work i cant use my Sublime 3 without it ;)

Regards

Original comment by hashem.k...@gmail.com on 6 Feb 2013 at 9:25

GoogleCodeExporter commented 9 years ago
 pandora@ubuntu:~/.config/sublime-text-3/Packages/PyV8/pyv8-linux32-p3$ uname -a
Linux ubuntu 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:08:14 UTC 2014 i686 
i686 i686 GNU/Linux
pandora@ubuntu:~/.config/sublime-text-3/Packages/PyV8/pyv8-linux32-p3$ python3 
-V
Python 3.3.5
pandora@ubuntu:~/.config/sublime-text-3/Packages/PyV8/pyv8-linux32-p3$ python3 
PyV8.py 
..............................F...........F..............
======================================================================
FAIL: testDestructor (__main__.TestWrapper)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "PyV8.py", line 1711, in testDestructor
    self.assertTrue(owner.deleted)
AssertionError: False is not true

======================================================================
FAIL: testLivingObjectCache (__main__.TestWrapper)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "PyV8.py", line 1728, in testLivingObjectCache
    self.assertTrue(ctxt.eval("o == o"))
AssertionError: False is not true

----------------------------------------------------------------------
Ran 57 tests in 2.082s

FAILED (failures=2)
pandora@ubuntu:~/.config/sublime-text-3/Packages/PyV8/pyv8-linux32-p3$ 

Original comment by Taurus...@gmail.com on 6 May 2014 at 8:12