Comments (8)
Note that the result of object.__sizeof__(1)
being an unexpected value is not necessarily a bug, the __sizeof__
method is overridden in int
and gives the expected value there. Also as a user the interface to get the size of an object is sys.getsizeof(1)
.
The crash in debug mode is likely because PyLongObject is not a PyVarObject in 3.12 even though the type has ob_itemsize
set to a nonzero value. In 3.9 the type is a PyVarObject, but doesn't follow the protocol entirely because the sign of the int
value is stored in ob_itemsize
.
I'm not familiar enough with the code in longobject.c and its evolution to know what's the best fix for 3.12. Long term it is probably better to unset ob_itemsize
, but who knows what will break when that change is made in 3.12.
from cpython.
object.__sizeof__(1)
gives me 56, but int.__sizeof__(1)
and 1 .__sizeof__()
and sys.getsizeof(1)
all give me 28. And id(1) - id(0)
and id(2) - id(1))
both give me 32. So it's certainly only object.__sizeof__
misreporting the size. (In Python 3.12.0.)
from cpython.
It's ends up with an assertion error on debug build for me (current main branch):
./python
Python 3.13.0a5+ (heads/main:eebea7e515, Mar 24 2024, 21:43:31) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> object.__sizeof__(1)
python: ./Include/object.h:344: Py_SIZE: Assertion `ob->ob_type != &PyLong_Type' failed.
Aborted
from cpython.
In 3.11, size of -1000, -1, 0, 1. 1000 are 20, 20, 24, 28, 28. In 3.13, 64, 64, 28, 56 , 56. I am not sure if really a 'bug' rather than intentional, but the only mention of 'size of' in 3.12 What's New is that str object size decreased and no mention that size of ints doubled. I seem's like a regression in memory use. The changelog has several mentions of sizes decreasing and only mentions a stack size increase.
from cpython.
./python
Python 3.13.0a5+ (heads/main:9967b568ed, Mar 23 2024, 16:10:16) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> object.__sizeof__(1)
56
from cpython.
./python Python 3.13.0a5+ (heads/main:9967b568ed, Mar 23 2024, 16:10:16) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> object.__sizeof__(1) 56
Is this a debug build? For the debug build, you should use ./configure --with-pydebug
on Linux or pcbuild/build.bat -c Debug
on Windows
from cpython.
Perhaps @markshannon is the right person for this discussion.
from cpython.
The result of object.__sizeof__(1)
is not meaningful, but it shouldn't crash.
from cpython.
Related Issues (20)
- 3.12.4 not recognised as gzip format HOT 1
- 3.12.4 Broke poetry for Docker python:alpine3.20 HOT 9
- `ctypes._FuncPtr` doesn't seem to exist as described in the doc (misspelled `_CFuncType`?) HOT 2
- Using internal tokenize module's TokenizerIter in multiple threads crashes
- Missing type checking on `maxsize` arg of `queue.Queue` class during initialization HOT 8
- Optimize random.choice when there is just one item HOT 4
- SIGSEGV with generators in free-threaded build HOT 6
- it is not detecting in cmd HOT 1
- Tier 2 optimizer: constant propagate through attribute loads HOT 2
- Tier 2 optimizer: refactor to reuse constant symbols
- Python 3.13 beta 2 build fails on Windows when using both `--experimental-jit` and `--disable-gil` HOT 7
- Compiler RecursionError more likely to occur in 3.13 HOT 1
- Multiple lines f-string with non-ASCII breaks tokenize.generate_tokens in 3.12.4 HOT 6
- Incorrect use of the :class: role with the "()" suffix
- PYTHON_BASIC_REPL is ignored by interactive inspect HOT 2
- Add a limit to `string.zfill` so it will raise an error to lengths bigger that the int in the brackets HOT 4
- Add option for "pydoc -b" to open new browser window.
- `idlelib/help.html` is outdated HOT 7
- `enum.nonmember` type-decays Flag values HOT 11
- no_redundant_jumps: Assertion `0' failed HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.