[pypy-issue] Issue #2499: cpyext: PyString_AsString() doesn't work (pypy/pypy)

Victor Stinner issues-reply at bitbucket.org
Wed Mar 15 20:33:29 EDT 2017


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.




More information about the pypy-issue mailing list