| 288 | |
| 289 | |
| 290 | static PyObject* |
| 291 | NumExpr_getstate(NumExprObject *self) { |
| 292 | // Pickle support |
| 293 | // The NumExprObject struct and its childern is packed into a C-string |
| 294 | // which is then returned as a PyBytes object which is pickleable. |
| 295 | |
| 296 | // Compute total size of self, program, registers, and scalarmem |
| 297 | npy_intp totalSize = sizeof(NumExprObject) + |
| 298 | self->program_len*sizeof(NumExprOperation) + |
| 299 | self->n_reg*sizeof(NumExprReg) + |
| 300 | self->scalar_mem_size; |
| 301 | |
| 302 | |
| 303 | char* state = (char *)malloc(totalSize); |
| 304 | npy_intp statePoint = 0; |
| 305 | |
| 306 | // printf( "TODO: likely PyObject_HEAD should not be overwritten.\n" ); |
| 307 | // Copy top-level NumExprObject |
| 308 | memcpy( state, self, sizeof(NumExprObject) ); |
| 309 | statePoint += sizeof(NumExprObject); |
| 310 | // Copy program |
| 311 | memcpy( state+statePoint, self->program, self->program_len*sizeof(NumExprOperation) ); |
| 312 | statePoint += self->program_len*sizeof(NumExprOperation); |
| 313 | // Copy registers |
| 314 | memcpy( state+statePoint, self->registers, self->n_reg*sizeof(NumExprReg) ); |
| 315 | statePoint += self->n_reg*sizeof(NumExprReg); |
| 316 | // Copy scalar_mem |
| 317 | memcpy( state+statePoint, self->scalar_mem, self->scalar_mem_size ); |
| 318 | |
| 319 | |
| 320 | return PyBytes_FromStringAndSize( state, totalSize ); |
| 321 | } |
| 322 | |
| 323 | static PyObject* |
| 324 | NumExpr_setstate(NumExprObject *self, PyObject *args) { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…