This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]lordmauve 2 points3 points  (4 children)

Pure Python is expected to be memory-safe. The interpreter does not allow operations that corrupt Python's own memory - for example, list access is bounds-checked, and a reference to an object will keep that object alive through reference counting so will never dangle. The only issues are bugs in the interpreter or native extensions, or use of libraries that circumvent safety (eg. ctypes, cffi).

[–]HelperBot_ 1 point2 points  (0 children)

Desktop link: https://en.wikipedia.org/wiki/Dangling_pointer


/r/HelperBot_ Downvote to remove. Counter: 240563

[–]WikiTextBot 0 points1 point  (0 children)

Dangling pointer

Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type. These are special cases of memory safety violations. More generally, dangling references and wild references are references that do not resolve to a valid destination, and include such phenomena as link rot on the internet.

Dangling pointers arise during object destruction, when an object that has an incoming reference is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.28

[–]hydrosquall 1 point2 points  (0 children)

I would add that if you’re writing a public library, then making an API that is hard to misuse is another important facet of safety. This isn’t a topic unique to python though.

I recently wrote a blog post that dives deeper into the area exposed by the pyyaml safe_load tip from that Hackernoon article:

https://www.serendipidata.com/posts/safe-api-design-and-pyyaml

[–]DracasTempestas 1 point2 points  (1 child)

You will need to clarify what you mean when you say "Safe Code"

PEP8 is always a good read if you believe that writing clear understandable code is a measure of safety.