[pypy-svn] r45983 - in pypy/branch/pypy-more-rtti-inprogress/rpython/tool: . test
fijal at codespeak.net
fijal at codespeak.net
Sat Aug 25 15:58:38 CEST 2007
Author: fijal
Date: Sat Aug 25 15:58:38 2007
New Revision: 45983
Modified:
pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rfficache.py
pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rfficache.py
Log:
Add platform.has('xxx')
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rfficache.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rfficache.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/tool/rfficache.py Sat Aug 25 15:58:38 2007
@@ -5,6 +5,7 @@
import py
import os
+import distutils
from pypy.translator.tool.cbuild import build_executable
from pypy.tool.udir import udir
from pypy.tool.autopath import pypydir
@@ -60,6 +61,16 @@
question = 'printf("%%d", %s);' % (c_def,)
return int(ask_gcc(question, **kwds))
+def have_c_obj(c_obj, **kwds):
+ question = c_obj + ';'
+ try:
+ ask_gcc(question, **kwds)
+ return True
+ except distutils.errors.CompileError:
+ # parsing errors here and trying to deduce whether
+ # it's this or not sounds like an overkill
+ return False
+
def create_cache_access_method(acc_func, meth_name):
def method(self, name, **kwds):
try:
@@ -116,6 +127,7 @@
defined = create_cache_access_method(c_ifdefined, 'defined')
intdefined = create_cache_access_method(c_defined_int, 'intdefined')
sizeof = create_cache_access_method(sizeof_c_type, 'sizeof')
+ has = create_cache_access_method(have_c_obj, 'has')
# optimal way of caching it, would be to store file on __del__,
# but since we cannot rely on __del__ having all modules, let's
Modified: pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rfficache.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rfficache.py (original)
+++ pypy/branch/pypy-more-rtti-inprogress/rpython/tool/test/test_rfficache.py Sat Aug 25 15:58:38 2007
@@ -14,6 +14,10 @@
def test_c_defined_int():
assert c_defined_int('X', add_source='#define X 3') == 3
+def test_c_existing_symbol():
+ assert have_c_obj('X', add_source='int X(int, int, int);')
+ assert not have_c_obj('xxx')
+
def test_rfficache():
cache = RffiCache(udir.join('cache.py'))
assert cache.inttype('uchar', 'unsigned char', False)._type.BITS == 8
@@ -38,3 +42,4 @@
name = name.replace(' ', '')
assert hasattr(rffi, 'r_' + name)
assert hasattr(rffi, name.upper())
+
More information about the Pypy-commit
mailing list