Commit 370e670
gh-153419: Fix several issues around bytearray __init__ (GH-153498)
Introduce a bytearray_new() function to ensure that
ob_bytes_object is always set on a bytearray.
Resizing a bytearray to 0 length now explicitly sets
the ob_bytes_object to the empty constant immortal.
Add a check in the 'bytearray init from string'
fast path to ensure there are no active exports.
This fixes asserts/crashes on the following:
- bytearray(1).__init__()
- bytearray().__new__(bytearray).append(1)
- a = bytearray(); b = memoryview(a); a.__init__('x', 'ascii')
(cherry picked from commit d5c1b29)
Co-authored-by: Steve Stagg <stestagg@gmail.com>
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
1 parent 99f6844 commit 370e670
4 files changed
Lines changed: 78 additions & 12 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Objects
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2197 | 2197 | | |
2198 | 2198 | | |
2199 | 2199 | | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
2200 | 2240 | | |
2201 | 2241 | | |
2202 | 2242 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
216 | 219 | | |
217 | 220 | | |
218 | 221 | | |
| |||
236 | 239 | | |
237 | 240 | | |
238 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
239 | 250 | | |
240 | 251 | | |
241 | 252 | | |
| |||
902 | 913 | | |
903 | 914 | | |
904 | 915 | | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
905 | 930 | | |
906 | 931 | | |
907 | 932 | | |
| |||
920 | 945 | | |
921 | 946 | | |
922 | 947 | | |
923 | | - | |
924 | | - | |
925 | | - | |
926 | | - | |
927 | | - | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
928 | 952 | | |
929 | 953 | | |
930 | | - | |
931 | | - | |
932 | | - | |
933 | | - | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
934 | 957 | | |
935 | | - | |
936 | | - | |
937 | 958 | | |
938 | 959 | | |
939 | 960 | | |
| |||
1607 | 1628 | | |
1608 | 1629 | | |
1609 | 1630 | | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
1610 | 1634 | | |
1611 | 1635 | | |
1612 | 1636 | | |
| |||
2937 | 2961 | | |
2938 | 2962 | | |
2939 | 2963 | | |
2940 | | - | |
| 2964 | + | |
2941 | 2965 | | |
2942 | 2966 | | |
2943 | 2967 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3380 | 3380 | | |
3381 | 3381 | | |
3382 | 3382 | | |
| 3383 | + | |
3383 | 3384 | | |
3384 | 3385 | | |
3385 | 3386 | | |
| |||
0 commit comments