Created
February 3, 2016 07:55
-
-
Save nhoad/0ac87132031a6c599c9e to your computer and use it in GitHub Desktop.
CPyCPy
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
import cffi | |
ffi = cffi.FFI() | |
ffi.cdef('int PyDict_DelItemString(void *, const char *key);') | |
lib = ffi.dlopen('libpython3.so') | |
d = {'foo': 'bar'} | |
print('before', d) | |
d_p = ffi.cast('void*', id(d)) | |
lib.PyDict_DelItemString(d_p, ffi.new('char[]', b'foo')) | |
print('after', d) | |
assert 'foo' not in d |
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
nathan@xxxxxx ~ $ python cpycpy.py | |
before {'foo': 'bar'} | |
after {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment