# HG changeset patch
# User ZyX <[email protected]>
# Date 1366476712 -14400
# Branch python-extended-2
# Node ID 3d61e036e5a6856a08e6e67bd9f372ebd79de15e
# Parent  588f9ea6424cf54f1ca879c1e9503dfa1a140eab
Reduce number of lines in ConvertFromPyObject code

diff -r 588f9ea6424c -r 3d61e036e5a6 src/if_py_both.h
--- a/src/if_py_both.h  Sat Apr 20 21:56:51 2013 +0400
+++ b/src/if_py_both.h  Sat Apr 20 20:51:52 2013 +0400
@@ -2852,7 +2852,6 @@
        tv->v_type = VAR_FUNC;
        func_ref(tv->vval.v_string);
     }
-#if PY_MAJOR_VERSION >= 3
     else if (PyBytes_Check(obj))
     {
        char_u  *result;
@@ -2872,7 +2871,7 @@
        PyObject        *bytes;
        char_u  *result;
 
-       bytes = PyString_AsBytes(obj);
+       bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
        if (bytes == NULL)
            return -1;
 
@@ -2890,44 +2889,7 @@
 
        tv->v_type = VAR_STRING;
     }
-#else
-    else if (PyUnicode_Check(obj))
-    {
-       PyObject        *bytes;
-       char_u  *result;
-
-       bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
-       if (bytes == NULL)
-           return -1;
-
-       if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
-           return -1;
-       if (result == NULL)
-           return -1;
-
-       if (set_string_copy(result, tv) == -1)
-       {
-           Py_XDECREF(bytes);
-           return -1;
-       }
-       Py_XDECREF(bytes);
-
-       tv->v_type = VAR_STRING;
-    }
-    else if (PyString_Check(obj))
-    {
-       char_u  *result;
-
-       if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
-           return -1;
-       if (result == NULL)
-           return -1;
-
-       if (set_string_copy(result, tv) == -1)
-           return -1;
-
-       tv->v_type = VAR_STRING;
-    }
+#if PY_MAJOR_VERSION < 3
     else if (PyInt_Check(obj))
     {
        tv->v_type = VAR_NUMBER;
diff -r 588f9ea6424c -r 3d61e036e5a6 src/if_python.c
--- a/src/if_python.c   Sat Apr 20 21:56:51 2013 +0400
+++ b/src/if_python.c   Sat Apr 20 20:51:52 2013 +0400
@@ -59,6 +59,7 @@
 static void init_structs(void);
 
 #define PyBytes_FromString PyString_FromString
+#define PyBytes_Check PyString_Check
 
 /* No-op conversion functions, use with care! */
 #define PyString_AsBytes(obj) (obj)

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


diff -cr vim.588f9ea6424c/src/if_py_both.h vim.3d61e036e5a6/src/if_py_both.h
*** vim.588f9ea6424c/src/if_py_both.h	2013-04-23 21:31:04.607740426 +0400
--- vim.3d61e036e5a6/src/if_py_both.h	2013-04-23 21:31:04.614740220 +0400
***************
*** 2852,2858 ****
  	tv->v_type = VAR_FUNC;
  	func_ref(tv->vval.v_string);
      }
- #if PY_MAJOR_VERSION >= 3
      else if (PyBytes_Check(obj))
      {
  	char_u	*result;
--- 2852,2857 ----
***************
*** 2872,2901 ****
  	PyObject	*bytes;
  	char_u	*result;
  
- 	bytes = PyString_AsBytes(obj);
- 	if (bytes == NULL)
- 	    return -1;
- 
- 	if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
- 	    return -1;
- 	if (result == NULL)
- 	    return -1;
- 
- 	if (set_string_copy(result, tv) == -1)
- 	{
- 	    Py_XDECREF(bytes);
- 	    return -1;
- 	}
- 	Py_XDECREF(bytes);
- 
- 	tv->v_type = VAR_STRING;
-     }
- #else
-     else if (PyUnicode_Check(obj))
-     {
- 	PyObject	*bytes;
- 	char_u	*result;
- 
  	bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
  	if (bytes == NULL)
  	    return -1;
--- 2871,2876 ----
***************
*** 2914,2933 ****
  
  	tv->v_type = VAR_STRING;
      }
!     else if (PyString_Check(obj))
!     {
! 	char_u	*result;
! 
! 	if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
! 	    return -1;
! 	if (result == NULL)
! 	    return -1;
! 
! 	if (set_string_copy(result, tv) == -1)
! 	    return -1;
! 
! 	tv->v_type = VAR_STRING;
!     }
      else if (PyInt_Check(obj))
      {
  	tv->v_type = VAR_NUMBER;
--- 2889,2895 ----
  
  	tv->v_type = VAR_STRING;
      }
! #if PY_MAJOR_VERSION < 3
      else if (PyInt_Check(obj))
      {
  	tv->v_type = VAR_NUMBER;
diff -cr vim.588f9ea6424c/src/if_python.c vim.3d61e036e5a6/src/if_python.c
*** vim.588f9ea6424c/src/if_python.c	2013-04-23 21:31:04.610740337 +0400
--- vim.3d61e036e5a6/src/if_python.c	2013-04-23 21:31:04.616740161 +0400
***************
*** 59,64 ****
--- 59,65 ----
  static void init_structs(void);
  
  #define PyBytes_FromString PyString_FromString
+ #define PyBytes_Check PyString_Check
  
  /* No-op conversion functions, use with care! */
  #define PyString_AsBytes(obj) (obj)

Raspunde prin e-mail lui