comparison src/if_py_both.h @ 4321:d8d9c591c50f v7.3.910

updated for version 7.3.910 Problem: Python code in #ifdef branches with only minor differences. Solution: Merge the #ifdef branches. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Wed, 24 Apr 2013 13:47:45 +0200
parents b79f3c3a584c
children f1eab4f77a6f
comparison
equal deleted inserted replaced
4320:4c7931bbf78a 4321:d8d9c591c50f
2851 return -1; 2851 return -1;
2852 2852
2853 tv->v_type = VAR_FUNC; 2853 tv->v_type = VAR_FUNC;
2854 func_ref(tv->vval.v_string); 2854 func_ref(tv->vval.v_string);
2855 } 2855 }
2856 #if PY_MAJOR_VERSION >= 3
2857 else if (PyBytes_Check(obj)) 2856 else if (PyBytes_Check(obj))
2858 { 2857 {
2859 char_u *result; 2858 char_u *result;
2860 2859
2861 if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1) 2860 if (PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
2871 else if (PyUnicode_Check(obj)) 2870 else if (PyUnicode_Check(obj))
2872 { 2871 {
2873 PyObject *bytes; 2872 PyObject *bytes;
2874 char_u *result; 2873 char_u *result;
2875 2874
2876 bytes = PyString_AsBytes(obj);
2877 if (bytes == NULL)
2878 return -1;
2879
2880 if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
2881 return -1;
2882 if (result == NULL)
2883 return -1;
2884
2885 if (set_string_copy(result, tv) == -1)
2886 {
2887 Py_XDECREF(bytes);
2888 return -1;
2889 }
2890 Py_XDECREF(bytes);
2891
2892 tv->v_type = VAR_STRING;
2893 }
2894 #else
2895 else if (PyUnicode_Check(obj))
2896 {
2897 PyObject *bytes;
2898 char_u *result;
2899
2900 bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL); 2875 bytes = PyUnicode_AsEncodedString(obj, (char *)ENC_OPT, NULL);
2901 if (bytes == NULL) 2876 if (bytes == NULL)
2902 return -1; 2877 return -1;
2903 2878
2904 if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1) 2879 if(PyString_AsStringAndSize(bytes, (char **) &result, NULL) == -1)
2913 } 2888 }
2914 Py_XDECREF(bytes); 2889 Py_XDECREF(bytes);
2915 2890
2916 tv->v_type = VAR_STRING; 2891 tv->v_type = VAR_STRING;
2917 } 2892 }
2918 else if (PyString_Check(obj)) 2893 #if PY_MAJOR_VERSION < 3
2919 {
2920 char_u *result;
2921
2922 if(PyString_AsStringAndSize(obj, (char **) &result, NULL) == -1)
2923 return -1;
2924 if (result == NULL)
2925 return -1;
2926
2927 if (set_string_copy(result, tv) == -1)
2928 return -1;
2929
2930 tv->v_type = VAR_STRING;
2931 }
2932 else if (PyInt_Check(obj)) 2894 else if (PyInt_Check(obj))
2933 { 2895 {
2934 tv->v_type = VAR_NUMBER; 2896 tv->v_type = VAR_NUMBER;
2935 tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj); 2897 tv->vval.v_number = (varnumber_T) PyInt_AsLong(obj);
2936 } 2898 }