From 10d0d9e67d52b1655435cf8e154c13523b9cbef9 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 4 Oct 2014 10:11:59 +0200 Subject: [PATCH] Issue 4152: Eliminate "will never be null" warnings in smobs.tcc Hopefully this will no longer cause spurious warnings with g++ 4.7. --- lily/include/small-smobs.hh | 3 -- lily/include/smobs.hh | 59 ++++++++++++++++++++++--------------- lily/include/smobs.tcc | 27 +++++++++++++---- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/lily/include/small-smobs.hh b/lily/include/small-smobs.hh index a752662c1e..fa63af9a90 100644 --- a/lily/include/small-smobs.hh +++ b/lily/include/small-smobs.hh @@ -32,7 +32,6 @@ public: static SCM make_smob (SCM arg1 = SCM_UNDEFINED) { SCM_RETURN_NEWSMOB (Smob_base::smob_tag (), SCM_UNPACK (arg1)); } - static const int free_smob = 0; SCM mark_smob () { return scm1 (); }; static Super *unchecked_unsmob (SCM s) { return reinterpret_cast (SCM_UNPACK (s)); @@ -53,7 +52,6 @@ public: SCM_UNPACK (arg1), SCM_UNPACK (arg2)); } - static const int free_smob = 0; SCM mark_smob () { scm_gc_mark (scm2 ()); @@ -82,7 +80,6 @@ public: SCM_UNPACK (arg2), SCM_UNPACK (arg3)); } - static const int free_smob = 0; static SCM mark_smob (SCM s) { scm_gc_mark (scm3 ()); diff --git a/lily/include/smobs.hh b/lily/include/smobs.hh index f9eeed7f85..bc4b61d7fd 100644 --- a/lily/include/smobs.hh +++ b/lily/include/smobs.hh @@ -172,25 +172,20 @@ private: // (where it will mask the private template member) rather than // specializing a different template function/pointer. // - // Since we consider those internal-only, two of them are actually - // implemented as literal zero constant. That allows us to fall - // back to GUILE's default implementation. Arguably the same could - // be done for print_smob, but the resulting default output of, say, - // # would depend on memory layout, thus - // being unsuitable for regtest comparisons unless filtered. - - SCM mark_smob (void); // Should not be inline since we do an address - // comparison + // Most default functions are do-nothings. void init() will + // recognize their address when not overriden and will then refrain + // altogether from passing the the respective callbacks to GUILE. + SCM mark_smob (void); static SCM mark_trampoline (SCM); // Used for calling mark_smob - static const int equal_p = 0; - static const int smob_proc = 0; - static const int smob_proc_signature_ = 0; + static size_t free_smob (SCM obj); + static SCM equal_p (SCM, SCM); + + // print_smob is the exception. It is unconditionally passed to + // GUILE since the default output of, say, # + // would depend on memory layout, thus being unsuitable for regtest + // comparisons unless filtered. static int print_smob (SCM, SCM, scm_print_state *); - static size_t free_smob (SCM obj) - { - delete Smob_base::unregister_ptr (obj); - return 0; - } + // type_p_name_ can be overriden in the Super class with a static // const char [] string. This requires both a declaration in the // class as well as a single instantiation outside. Using a @@ -201,12 +196,13 @@ private: // in a single compilation unit. That requires just as much source // code maintenance while being harder to understand and quite // trickier in its failure symptoms when things go wrong. So we - // just do things like with the other specializations. + // just use a static zero as "not here" indication. static const int type_p_name_ = 0; - // This macro is used in the Super class definition for making a - // smob callable like a function. Declaration has to be public. It - // may be either be completed with a semicolon in which case a - // definition of the member function smob_proc has to be done + + // LY_DECLARE_SMOB_PROC is used in the Super class definition for + // making a smob callable like a function. Declaration has to be + // public. It may be either be completed with a semicolon in which + // case a definition of the member function smob_proc has to be done // outside of the class body, or the semicolon is left off and an // inline function body is added immediately below. It would be // nice if this were a non-static member function but it would seem @@ -215,8 +211,15 @@ private: #define LY_DECLARE_SMOB_PROC(REQ, OPT, VAR, ARGLIST) \ static const int smob_proc_signature_ = ((REQ)<<8)|((OPT)<<4)|(VAR); \ static SCM smob_proc ARGLIST + // a separate LY_DEFINE_SMOB_PROC seems sort of pointless as it // would just result in SCM CLASS::smob_proc ARGLIST + // + // The default case without function functionality is recognized by + // smob_proc_signature being -1. + static const int smob_proc = 0; + static const int smob_proc_signature_ = -1; + public: static bool is_smob (SCM s) { @@ -232,10 +235,15 @@ public: } }; - +// Simple smobs template class Simple_smob : public Smob_base { public: + static size_t free_smob (SCM obj) + { + delete Smob_base::unregister_ptr (obj); + return 0; + } SCM smobbed_copy () const { Super *p = new Super(*static_cast (this)); @@ -252,6 +260,11 @@ private: SCM self_scm_; SCM protection_cons_; public: + static size_t free_smob (SCM obj) + { + delete Smob_base::unregister_ptr (obj); + return 0; + } SCM unprotected_smobify_self () { self_scm_ = SCM_UNDEFINED; diff --git a/lily/include/smobs.tcc b/lily/include/smobs.tcc index eaec076de3..f927d481d4 100644 --- a/lily/include/smobs.tcc +++ b/lily/include/smobs.tcc @@ -49,7 +49,7 @@ Smob_base::register_ptr (Super *p) return s; } -// Default, should not actually get called +// Defaults, should not actually get called template SCM Smob_base::mark_smob () @@ -57,6 +57,22 @@ Smob_base::mark_smob () return SCM_UNSPECIFIED; } +template +size_t +Smob_base::free_smob (SCM) +{ + return 0; +} + +template +SCM +Smob_base::equal_p (SCM, SCM) +{ + return SCM_BOOL_F; +} + +// Default, will often get called + template int Smob_base::print_smob (SCM, SCM p, scm_print_state *) @@ -103,13 +119,12 @@ void Smob_base::init () // While that's not a consideration for type_p_name_, it's easier // doing it like the rest. - if (Super::free_smob != 0) + if (&Super::free_smob != &Smob_base::free_smob) scm_set_smob_free (smob_tag_, Super::free_smob); if (&Super::mark_smob != &Smob_base::mark_smob) scm_set_smob_mark (smob_tag_, Super::mark_trampoline); - if (Super::print_smob != 0) - scm_set_smob_print (smob_tag_, Super::print_smob); - if (Super::equal_p != 0) + scm_set_smob_print (smob_tag_, Super::print_smob); + if (&Super::equal_p != &Smob_base::equal_p) scm_set_smob_equalp (smob_tag_, Super::equal_p); if (Super::type_p_name_ != 0) { @@ -122,7 +137,7 @@ void Smob_base::init () scm_c_export (Super::type_p_name_, NULL); } ly_add_type_predicate ((void *) is_smob, smob_name_.c_str ()); - if (Super::smob_proc != 0) + if (Super::smob_proc_signature_ >= 0) scm_set_smob_apply (smob_tag_, (scm_t_subr)Super::smob_proc, Super::smob_proc_signature_ >> 8, -- 2.39.2