You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [~] **For Record:** Implement these so `r[0]` and `len(r)` work *(design understood, implementation pending)*
151
+
- [x] **For Record:** Implement these so `r[0]` and `len(r)` work
152
152
153
153
**Notes from session:**
154
154
- `PySequenceMethods` contains: `sq_length`, `sq_concat`, `sq_repeat`, `sq_item`, `sq_ass_item`, `sq_contains`, etc.
@@ -243,38 +243,132 @@ r == r2 # comparable
243
243
## Phase 5: Implementation
244
244
245
245
### 5.1 Create the Header File
246
-
- [ ] Create `Include/recordobject.h`
247
-
- [ ] Define `RecordObject` struct
248
-
- [ ] Declare `PyRecord_Type`
249
-
- [ ] Declare `PyRecord_New()` constructor function
246
+
- [x] Create `Include/recordobject.h`
247
+
- [x] Define `RecordObject` struct
248
+
- [x] Declare `PyRecord_Type`
249
+
- [x] Declare `PyRecord_New()` constructor function
250
+
251
+
**Notes from session:**
252
+
- Two-level header structure: `Include/recordobject.h` (public) includes `Include/cpython/recordobject.h` (internal)
253
+
- Must add `#include "recordobject.h"` to `Include/Python.h` for it to be visible
254
+
- `PyRecord_Check` macro simplified to `Py_IS_TYPE(op, &PyRecord_Type)` (no subclass flag)
250
255
251
256
### 5.2 Implement the Type
252
-
- [ ] Create `Objects/recordobject.c`
253
-
- [ ] Implement `record_dealloc`
254
-
- [ ] Implement `record_repr`
255
-
- [ ] Implement `record_hash`
256
-
- [ ] Implement `record_richcompare`
257
-
- [ ] Implement `record_length` (sq_length)
258
-
- [ ] Implement `record_item` (sq_item)
259
-
- [ ] Implement `record_getattro` (attribute access by name)
260
-
- [ ] Define `PyRecord_Type` with all slots filled
261
-
- [ ] Implement `PyRecord_New()` - the C API constructor
257
+
- [x] Create `Objects/recordobject.c`
258
+
- [x] Implement `record_dealloc`
259
+
- [x] Implement `record_repr`
260
+
- [x] Implement `record_hash`
261
+
- [x] Implement `record_richcompare`
262
+
- [x] Implement `record_length` (sq_length)
263
+
- [x] Implement `record_item` (sq_item)
264
+
- [x] Implement `record_getattro` (attribute access by name)
265
+
- [x] Define `PyRecord_Type` with all slots filled
266
+
- [x] Implement `PyRecord_New()` - the C API constructor
267
+
268
+
**Notes from session:**
269
+
- Started by copying tupleobject.c, then stripped out complexity (clinic, free lists, etc.)
270
+
- **GC gotcha:** Originally had GC alloc/track/untrack but no `Py_TPFLAGS_HAVE_GC` or `tp_traverse` - caused segfault. Fixed by removing GC entirely (simpler for learning)
271
+
- **record_dealloc:** `Py_XDECREF(names)` + XDECREF each value, use XDECREF (handles NULL safely)
272
+
- **record_repr:** Use `_PyUnicodeWriter`, format as `record(x=1, y=2)`, don't repr the field names (just write them directly)
273
+
- **record_hash:** Copied xxHash pattern from tuple, hash names tuple + all values, `-1` → `-2` for actual -1 hash
274
+
- **record_getattro:** Loop through names with `PyUnicode_Compare`, return value with INCREF, fallback to `PyObject_GenericGetAttr`
275
+
- **record_richcompare:** Compare names first (if different, not equal), then values; return `Py_NotImplemented` for ordering
276
+
- **record_new (tp_new):** Parse kwargs with `PyDict_Keys`/`PyDict_Values`, convert keys to tuple for names
0 commit comments