Py_BuildValue is an overkill when all you need is a simple string.

# HG changeset patch
# User ZyX <[email protected]>
# Date 1369474993 -14400
# Node ID df22b77f9a4b8172c6b41745a42a0574ce907d14
# Parent  cc578271bc44d90911e71c3e0992772826e5e26c
Purge out more Py_BuildValue: now don’t use it for building strings

diff -r cc578271bc44 -r df22b77f9a4b src/if_py_both.h
--- a/src/if_py_both.h  Sat May 25 13:34:21 2013 +0400
+++ b/src/if_py_both.h  Sat May 25 13:43:13 2013 +0400
@@ -442,7 +442,7 @@
 
     if (our_tv->v_type == VAR_STRING)
     {
-       result = Py_BuildValue("s", our_tv->vval.v_string == NULL
+       result = PyString_FromString(our_tv->vval.v_string == NULL
                                        ? "" : (char *)our_tv->vval.v_string);
     }
     else if (our_tv->v_type == VAR_NUMBER)
@@ -451,7 +451,7 @@
 
        /* For backwards compatibility numbers are stored as strings. */
        sprintf(buf, "%ld", (long)our_tv->vval.v_number);
-       result = Py_BuildValue("s", buf);
+       result = PyString_FromString((char *) buf);
     }
 # ifdef FEAT_FLOAT
     else if (our_tv->v_type == VAR_FLOAT)
@@ -459,7 +459,7 @@
        char buf[NUMBUFLEN];
 
        sprintf(buf, "%f", our_tv->vval.v_float);
-       result = Py_BuildValue("s", buf);
+       result = PyString_FromString((char *) buf);
     }
 # endif
     else if (our_tv->v_type == VAR_LIST)
@@ -3256,7 +3256,7 @@
 BufferAttr(BufferObject *self, char *name)
 {
     if (strcmp(name, "name") == 0)
-       return Py_BuildValue("s", self->buf->b_ffname);
+       return PyString_FromString((char *) self->buf->b_ffname);
     else if (strcmp(name, "number") == 0)
        return Py_BuildValue(Py_ssize_t_fmt, self->buf->b_fnum);
     else if (strcmp(name, "vars") == 0)

-- 
-- 
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.


Raspunde prin e-mail lui