diff options
author | Kevin Cheng <kevcheng@google.com> | 2019-04-18 11:31:16 -0700 |
---|---|---|
committer | Kevin Cheng <kevcheng@google.com> | 2019-05-02 13:59:40 -0700 |
commit | 757c264bc10ebc71074ee3f5fb66d670667a09bc (patch) | |
tree | 26c7f7b74c752db99d9b0ac1f94fc592aca1e53a /demo/gmp.py | |
parent | 99013222844839c42437f16eace25f4e6a8a8b20 (diff) | |
download | cffi-757c264bc10ebc71074ee3f5fb66d670667a09bc.tar.gz |
Add in cffi 1.12.2 (e0c7666)
Since this is a mercurial repo, d/led zip of src:
https://bitbucket.org/cffi/cffi/get/v1.12.2.zip
Also add in misc METADATA/NOTICE/Android.bp/etc files.
Bug: 122778810
Test: None
Change-Id: I36c58ed07a2cdd4d9d11831908175a5c988f33c1
Diffstat (limited to 'demo/gmp.py')
-rw-r--r-- | demo/gmp.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/demo/gmp.py b/demo/gmp.py new file mode 100644 index 0000000..44f233c --- /dev/null +++ b/demo/gmp.py @@ -0,0 +1,33 @@ +import sys +# +# This is only a demo based on the GMP library. +# There is a rather more complete (but perhaps outdated) version available at: +# http://bazaar.launchpad.net/~tolot-solar-empire/+junk/gmpy_cffi/files +# + +try: + from _gmp_cffi import ffi, lib +except ImportError: + print 'run gmp_build first, then make sure the shared object is on sys.path' + sys.exit(1) + +# ffi "knows" about the declared variables and functions from the +# cdef parts of the module created from gmp_build +# lib "knows" how to call the functions from the set_source parts +# of the module. + +# ____________________________________________________________ + +a = ffi.new("mpz_t") +b = ffi.new("mpz_t") + +if len(sys.argv) < 3: + print 'call as %s bigint1, bigint2' % sys.argv[0] + sys.exit(2) + +lib.mpz_init_set_str(a, sys.argv[1], 10) # Assume decimal integers +lib.mpz_init_set_str(b, sys.argv[2], 10) # Assume decimal integers +lib.mpz_add(a, a, b) # a=a+b + +s = lib.mpz_get_str(ffi.NULL, 10, a) +print ffi.string(s) |