SourceForge logo
SourceForge logo
Menu

Re: [matplotlib-devel] Experiments in removing/replacing PyCXX

From: Michael D. <md...@st...> - 2012年12月04日 13:46:02
On 12/03/2012 08:01 PM, Chris Barker - NOAA Federal wrote:
> On Mon, Dec 3, 2012 at 4:16 PM, Nathaniel Smith <nj...@po...> wrote:
>
>> Yeah, this is a general problem with the Python file API, trying to
>> hook it up to stdio is not at all an easy thing. A better version of
>> this code would skip that altogether like:
>>
>> cdef void write_to_pyfile(png_structp s, png_bytep data, png_size_t count):
>> fobj = <object>png_get_io_ptr(s)
>> pydata = PyString_FromStringAndSize(data, count)
>> fobj.write(pydata)
> Good point -- not at all Cython-specific, but do you need libpng (or
> whatever) to write to the file? can you just get a buffer with the
> encoded data and write it on the Python side? Particularly if the user
> wants to pass in an open file object. This might be a better API for
> folks that might want stream an image right through a web app, too.
You need to support both: raw C FILE objects for speed, and writing to a 
Python file-like object for flexibility. The code in master already 
does this (albeit with PyCXX), and the code on my "No CXX" branch does 
this as well with Cython.
>
> As a lot of Python APIs take either a file name or a file-like object,
> perhaps it would make sense to push that distinction down to the
> Cython level:
> -- if it's a filename, open it with raw C
Unfortunately, as stated in detail in my last e-mail, that doesn't work 
with Unicode paths.
> -- if it's a file-like object, have libpng write to a buffer (bytes
> object) , and pass that to the file-like object in Python
libpng does one better and allows us to stream directly to a callback 
which can then write to a Python object. This prevents double 
allocation of memory.
>
> anyway, not really a Cython issue, but that second object sure would
> be easy on Cython....
>
Yeah -- once I figured out how to make a real C callback function from 
Cython, the contents of the callback function itself is pretty easy to 
write.
Mike

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /