Created
March 27, 2014 19:18
-
-
Save jkbbwr/9815846 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tuplecpy(dst, src, begin_offset): | |
""" | |
Of course this function should NEVER be used in real code | |
It will probably result in segfaults/crashes | |
- copy tuple(src) to dst[begin_offset:] tuple | |
- remember id(x) -> addressof(x) | |
""" | |
OFFSET = ctypes.sizeof(ctypes.c_size_t) * 3 | |
PTR_SIZE = ctypes.sizeof(ctypes.c_size_t) | |
dst_addr = id(dst) + OFFSET + PTR_SIZE * begin_offset | |
src_addr = id(src) + OFFSET | |
ctypes.memmove(dst_addr, src_addr, len(src) * PTR_SIZE) | |
def x2(x): | |
return x * 2 | |
print x2(4) | |
# Orly? | |
tuplecpy(x2.func_code.co_consts, (None, 10), 0) | |
print x2(4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment