MCPcopy Index your code
hub / github.com/python/cpython / verify_structure

Function verify_structure

Lib/test/test_buffer.py:455–479  ·  view source on GitHub ↗

Verify that the parameters represent a valid array within the bounds of the allocated memory: char *mem: start of the physical memory block memlen: length of the physical memory block offset: (char *)buf - mem

(memlen, itemsize, ndim, shape, strides, offset)

Source from the content-addressed store, hash-verified

453#
454
455def verify_structure(memlen, itemsize, ndim, shape, strides, offset):
456 """Verify that the parameters represent a valid array within
457 the bounds of the allocated memory:
458 char *mem: start of the physical memory block
459 memlen: length of the physical memory block
460 offset: (char *)buf - mem
461 """
462 if offset % itemsize:
463 return False
464 if offset < 0 or offset+itemsize > memlen:
465 return False
466 if any(v % itemsize for v in strides):
467 return False
468
469 if ndim <= 0:
470 return ndim == 0 and not shape and not strides
471 if 0 in shape:
472 return True
473
474 imin = sum(strides[j]*(shape[j]-1) for j in range(ndim)
475 if strides[j] <= 0)
476 imax = sum(strides[j]*(shape[j]-1) for j in range(ndim)
477 if strides[j] > 0)
478
479 return 0 <= offset+imin and offset+imax+itemsize <= memlen
480
481def get_item(lst, indices):
482 for i in indices:

Calls 1

anyFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…