cpyext: PyString_AsString() doesn't work

Issue #2499 closed
Victor Stinner
created an issue

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

Comments (3)

  1. Log in to comment