[pypy-commit] cffi default: Small tweaks
arigo
noreply at buildbot.pypy.org
Sun Nov 10 09:19:14 CET 2013
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r1406:1352b9a24203
Date: 2013-11-10 08:59 +0100
http://bitbucket.org/cffi/cffi/changeset/1352b9a24203/
Log: Small tweaks
diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -129,11 +129,9 @@
cdecl = cdecl.encode('ascii')
#
type = self._parser.parse_type(cdecl)
- if hasattr(type, 'as_function_pointer'):
- really_a_function_type = True
+ really_a_function_type = type.is_raw_function
+ if really_a_function_type:
type = type.as_function_pointer()
- else:
- really_a_function_type = False
btype = self._get_cached_btype(type)
result = btype, really_a_function_type
self._parsed_types[key] = result
diff --git a/cffi/model.py b/cffi/model.py
--- a/cffi/model.py
+++ b/cffi/model.py
@@ -2,6 +2,7 @@
class BaseTypeByIdentity(object):
is_array_type = False
+ is_raw_function = False
def get_c_name(self, replace_with='', context='a C file'):
result = self.c_name_with_marker
@@ -146,6 +147,7 @@
# a function, but not a pointer-to-function. The backend has no
# notion of such a type; it's used temporarily by parsing.
_base_pattern = '(&)(%s)'
+ is_raw_function = True
def build_backend_type(self, ffi, finishlist):
from . import api
@@ -212,8 +214,10 @@
self.item = item
self.length = length
#
- if length is None or length == '...':
+ if length is None:
brackets = '&[]'
+ elif length == '...':
+ brackets = '&[/*...*/]'
else:
brackets = '&[%d]' % length
self.c_name_with_marker = (
@@ -449,6 +453,7 @@
return NamedPointerType(tp, name)
def global_cache(srctype, ffi, funcname, *args, **kwds):
+ # NB. multithread: careful code that should work without an explicit lock
key = kwds.pop('key', (funcname, args))
assert not kwds
try:
@@ -468,8 +473,7 @@
res = getattr(ffi._backend, funcname)(*args)
except NotImplementedError as e:
raise NotImplementedError("%r: %s" % (srctype, e))
- ffi._backend.__typecache[key] = res
- return res
+ return ffi._backend.__typecache.setdefault(key, res)
def pointer_cache(ffi, BType):
return global_cache('?', ffi, 'new_pointer_type', BType)
More information about the pypy-commit
mailing list