Patchwork D6397: rust-python3: compatibility fix for incoming PyLong

login
register
mail settings
Submitter phabricator
Date May 17, 2019, 11:42 a.m.
Message ID <differential-rev-PHID-DREV-l2zspehyvlfjm3nc46wx-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/40112/
State Superseded
Headers show

Comments

phabricator - May 17, 2019, 11:42 a.m.
gracinet created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  On Python3, PyInt is PyLong and it doesn't have the
  `value()` method.
  Re upcasting to PythonObj as done here works, but we
  might prefer taking a PythonObj from the onset
  (would require more testing)

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6397

AFFECTED FILES
  rust/hg-cpython/src/dirstate.rs

CHANGE DETAILS




To: gracinet, #hg-reviewers
Cc: durin42, kevincox, mercurial-devel
Yuya Nishihara - May 18, 2019, 3:24 a.m.
> @@ -153,7 +153,7 @@
>          &dirstate_vec?,
>          &copies?,
>          DirstateParents { p1, p2 },
> -        now.value(py) as i32,
> +        now.into_object().extract::<i32>(py)?,

Minor thing, but I think `as_object()` is preferred since it isn't needed
to consume the now value to extract.
phabricator - May 18, 2019, 3:25 a.m.
yuja added a comment.


  > @@ -153,7 +153,7 @@
  > 
  >   &dirstate_vec?,
  >   &copies?,
  >   DirstateParents { p1, p2 },
  > 
  > - now.value(py) as i32, +        now.into_object().extract::<i32>(py)?,
  
  Minor thing, but I think `as_object()` is preferred since it isn't needed
  to consume the now value to extract.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6397

To: gracinet, #hg-reviewers
Cc: yuja, durin42, kevincox, mercurial-devel
phabricator - May 21, 2019, 6:01 p.m.
gracinet added a comment.


  @yuja yes indeed, just resubmitted with `as_object()`, thanks
  
  Actually the first variant I tried was with it but I must have botched it, because it didn't compile.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6397

To: gracinet, #hg-reviewers
Cc: yuja, durin42, kevincox, mercurial-devel
phabricator - May 21, 2019, 6:09 p.m.
gracinet added a comment.


  https://phab.mercurial-scm.org/D6415 is also necessary to actually build with python3

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6397

To: gracinet, #hg-reviewers
Cc: yuja, durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-cpython/src/dirstate.rs b/rust/hg-cpython/src/dirstate.rs
--- a/rust/hg-cpython/src/dirstate.rs
+++ b/rust/hg-cpython/src/dirstate.rs
@@ -12,7 +12,7 @@ 
 
 use cpython::{
     exc, PyBytes, PyDict, PyErr, PyInt, PyModule, PyObject, PyResult,
-    PySequence, PyTuple, Python, ToPyObject,
+    PySequence, PythonObject, PyTuple, Python, ToPyObject,
 };
 use hg::{
     pack_dirstate, parse_dirstate, CopyVecEntry, DirstateEntry,
@@ -153,7 +153,7 @@ 
         &dirstate_vec?,
         &copies?,
         DirstateParents { p1, p2 },
-        now.value(py) as i32,
+        now.into_object().extract::<i32>(py)?,
     ) {
         Ok((packed, new_dirstate_vec)) => {
             for (