that would mess up the inner mecanism of std::string

Le 9 mars 2013 21:49, "serge-sans-paille" <notifications@github.com> a
écrit :

In pythran/pythonic++/core/file.h:

> +                    // Getline will always realloc content to store full string.
> +                    // => Emulating expected behaviour
> +                    char *content = nullptr;
> +                    size_t real_size = getline(&content, &real_size, **data); // Careful return type
> +                    if((ssize_t)real_size == -1 && not eof()){
> +                        int errsv = errno; // Saving errno since throw or another thread can change it
> +                        free(content);
> +                        throw IOError("file.readline() : errno "+errsv);
> +                    }
> +                    if (real_size > size){
> +                        fseek(**data, -(long)(real_size - size), SEEK_CUR);
> +                        content[size] = '\0';
> +                    }
> +                    // TODO: This part needs a new implementation of core::string(char*) to avoid unnecessary copy.
> +                    core::string res(content);
> +                    free(content);

same const_cast + c_char + reserve trick ?



—
Reply to this email directly or view it on GitHub.[image]