create PyString

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torsten Mohr

    create PyString

    Hi,

    in an extension module i'd like to create a very large PyString.
    As the string is very large i'd first like to create the string
    and let Python allocate the space for it and then fill it from
    my code.

    But the only interface that i can find in Python/stringobject.h
    is:

    PyAPI_FUNC(PyOb ject *) PyString_FromSt ringAndSize(con st char *, Py_ssize_t);

    But my extension module does not have the data consecutively in memory.

    If i'd use this function i'd first have to allocate the data, construct the
    string and then let python _again_ allocate the same amount of memory
    and copy my data.


    Is there a way to tell python to:
    1. let python create a PyString with an allocated buffer
    2. let my extension module fill the buffer
    3. let python validate the strings hash value and whatever else is
    necessary?


    Thanks for any hints,
    Torsten.

Working...