Skip to content

Commit

Permalink
Revert "vararg: iString::Format()"
Browse files Browse the repository at this point in the history
Apple's llvm-gcc's support for C++ is incomplete. It throws an error
upon encountering a virtual vararg method in a virtual base class. The
implemented work-around for this problem is to #ifdef-out the offending
methods and instead have clients invoke the va_list counterpart of the
vararg method via CS::va_call(). This approach, however, is somewhat
maintenance heavy and just plain ugly. A more maintainable and less
invasive work-around is instead to implement the vararg methods as thin
inline non-virtual wrappers which delegate to the va_list counterparts
automatically.  In preparation for this revised solution, revert the
CS::va_call() approach.
  • Loading branch information
sunshine committed Jul 18, 2012
1 parent 10a3383 commit 7d81051
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 12 deletions.
3 changes: 0 additions & 3 deletions include/csutil/scfstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,11 @@ class CS_CRYSTALSPACE_EXPORT scfString :
*/
virtual void ReplaceAll (const char* search, const char* replacement);

#ifndef CS_VIRTUAL_BASE_VARARG_BROKEN
/**
* Format.
* \sa \ref FormatterNotes
*/
virtual void Format (const char* format, ...) CS_GNUC_PRINTF (2, 3);
#endif

/**
* Format.
* \sa \ref FormatterNotes
Expand Down
2 changes: 0 additions & 2 deletions include/iutil/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,13 @@ struct iString : public virtual iBase
*/
virtual void ReplaceAll (const char* search, const char* replacement) = 0;

#ifndef CS_VIRTUAL_BASE_VARARG_BROKEN
/**
* Format this string using sprintf()-style formatting directives.
* \remarks Automatically allocates sufficient memory to hold result. Newly
* formatted string replaces previous string value.
* \sa \ref FormatterNotes
*/
virtual void Format (const char* format, ...) CS_GNUC_PRINTF (2, 3) = 0;
#endif

/**
* Format this string using sprintf() formatting directives in a va_list.
Expand Down
2 changes: 0 additions & 2 deletions libs/csutil/scfstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,13 @@ size_t scfString::Find (const char* t, size_t p) const
void scfString::ReplaceAll (const char* search, const char* replacement)
{ s.ReplaceAll(search, replacement); }

#ifndef CS_VIRTUAL_BASE_VARARG_BROKEN
void scfString::Format (const char* format, ...)
{
va_list args;
va_start (args, format);
FormatV (format, args);
va_end (args);
}
#endif

void scfString::FormatV (const char* format, va_list args)
{ s.FormatV (format, args); }
Expand Down
3 changes: 1 addition & 2 deletions plugins/culling/dynavis/dynavis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "csutil/event.h"
#include "csutil/eventnames.h"
#include "csutil/stringquote.h"
#include "csutil/vararg.h"
#include "iutil/event.h"
#include "iutil/eventq.h"
#include "csgeom/frustum.h"
Expand Down Expand Up @@ -145,7 +144,7 @@ class csDynaVisObjectDescriptor : public scfImplementation1<
const csBox3& b = child->GetBBox ();
csVisibilityObjectWrapper* obj = (csVisibilityObjectWrapper*)(
child->GetObject ());
CS::va_callv(&iString::FormatV, (iString*)str, "%s (%g,%g,%g)-(%g,%g,%g)",
str->Format ("%s (%g,%g,%g)-(%g,%g,%g)",
CS::Quote::Single (obj->mesh->QueryObject ()->GetName ()),
b.MinX (), b.MinY (), b.MinZ (),
b.MaxX (), b.MaxY (), b.MaxZ ());
Expand Down
3 changes: 1 addition & 2 deletions plugins/culling/frustvis/frustvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "csutil/event.h"
#include "csutil/eventnames.h"
#include "csutil/stringquote.h"
#include "csutil/vararg.h"
#include "iutil/event.h"
#include "iutil/eventq.h"
#include "csgeom/frustum.h"
Expand Down Expand Up @@ -135,7 +134,7 @@ class csFrustVisObjectDescriptor : public scfImplementation1<
const csBox3& b = child->GetBBox ();
csFrustVisObjectWrapper* obj = (csFrustVisObjectWrapper*)(
child->GetObject ());
CS::va_callv(&iString::FormatV, (iString*)str, "%s (%g,%g,%g)-(%g,%g,%g)",
str->Format ("%s (%g,%g,%g)-(%g,%g,%g)",
CS::Quote::Single (obj->mesh->QueryObject ()->GetName ()),
b.MinX (), b.MinY (), b.MinZ (),
b.MaxX (), b.MaxY (), b.MaxZ ());
Expand Down
2 changes: 1 addition & 1 deletion plugins/utilities/colladaconvertor/csColladaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ CS_PLUGIN_NAMESPACE_BEGIN (ColladaConvertor)

/// @todo: Add normal information here.
/* WRITE OUT VERTICES */
csString formatter;
scfString formatter;

// positions
currentCrystalVElement = currentCrystalParamsElement->CreateNodeBefore(CS_NODE_ELEMENT);
Expand Down

0 comments on commit 7d81051

Please sign in to comment.