New issue 2499: cpyext: PyString_AsString() doesn't work
https://bitbucket.org/pypy/pypy/issues/2499/cpyext-pystring_asstring-doesnt-work

Victor Stinner:

The following fuction returns '\x01\x02' on CPytohn, but '\x00\x00' on PyPy.

```
static PyObject *py_apply_delta(PyObject *self, PyObject *args)
{
        uint8_t *out;
        PyObject *ret;

        ret = PyString_FromStringAndSize(NULL, 2);
        if (ret == NULL) {
                PyErr_NoMemory();
                return NULL;
        }
        out = (uint8_t *)PyString_AsString(ret);
        out[0] = 1;
        out[1] = 2;
        return ret;
}
```

If you replace PyString_AsString() with PyString_AS_STRING(), it works as 
expected.

It seems like PyString_AS_STRING() behaves differently.


_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to