question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

memory view over 'bytes', incorrect doc?

See original GitHub issue

Hi! I was trying to write a function accepting string/bytes and returning string/bytes again. I found an example of accepting strings in the documentation: https://cython.readthedocs.io/en/latest/src/tutorial/strings.html#accepting-strings-from-python-code

but it doesn’t work:

def process_byte_data(unsigned char[:] data):
    length = data.shape[0]
    first_byte = data[0]
    slice_view = data[1:-1]

b = b'asd'
process_byte_data(b)

results in

BufferError: Object is not writable.

(Relevant topic in mailing list: https://groups.google.com/d/topic/cython-users/32CMgaLrNhc/discussion)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
TeamSpen210commented, Oct 12, 2018

You need to specify it as const, since bytes is readonly. That should probably be highlighted more in the tutorial.

0reactions
scodercommented, Oct 13, 2018

You need to specify it as const, since bytes is readonly. That should probably be highlighted more in the tutorial.

Absolutely. Docs PR welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Obtaining pointer to python memoryview on bytes object
My problem is: because the bytes object is not writable, cython does not allow constructing a typed (cython) memoryview from it; I cannot...
Read more >
Memory allocation errors can be caused by slow page file ...
Memory allocation failures can occur due to latencies that are associated with growing the size of a page file to support additional memory ......
Read more >
memoryview() in Python - GeeksforGeeks
The memoryview() function allows direct read and write access to an object's byte-oriented data without needing to copy it first.
Read more >
4. Built-in Types — Python 3.6.3 documentation - Read the Docs
The integer is represented using length bytes. An OverflowError is raised if the integer is not representable with the given number of bytes....
Read more >
Troubleshooting Memory Leaks - Oracle Help Center
The document provides a description of the tools, command line options, and other help in analyzing a problem. The document also provides guidance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found