Author: Wim Lavrijsen <[email protected]>
Branch: cling-support
Changeset: r86367:b0a2d7ad8562
Date: 2016-08-20 22:30 -0700
http://bitbucket.org/pypy/pypy/changeset/b0a2d7ad8562/
Log: capitulate on __dir__ for now
diff --git a/pypy/module/cppyy/interp_cppyy.py
b/pypy/module/cppyy/interp_cppyy.py
--- a/pypy/module/cppyy/interp_cppyy.py
+++ b/pypy/module/cppyy/interp_cppyy.py
@@ -832,13 +832,7 @@
return datamember
def _find_datamembers(self):
- num_datamembers = capi.c_num_datamembers(self.space, self)
- for i in range(num_datamembers):
- if not capi.c_is_publicdata(self.space, self, i):
- continue
- datamember_name = capi.c_datamember_name(self.space, self, i)
- if not datamember_name in self.datamembers:
- self._make_datamember(datamember_name, i)
+ pass # force lazy lookups in namespaces
def find_overload(self, meth_name):
indices = capi.c_method_indices_from_name(self.space, self, meth_name)
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx
b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -132,7 +132,19 @@
Cppyy::TCppIndex_t Cppyy::GetNumScopes( TCppScope_t scope )
{
TClassRef& cr = type_from_handle( scope );
- if ( cr.GetClass() ) return 0; // not supported if not at global scope
+ if ( cr.GetClass() ) {
+ // this is expensive, but this function is only ever called for __dir__
+ // TODO: rewrite __dir__ on the C++ side for a single loop
+ std::string s = GetFinalName( scope ); s += "::";
+ gClassTable->Init();
+ const int N = gClassTable->Classes();
+ int total = 0;
+ for ( int i = 0; i < N; ++i ) {
+ if ( strncmp( gClassTable->Next(), s.c_str(), s.size() ) == 0 )
+ total += 1;
+ }
+ return total;
+ }
assert( scope == (TCppScope_t)GLOBAL_HANDLE );
return gClassTable->Classes();
}
@@ -141,7 +153,22 @@
{
// Retrieve the scope name of the scope indexed with iscope in parent.
TClassRef& cr = type_from_handle( parent );
- if ( cr.GetClass() ) return 0; // not supported if not at global scope
+ if ( cr.GetClass() ) {
+ // this is expensive (quadratic in number of classes), but only ever called
for __dir__
+ // TODO: rewrite __dir__ on the C++ side for a single loop
+ std::string s = GetFinalName( parent ); s += "::";
+ gClassTable->Init();
+ const int N = gClassTable->Classes();
+ int match = 0;
+ for ( int i = 0; i < N; ++i ) {
+ char* cname = gClassTable->Next();
+ if ( strncmp( cname, s.c_str(), s.size() ) == 0 && match++ ==
iscope ) {
+ std::string ret( cname+ s.size() );
+ return ret.substr(0, ret.find( "::" ) ); // TODO: may mean
duplicates
+ }
+ }
+ // should never get here ... fall through will fail on assert below
+ }
assert( parent == (TCppScope_t)GLOBAL_HANDLE );
std::string name = gClassTable->At( iscope );
if ( name.find("::") == std::string::npos )
diff --git a/pypy/module/cppyy/test/test_fragile.py
b/pypy/module/cppyy/test/test_fragile.py
--- a/pypy/module/cppyy/test/test_fragile.py
+++ b/pypy/module/cppyy/test/test_fragile.py
@@ -228,8 +228,10 @@
assert 'nested1' in members # namespace
- assert 'fglobal' in members # function
- assert 'gI'in members # variable
+ # TODO: think this through ... probably want this, but interferes with
+ # the (new) policy of lazy lookups
+ #assert 'fglobal' in members # function
+ #assert 'gI'in members # variable
def test12_imports(self):
"""Test ability to import from namespace (or fail with ImportError)"""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit