Author: Wim Lavrijsen <wlavrij...@lbl.gov> Branch: cling-support Changeset: r85671:7e5b01d3cab2 Date: 2016-07-12 11:40 -0700 http://bitbucket.org/pypy/pypy/changeset/7e5b01d3cab2/
Log: simpler template handling diff --git a/pypy/module/cppyy/capi/builtin_capi.py b/pypy/module/cppyy/capi/builtin_capi.py --- a/pypy/module/cppyy/capi/builtin_capi.py +++ b/pypy/module/cppyy/capi/builtin_capi.py @@ -53,13 +53,6 @@ compilation_info=backend.eci) def c_get_scope_opaque(space, name): return _c_get_scope_opaque(name) -_c_get_template = rffi.llexternal( - "cppyy_get_template", - [rffi.CCHARP], C_TYPE, - releasegil=ts_reflect, - compilation_info=backend.eci) -def c_get_template(space, name): - return _c_get_template(name) _c_actual_class = rffi.llexternal( "cppyy_actual_class", [C_TYPE, C_OBJECT], C_TYPE, @@ -238,6 +231,13 @@ compilation_info=backend.eci) def c_is_namespace(space, scope): return _c_is_namespace(scope) +_c_is_template = rffi.llexternal( + "cppyy_is_template", + [rffi.CCHARP], rffi.INT, + releasegil=ts_reflect, + compilation_info=backend.eci) +def c_is_template(space, name): + return _c_is_template(name) _c_is_abstract = rffi.llexternal( "cppyy_is_abstract", [C_SCOPE], rffi.INT, diff --git a/pypy/module/cppyy/capi/loadable_capi.py b/pypy/module/cppyy/capi/loadable_capi.py --- a/pypy/module/cppyy/capi/loadable_capi.py +++ b/pypy/module/cppyy/capi/loadable_capi.py @@ -126,7 +126,6 @@ 'resolve_name' : ([c_ccharp], c_ccharp), 'get_scope' : ([c_ccharp], c_scope), - 'get_template' : ([c_ccharp], c_type), 'actual_class' : ([c_type, c_object], c_type), # memory management @@ -162,6 +161,7 @@ # scope reflection information 'is_namespace' : ([c_scope], c_int), + 'is_template' : ([c_ccharp], c_int), 'is_abstract' : ([c_type], c_int), 'is_enum' : ([c_ccharp], c_int), @@ -291,8 +291,6 @@ return charp2str_free(space, call_capi(space, 'resolve_name', [_Arg(s=name)])) def c_get_scope_opaque(space, name): return rffi.cast(C_SCOPE, space.uint_w(call_capi(space, 'get_scope', [_Arg(s=name)]))) -def c_get_template(space, name): - return rffi.cast(C_TYPE, space.uint_w(call_capi(space, 'get_template', [_Arg(s=name)]))) def c_actual_class(space, cppclass, cppobj): args = [_Arg(h=cppclass.handle), _Arg(h=cppobj)] return rffi.cast(C_TYPE, space.uint_w(call_capi(space, 'actual_class', args))) @@ -368,6 +366,8 @@ # scope reflection information ----------------------------------------------- def c_is_namespace(space, scope): return space.bool_w(call_capi(space, 'is_namespace', [_Arg(h=scope)])) +def c_is_template(space, name): + return space.bool_w(call_capi(space, 'is_template', [_Arg(s=name)])) def c_is_abstract(space, scope): return space.bool_w(call_capi(space, 'is_abstract', [_Arg(h=cpptype)])) def c_is_enum(space, name): diff --git a/pypy/module/cppyy/include/capi.h b/pypy/module/cppyy/include/capi.h --- a/pypy/module/cppyy/include/capi.h +++ b/pypy/module/cppyy/include/capi.h @@ -26,8 +26,6 @@ RPY_EXTERN cppyy_scope_t cppyy_get_scope(const char* scope_name); RPY_EXTERN - cppyy_type_t cppyy_get_template(const char* template_name); - RPY_EXTERN cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj); /* memory management ------------------------------------------------------ */ @@ -85,6 +83,8 @@ RPY_EXTERN int cppyy_is_namespace(cppyy_scope_t scope); RPY_EXTERN + int cppyy_is_template(const char* template_name); + RPY_EXTERN int cppyy_is_abstract(cppyy_type_t type); RPY_EXTERN int cppyy_is_enum(const char* type_name); diff --git a/pypy/module/cppyy/include/cpp_cppyy.h b/pypy/module/cppyy/include/cpp_cppyy.h --- a/pypy/module/cppyy/include/cpp_cppyy.h +++ b/pypy/module/cppyy/include/cpp_cppyy.h @@ -6,21 +6,21 @@ #include <vector> #include <stddef.h> -//ROOT types - typedef long Long_t; - typedef unsigned long ULong_t; - typedef long long Long64_t; - typedef unsigned long long ULong64_t; - typedef float Float_t; - typedef double Double_t; - typedef long double LongDouble_t; - typedef bool Bool_t; - typedef char Char_t; - typedef unsigned char UChar_t; - typedef short Short_t; - typedef unsigned short UShort_t; - typedef int Int_t; - typedef unsigned int UInt_t; +// ROOT types +typedef long Long_t; +typedef unsigned long ULong_t; +typedef long long Long64_t; +typedef unsigned long long ULong64_t; +typedef float Float_t; +typedef double Double_t; +typedef long double LongDouble_t; +typedef bool Bool_t; +typedef char Char_t; +typedef unsigned char UChar_t; +typedef short Short_t; +typedef unsigned short UShort_t; +typedef int Int_t; +typedef unsigned int UInt_t; namespace Cppyy { typedef ptrdiff_t TCppScope_t; @@ -36,7 +36,6 @@ std::string GetScopeName( TCppScope_t parent, TCppIndex_t iscope ); std::string ResolveName( const std::string& cppitem_name ); TCppScope_t GetScope( const std::string& scope_name ); - TCppType_t GetTemplate( const std::string& template_name ); TCppType_t GetActualClass( TCppType_t klass, TCppObject_t obj ); size_t SizeOf( TCppType_t klass ); @@ -78,6 +77,7 @@ // scope reflection information ---------------------------------------------- Bool_t IsNamespace( TCppScope_t scope ); + Bool_t IsTemplate( const std::string& template_name ); Bool_t IsAbstract( TCppType_t type ); Bool_t IsEnum( const std::string& type_name ); 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 @@ -103,10 +103,8 @@ except KeyError: pass - opaque_handle = capi.c_get_template(space, name) - assert lltype.typeOf(opaque_handle) == capi.C_TYPE - if opaque_handle: - cpptemplate = W_CPPTemplateType(space, name, opaque_handle) + if capi.c_is_template(space, name): + cpptemplate = W_CPPTemplateType(space, name) state.cpptemplate_cache[name] = cpptemplate return cpptemplate @@ -997,14 +995,12 @@ class W_CPPTemplateType(W_Root): - _attrs_ = ['space', 'name', 'handle'] - _immutable_fields = ['name', 'handle'] + _attrs_ = ['space', 'name'] + _immutable_fields = ['name'] - def __init__(self, space, name, opaque_handle): + def __init__(self, space, name): self.space = space self.name = name - assert lltype.typeOf(opaque_handle) == capi.C_TYPE - self.handle = opaque_handle @unwrap_spec(args_w='args_w') def __call__(self, args_w): 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 @@ -178,9 +178,9 @@ return (TCppScope_t)sz; } -Cppyy::TCppType_t Cppyy::GetTemplate( const std::string& /* template_name */ ) +Bool_t Cppyy::IsTemplate( const std::string& template_name ) { - return (TCppType_t)0; + return (Bool_t)gInterpreter->CheckClassTemplate( template_name.c_str() ); } Cppyy::TCppType_t Cppyy::GetActualClass( TCppType_t klass, TCppObject_t obj ) @@ -1082,10 +1082,6 @@ return cppyy_scope_t(Cppyy::GetScope(scope_name)); } -cppyy_type_t cppyy_get_template(const char* template_name) { - return cppyy_type_t(Cppyy::GetTemplate(template_name)); -} - cppyy_type_t cppyy_actual_class(cppyy_type_t klass, cppyy_object_t obj) { return cppyy_type_t(Cppyy::GetActualClass(klass, (void*)obj)); } @@ -1200,6 +1196,10 @@ return (int)Cppyy::IsNamespace(scope); } +int cppyy_is_template(const char* template_name) { + return (int)Cppyy::IsTemplate(template_name); +} + int cppyy_is_abstract(cppyy_type_t type){ return (int)Cppyy::IsAbstract(type); } _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit