Archive for September, 2009

Painters and @Decorators?

Tuesday, 29 September 2009

Python Decorator Library

Includes:

Memoize
[Pseudo-]Currying
Pre-/Post-conditions
Type Enforcement

Memory Leaks

Tuesday, 29 September 2009

To check for possible memory leaks using MSVC:
_CrtDumpMemoryLeaks()

Custom Comments in XML

Friday, 25 September 2009

Imagine you’re using an XML parser to read in files, editing them, and then using an XML formatter to write the files, and that the XML style <!– comments –> are not preserved. If the editing process preserves all elements and attributes, however, even those that are not expected, then that might be exploited to provide custom comments.

Thus, rather than writing this:

<element field="value">
  <!-- comment text -->
</element>

you could write this:

<element field="value">
  <comment>comment text</comment>
</element>

or this:

<element comment="comment text" field="value"/>

Furthermore, note that if the order of sibling elements is not preserved (perhaps the elements are being deliberately sorted), then the comment will have to be a child (not a sibling) of the associated element.

C/C++ Pre-processor Links

Friday, 25 September 2009

Some handy, partly Mi¢ro$oft/MSVC-specific, C/C++ pre-processor  links:

MS Visual C++ Pre-#defined Macros

MS Visual C++ #pragma Directives

Heads or Tails?

Friday, 25 September 2009

It is well written about that a tossed coin has no ‘memory’; that the outcome of a given toss of the coin is independent of previous ones.

So, following ten heads in a row, the probability of another head (assuming that a fair coin is used) is still 50%.

(Perhaps the probability of another head is more than 50%: a run of heads might indicate a bias on the coin.)

The fact that many people hold the misconception that coins do have such a memory can be exploited for financial gain. This is the basis on which some professional gamblers, ‘working’ the casinos, acquire their income: they do not bet with the casino itself, but with other customers about their bets with the casinos, exploiting superstitions and misplaced intuitions.

STL Design Problem?

Thursday, 24 September 2009

Consider the following functions:

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/date_facet.hpp>
#include <clocale>

std::string format_date_crash (::boost::gregorian::date dt)
{
  std::locale locale_local ("");

  ::boost::gregorian::date_facet date_output;
  std::locale locale_adjusted (locale_local, &date_output);

  std::ostringstream date_ss;
  date_ss.imbue (locale_adjusted);

  p_date_output.format("%x");
  date_ss << dt;

  return date_ss.str();
}

std::string format_date_leakquery (::boost::gregorian::date dt)
{
  std::locale locale_local ("");

  ::boost::gregorian::date_facet * p_date_output
      = new ::boost::gregorian::date_facet;
  std::locale locale_adjusted (locale_local, p_date_output);

  std::ostringstream date_ss;
  date_ss.imbue (locale_adjusted);

  (*p_date_output).format("%x");
  date_ss << dt;

  // *** don't delete p_date_output ***
  return date_ss.str();
}

Here, I have used Boost too, but I don't believe that the problem is in Boost.

Calls to format_date_crash() crash in the ~std::locale() destructor [oddly, I found that it crashes only on the second call].

On the other hand format_date_leakquery() looks as though it might leak: it has a new without a corresponding delete. However a test showed that it does not leak.

It seems that the std::locale constructor takes ownership of the facet, so that when the locale object is destroyed, so is the facet (ie. the facet is deleted).

Is this an instance of poor design in the STL, or is there some compelling reason that things are arranged this way?

XSLT seems to be broken in Firefox 3…

Friday, 18 September 2009

… but it isn’t really. If you are having this problem, it might just be that the path to the style-sheet is either an absolute path or a relative path upwards.

It might be that Firefox 3 is blocking access outside the current directory. That is a security feature, and as such is worth having. If you can, move the XSLT style-sheet into or below the directory of the XML file using it.

Alternatively, you might opt to disable this security setting, and return to the Firefox 2 behaviour in this respect:

  • type “about:config” into the address bar
  • change the value of “security.fileuri.strict_origin_policy” to “false”

This information is from mozillaZine.

Bugzilla trick: Static Bug List URLs.

Monday, 14 September 2009

There is a simple although round-about way to produce a Bugzilla query with an explicit list of bugs numbers.

(more…)

Notes on Merging using SVN and T-SVN

Thursday, 10 September 2009

In trying to provide some help on merging with SVN, especially with the new “mergeinfo” functionality, I discovered a number of things that anyone doing branching and merging with SVN (Subversion) or T-SVN (TortoiseSVN) should know.
(more…)


Follow

Get every new post delivered to your Inbox.