aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2013-10-12 11:58:43 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2013-10-12 12:15:17 -0500
commit01e3201cab97d9af98a9c7090436ec05db56d4a2 (patch)
tree61fcbc1005cafb61d92fda6b82e6d84f9210555f
parent5dd35ab0a3edf924e84afc65d0eebe8a80bfb17b (diff)
downloadcryptography-01e3201cab97d9af98a9c7090436ec05db56d4a2.tar.gz
cryptography-01e3201cab97d9af98a9c7090436ec05db56d4a2.tar.bz2
cryptography-01e3201cab97d9af98a9c7090436ec05db56d4a2.zip
Load types from all cffi modules before declaring functions or macros
This change loads all the types via cdef & then loops over the macros & functions and cdefs them. The advantage of this approach is that you can define the types in the right modules without worrying about import order. For example, if you need the BIO typedef in the asn1 module but it is defined in the bio module you can still import the modules alphabetically and expect that BIO will be properly declared.
-rw-r--r--cryptography/bindings/openssl/api.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py
index 129605f3..f7e14c10 100644
--- a/cryptography/bindings/openssl/api.py
+++ b/cryptography/bindings/openssl/api.py
@@ -17,6 +17,8 @@ import sys
import cffi
+import six
+
from cryptography.primitives import interfaces
@@ -41,16 +43,23 @@ class API(object):
self.ffi = cffi.FFI()
includes = []
functions = []
+ macros = []
for name in self._modules:
__import__("cryptography.bindings.openssl." + name)
module = sys.modules["cryptography.bindings.openssl." + name]
self.ffi.cdef(module.TYPES)
- self.ffi.cdef(module.FUNCTIONS)
- self.ffi.cdef(module.MACROS)
+ macros.append(module.MACROS)
functions.append(module.FUNCTIONS)
includes.append(module.INCLUDES)
+ # loop over the functions & macros after declaring all the types
+ # so we can set interdependent types in different files and still
+ # have them all defined before we parse the funcs & macros
+ for func, macro in six.moves.zip(functions, macros):
+ self.ffi.cdef(func)
+ self.ffi.cdef(macro)
+
# We include functions here so that if we got any of their definitions
# wrong, the underlying C compiler will explode. In C you are allowed
# to re-declare a function if it has the same signature. That is: