Skip to content

Instantly share code, notes, and snippets.

@nhoad
Created February 3, 2016 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhoad/0ac87132031a6c599c9e to your computer and use it in GitHub Desktop.
Save nhoad/0ac87132031a6c599c9e to your computer and use it in GitHub Desktop.
CPyCPy
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
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