| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,7 @@ typedef struct { | |||
| 12 | 12 | } _PyVMData; | |
| 13 | 13 | ||
| 14 | 14 | typedef struct _PyExecutorObject { | |
| 15 | - PyObject_HEAD | ||
| 15 | + PyObject_VAR_HEAD | ||
| 16 | 16 | /* WARNING: execute consumes a reference to self. This is necessary to allow executors to tail call into each other. */ | |
| 17 | 17 | struct _PyInterpreterFrame *(*execute)(struct _PyExecutorObject *self, struct _PyInterpreterFrame *frame, PyObject **stack_pointer); | |
| 18 | 18 | _PyVMData vm_data; /* Used by the VM, but opaque to the optimizer */ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ typedef struct { | |||
| 18 | 18 | ||
| 19 | 19 | typedef struct { | |
| 20 | 20 | _PyExecutorObject base; | |
| 21 | - _PyUOpInstruction trace[_Py_UOP_MAX_TRACE_LENGTH]; // TODO: variable length | ||
| 21 | + _PyUOpInstruction trace[1]; | ||
| 22 | 22 | } _PyUOpExecutorObject; | |
| 23 | 23 | ||
| 24 | 24 | _PyInterpreterFrame *_PyUopExecute( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Make ``_PyUOpExecutorObject`` variable length. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,13 +320,7 @@ uop_name(int index) { | |||
| 320 | 320 | static Py_ssize_t | |
| 321 | 321 | uop_len(_PyUOpExecutorObject *self) | |
| 322 | 322 | { | |
| 323 | - int count = 0; | ||
| 324 | - for (; count < _Py_UOP_MAX_TRACE_LENGTH; count++) { | ||
| 325 | - if (self->trace[count].opcode == 0) { | ||
| 326 | - break; | ||
| 327 | - } | ||
| 328 | - } | ||
| 329 | - return count; | ||
| 323 | + return Py_SIZE(self); | ||
| 330 | 324 | } | |
| 331 | 325 | ||
| 332 | 326 | static PyObject * | |
@@ -368,8 +362,8 @@ PySequenceMethods uop_as_sequence = { | |||
| 368 | 362 | static PyTypeObject UOpExecutor_Type = { | |
| 369 | 363 | PyVarObject_HEAD_INIT(&PyType_Type, 0) | |
| 370 | 364 | .tp_name = "uop_executor", | |
| 371 | - .tp_basicsize = sizeof(_PyUOpExecutorObject), | ||
| 372 | - .tp_itemsize = 0, | ||
| 365 | + .tp_basicsize = sizeof(_PyUOpExecutorObject) - sizeof(_PyUOpInstruction), | ||
| 366 | + .tp_itemsize = sizeof(_PyUOpInstruction), | ||
| 373 | 367 | .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION, | |
| 374 | 368 | .tp_dealloc = (destructor)uop_dealloc, | |
| 375 | 369 | .tp_as_sequence = &uop_as_sequence, | |
@@ -699,15 +693,12 @@ uop_optimize( | |||
| 699 | 693 | return trace_length; | |
| 700 | 694 | } | |
| 701 | 695 | OBJECT_STAT_INC(optimization_traces_created); | |
| 702 | - _PyUOpExecutorObject *executor = PyObject_New(_PyUOpExecutorObject, &UOpExecutor_Type); | ||
| 696 | + _PyUOpExecutorObject *executor = PyObject_NewVar(_PyUOpExecutorObject, &UOpExecutor_Type, trace_length); | ||
| 703 | 697 | if (executor == NULL) { | |
| 704 | 698 | return -1; | |
| 705 | 699 | } | |
| 706 | 700 | executor->base.execute = _PyUopExecute; | |
| 707 | 701 | memcpy(executor->trace, trace, trace_length * sizeof(_PyUOpInstruction)); | |
| 708 | - if (trace_length < _Py_UOP_MAX_TRACE_LENGTH) { | ||
| 709 | - executor->trace[trace_length].opcode = 0; // Sentinel | ||
| 710 | - } | ||
| 711 | 702 | *exec_ptr = (_PyExecutorObject *)executor; | |
| 712 | 703 | return 1; | |
| 713 | 704 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments