MCPcopy Create free account
hub / github.com/pydata/numexpr / NumExpr_getstate

Function NumExpr_getstate

numexpr3/numexpr_object.cpp:290–321  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288
289
290static PyObject*
291NumExpr_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
323static PyObject*
324NumExpr_setstate(NumExprObject *self, PyObject *args) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…