]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1967: if_python: 64bit numbers truncated v9.1.1967
authorlsq <lsqypj@gmail.com>
Thu, 11 Dec 2025 18:59:13 +0000 (19:59 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 11 Dec 2025 18:59:13 +0000 (19:59 +0100)
Problem:  if_python: 64bit numbers truncated
Solution: cast python result to long long (lsq)

fixes:  #18899
closes: #18904

Signed-off-by: lsq <lsqypj@gmail.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/if_py_both.h
src/testdir/test_python3.vim
src/version.c

index 7fc055db53dbd7023c771e1e0528617363bddd1c..e0020519b098ffd804b98b4447e58611f3f552aa 100644 (file)
@@ -1039,7 +1039,7 @@ VimToPython(typval_T *our_tv, int depth, PyObject *lookup_dict)
        char buf[NUMBUFLEN];
 
        // For backwards compatibility numbers are stored as strings.
-       sprintf(buf, "%ld", (long)our_tv->vval.v_number);
+       sprintf(buf, "%lld", (long long)our_tv->vval.v_number);
        ret = PyString_FromString((char *)buf);
     }
     else if (our_tv->v_type == VAR_FLOAT)
index 3cc5ff2d9fc715af1f927a3bedee45ac2c01c370..8fc62d699131608bd5362184b1dc291a5442d672 100644 (file)
@@ -305,7 +305,12 @@ endfunc
 
 " Test vim.eval() with various types.
 func Test_python3_vim_eval()
-  call assert_equal("\n8",             execute('py3 print(vim.eval("3+5"))'))
+  call assert_equal("\n2061300532912", execute('py3 print(vim.eval("2061300532912"))'))
+  call assert_equal("\n9223372036854775807", execute('py3 print(vim.eval("9223372036854775807"))'))
+  call assert_equal("\n-9223372036854775807",execute('py3 print(vim.eval("-9223372036854775807"))'))
+  call assert_equal("\n2147483648",  execute('py3 print(vim.eval("2147483648"))'))
+  call assert_equal("\n-2147483649", execute('py3 print(vim.eval("-2147483649"))'))
+  call assert_equal("\n8",           execute('py3 print(vim.eval("3+5"))'))
   call assert_equal("\n3.140000",    execute('py3 print(vim.eval("1.01+2.13"))'))
   call assert_equal("\n0.000000",    execute('py3 print(vim.eval("0.0/(1.0/0.0)"))'))
   call assert_equal("\n0.000000",    execute('py3 print(vim.eval("0.0/(1.0/0.0)"))'))
index 9e5cfdcd557db8188b2583890f532fac8779eb6e..e02438312fbc91e50666833941d6e9def668be27 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1967,
 /**/
     1966,
 /**/