This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年09月20日 17:57 by skrah, last changed 2022年04月11日 14:57 by admin.
| Messages (9) | |||
|---|---|---|---|
| msg224389 - (view) | Author: Josh Rosenberg (josh.r) * (Python triager) | Date: 2014年07月31日 10:54 | |
To do what? |
|||
| msg224394 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年07月31日 11:29 | |
This issue was linked from <https://mail.python.org/pipermail/python-dev/2012-September/121781.html>. I was looking for ways to pass read-only memory views into "ctypes" without copying memory, and came across that thread. Assuming this "buf" attribute points to the memory of the memory view, it could then be passed to "ctypes.c_void_p" or "_CData.from_address". |
|||
| msg224410 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年07月31日 15:05 | |
ctypes could grow a way to access the Py_buffer API instead. |
|||
| msg224413 - (view) | Author: David Beazley (dabeaz) | Date: 2014年07月31日 15:19 | |
There are other kinds of libraries that might want to access the .buf attribute. For example, the llvmpy extension. Exposing it would be useful. |
|||
| msg224415 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年07月31日 15:20 | |
Ha, llvmpy... Yes, it could be useful. It's dangerous too, especially since the buffer isn't necessarily contiguous. |
|||
| msg224416 - (view) | Author: David Beazley (dabeaz) | Date: 2014年07月31日 15:24 | |
Well, a lot of things in this big bad world are dangerous. Don't see how this is any more dangerous than all of the peril that tools like ctypes and llvmpy already provide. |
|||
| msg224417 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年07月31日 15:26 | |
Le 31/07/2014 11:24, David Beazley a écrit : > > Well, a lot of things in this big bad world are dangerous. Don't see how this is any more dangerous than all of the peril that tools like ctypes and llvmpy already provide. The point of the buffer API is to make memory access *less* dangerous than with the perilous tools, though. Otherwise we might as well decide that Python crashes because C crashes :-) (as for llvmpy, I think its implementation deserves to die) |
|||
| msg224418 - (view) | Author: David Beazley (dabeaz) | Date: 2014年07月31日 15:34 | |
One of the other goals of memoryviews is to make memory access less hacky. To that end, it would be nice to have the .buf attribute available given that all of the other attributes are already there. I don't see why people should need to do some even more hacky hack thing on top of hacks just to expose the pointer (which they'll figure out how to do anyway if they actually need to use it for something). |
|||
| msg227669 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2014年09月27日 12:51 | |
Sometimes I've used memoryview slices to model pointers in C code. memoryview could have limited number methods for pointer arithmetic on the buf pointer. Arithmetic would return new slices, so in fact everything would be safe with respect to bounds checking and life-cycle management. Not completely safe of course once you pass the pointer to ctypes, but the following is less likely to happen: m = memoryview(b"123") ptr = m.buf del m my_ctypes_func(ptr) This is safer, since the view itself is the pointer: m = memoryview(b"123") my_ctypes_func(m) Of course you could still subvert the second idiom by using ptr = int(m). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:36 | admin | set | github: 60190 |
| 2014年09月27日 12:51:54 | skrah | set | messages: + msg227669 |
| 2014年07月31日 15:34:06 | dabeaz | set | messages: + msg224418 |
| 2014年07月31日 15:26:30 | pitrou | set | messages: + msg224417 |
| 2014年07月31日 15:24:43 | dabeaz | set | messages: + msg224416 |
| 2014年07月31日 15:20:50 | pitrou | set | messages: + msg224415 |
| 2014年07月31日 15:19:20 | dabeaz | set | messages: + msg224413 |
| 2014年07月31日 15:05:12 | pitrou | set | nosy:
+ pitrou, belopolsky, amaury.forgeotdarc, meador.inge messages: + msg224410 |
| 2014年07月31日 11:29:50 | martin.panter | set | messages: + msg224394 |
| 2014年07月31日 10:54:48 | josh.r | set | nosy:
+ josh.r messages: + msg224389 |
| 2014年07月31日 09:01:04 | martin.panter | set | nosy:
+ martin.panter |
| 2012年09月20日 17:57:18 | skrah | create | |