Skip to content

Commit 2f4db59

Browse files
added module specific debug capabilities, controlled by RCPP_DEBUG_MODULE_LEVEL
1 parent 16f62cf commit 2f4db59

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

inst/include/Rcpp/macros/debug.h

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// debug.h: Rcpp R/C++ interface class library -- debug macros
44
//
5-
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
66
//
77
// This file is part of Rcpp.
88
//
@@ -27,6 +27,11 @@
2727
#define RCPP_DEBUG_LEVEL 0
2828
#endif
2929

30+
#ifndef RCPP_DEBUG_MODULE_LEVEL
31+
#define RCPP_DEBUG_MODULE_LEVEL RCPP_DEBUG_LEVEL
32+
#endif
33+
34+
3035
#if RCPP_DEBUG_LEVEL > 0
3136
#define RCPP_DEBUG( MSG ) Rprintf( "%40s:%4d %s\n" , short_file_name(__FILE__), __LINE__, MSG ) ;
3237
#define RCPP_DEBUG_1( fmt, MSG ) Rprintf( "%40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, MSG ) ;
@@ -43,4 +48,62 @@
4348
#define RCPP_DEBUG_5( fmt, M1, M2, M3, M4, M5 )
4449
#endif
4550

51+
#if RCPP_DEBUG_MODULE_LEVEL > 0
52+
#define RCPP_DEBUG_MODULE( MSG ) { \
53+
Rcpp::Module * mod__ = getCurrentScope() ; \
54+
if( mod__ ){ \
55+
Rprintf( "[module (%s) <%p> ] %40s:%4d %s\n" , mod__->name.c_str(), mod__, short_file_name(__FILE__), __LINE__, MSG ) ;\
56+
} else { \
57+
Rprintf( "[module () ] %40s:%4d %s\n" , short_file_name(__FILE__), __LINE__, MSG ) ; \
58+
} \
59+
}
60+
#define RCPP_DEBUG_MODULE_1( fmt, MSG ) { \
61+
Rcpp::Module * mod__ = getCurrentScope() ; \
62+
if( mod__ ){ \
63+
Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, short_file_name(__FILE__), __LINE__, MSG ) ;\
64+
} else { \
65+
Rprintf( "[module () ] %40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, MSG ) ; \
66+
} \
67+
}
68+
#define RCPP_DEBUG_MODULE_2( fmt, M1, M2 ) { \
69+
Rcpp::Module * mod__ = getCurrentScope() ; \
70+
if( mod__ ){ \
71+
Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, short_file_name(__FILE__), __LINE__, M1, M2 ) ;\
72+
} else { \
73+
Rprintf( "[module () ] %40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2 ) ; \
74+
} \
75+
}
76+
#define RCPP_DEBUG_MODULE_3( fmt, M1, M2, M3 ) { \
77+
Rcpp::Module * mod__ = getCurrentScope() ; \
78+
if( mod__ ){ \
79+
Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, short_file_name(__FILE__), __LINE__, M1, M2, M3 ) ;\
80+
} else { \
81+
Rprintf( "[module () ] %40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3 ) ; \
82+
} \
83+
}
84+
#define RCPP_DEBUG_MODULE_4( fmt, M1, M2, M3, M4 ) { \
85+
Rcpp::Module * mod__ = getCurrentScope() ; \
86+
if( mod__ ) { \
87+
Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, short_file_name(__FILE__), __LINE__, M1, M2, M3, M4 ) ;\
88+
} else { \
89+
Rprintf( "[module () ] %40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3, M4 ) ; \
90+
} \
91+
}
92+
#define RCPP_DEBUG_MODULE_5( fmt, M1, M2, M3, M4, M5 ) { \
93+
Rcpp::Module * mod__ = getCurrentScope() ; \
94+
if( mod__ ){ \
95+
Rprintf( "[module (%s) <%p> ] %40s:%4d " fmt "\n" , mod__->name.c_str(), mod__, short_file_name(__FILE__), __LINE__, M1, M2, M3, M4, M5 ) ;\
96+
} else { \
97+
Rprintf( "[module () ] %40s:%4d " fmt "\n" , short_file_name(__FILE__), __LINE__, M1, M2, M3, M4, M5 ) ; \
98+
} \
99+
}
100+
#else
101+
#define RCPP_DEBUG_MODULE( MSG )
102+
#define RCPP_DEBUG_MODULE_1( fmt, MSG )
103+
#define RCPP_DEBUG_MODULE_2( fmt, M1, M2 )
104+
#define RCPP_DEBUG_MODULE_3( fmt, M1, M2, M3 )
105+
#define RCPP_DEBUG_MODULE_4( fmt, M1, M2, M3, M4 )
106+
#define RCPP_DEBUG_MODULE_5( fmt, M1, M2, M3, M4, M5 )
107+
#endif
108+
46109
#endif

inst/include/Rcpp/module/class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230

231231

232232
self& AddMethod( const char* name_, method_class* m, ValidMethod valid = &yes, const char* docstring = 0){
233-
RCPP_DEBUG_1( "AddMethod( %s, method_class* m, ValidMethod valid = &yes, const char* docstring = 0", name_ )
233+
RCPP_DEBUG_MODULE_1( "AddMethod( %s, method_class* m, ValidMethod valid = &yes, const char* docstring = 0", name_ )
234234
self* ptr = get_instance() ;
235235
typename map_vec_signed_method::iterator it = ptr->vec_methods.find( name_ ) ;
236236
if( it == ptr->vec_methods.end() ){
@@ -413,7 +413,7 @@
413413
}
414414

415415
Rcpp::List getMethods( const XP_Class& class_xp, std::string& buffer){
416-
RCPP_DEBUG( "Rcpp::List getMethods( const XP_Class& class_xp, std::string& buffer" )
416+
RCPP_DEBUG_MODULE( "Rcpp::List getMethods( const XP_Class& class_xp, std::string& buffer" )
417417
#if RCPP_DEBUG_LEVEL > 0
418418
Rf_PrintValue( class_xp ) ;
419419
#endif

inst/include/RcppCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define RcppCommon_h
2525

2626
// #define RCPP_DEBUG_LEVEL 1
27+
// #define RCPP_DEBUG_MODULE_LEVEL 1
2728

2829
#include <Rcpp/platform/compiler.h>
2930
#include <Rcpp/config.h>

0 commit comments

Comments
 (0)