comparison src/if_py_both.h @ 4995:b4a2eaf28b51 v7.3.1242

updated for version 7.3.1242 Problem: No failure when trying to use a number as a string. Solution: Give an error when StringToLine() is called with an instance of the wrong type. (Jun Takimoto)
author Bram Moolenaar <bram@vim.org>
date Mon, 24 Jun 2013 22:33:30 +0200
parents e130cc3d17af
children 34c629c3b4ba
comparison
equal deleted inserted replaced
4994:879ebefc462c 4995:b4a2eaf28b51
3547 else if (PyUnicode_Check(obj)) 3547 else if (PyUnicode_Check(obj))
3548 { 3548 {
3549 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL))) 3549 if (!(bytes = PyUnicode_AsEncodedString(obj, ENC_OPT, NULL)))
3550 return NULL; 3550 return NULL;
3551 3551
3552 if(PyBytes_AsStringAndSize(bytes, &str, &len) == -1 3552 if (PyBytes_AsStringAndSize(bytes, &str, &len) == -1
3553 || str == NULL) 3553 || str == NULL)
3554 { 3554 {
3555 Py_DECREF(bytes); 3555 Py_DECREF(bytes);
3556 return NULL; 3556 return NULL;
3557 } 3557 }
3558 }
3559 else
3560 {
3561 #if PY_MAJOR_VERSION < 3
3562 PyErr_FORMAT(PyExc_TypeError,
3563 N_("expected str() or unicode() instance, but got %s"),
3564 Py_TYPE_NAME(obj));
3565 #else
3566 PyErr_FORMAT(PyExc_TypeError,
3567 N_("expected bytes() or str() instance, but got %s"),
3568 Py_TYPE_NAME(obj));
3569 #endif
3570 return NULL;
3558 } 3571 }
3559 3572
3560 /* 3573 /*
3561 * Error checking: String must not contain newlines, as we 3574 * Error checking: String must not contain newlines, as we
3562 * are replacing a single line, and we must replace it with 3575 * are replacing a single line, and we must replace it with