Thursday, 11 November 2010

Sneaky use of sequence points in c++

1 comments
i've found a very interesting corner case where fiddly knowledge of
sequence points and STL are used.
apparently it's not possible to use remove_if on associate arrays but
this didn't stop me trying for a good 30 mins before i discovered this
workaround:

for(; iter != endIter; )
{
if(Some Condition)
{
// is it safe ?
aMap.erase(iter++);
}
else
{
++iter;
}
}


There's no evidence in the answer, but it's apparent after digging
through the numerous overloads and associated nastiness that its
apparently excusable simplicity comes down to sneaky use of sequence
points.

http://www.cplusplus.com/reference/algorithm/remove_if/
http://stackoverflow.com/questions/800955/remove-if-equivalent-for-stdmap/800984#800984

Silly programming errors

0 comments
Here's a list of silly programming mistakes I've made recently with the appropriate line highlighted. You can clearly see from the context given that it was not intended, but you must look carefully.

This one was caught by valgrind, about 6 frames deeper as being uninitialized:
struct CpfsTime ct[2];
timespec_cpfstime(&tv[0], &ct[0]);
timespec_cpfstime(&tv[0], &ct[0]);

This one typically gives a compiler warning. However this one I found after my filesystem started gaining free space when I copied to it.
if (g_cpfs->freeblks = -1) {
    g_cpfs->freeblks = bitmap_avail_raw();
}

This one was the hardest to find. I did not even know it was the cause of the problem. In Windows there is a special form of "stat" used in their equivalent to "readdir". The erroneous file sizes would only cause errors in applications that depended on the readdir() form, such as the builtin Windows explorer and image viewer.
split_to_DWORDs(cpfsStat.size, to.nFileIndexLow, to.nFileSizeHigh);
to.nNumberOfLinks = cpfsStat.nlink;
split_to_DWORDs(cpfsStat.ino, to.nFileIndexLow, to.nFileIndexHigh);

Are these the kind of "problems" with using C, and allegedly to a lesser degree (but still present) C++? The general opinion is that these are typing errors, but languages like Python would never pick them up, and in statically typed languages the use of primitive types would still prevent any checks by the compiler.

Saturday, 30 October 2010

Clever piece of code

0 comments
srand(time(NULL) ^ _getpid());
Nice huh?

Sunday, 24 October 2010

Ubuntu Maverick 10.10

0 comments
Pros
  • The new font is great.
Cons
  • Booting is not clean on all hardware.
  • Default themes still have contrast issues.
  • Many packages are unstable, or have conflicts.
  • Unity is completely broken. It has terrible performance and no functionality at all.
This is not good for an Ubuntu release. 5/10.

Saturday, 3 July 2010

Tkinter

0 comments
Pros
  • Ships with Python.
  • Also has C and Tcl bindings.
Cons
  • Not necessarily packaged with Python.
  • Looks like arse.
  • Nobody has tried writing doco for it in 5 years.
  • Nobody has ever written complete documentation for it.
  • It's behind the mainstream GUI toolkits by about 15 years.
  • The bindings were written in around 1997, and probably only stick around because they're low maintenance, and picking another toolkit would invoke a holy war.
  • Errors, and invalid geometry configurations don't always throw exceptions, and may cause infinite loops.

Tuesday, 15 June 2010

Virgin Mobile Mobile Broadband on Ubuntu Lucid Lynx

0 comments
Using the Huawei E160e dongle provided, it was necessary to turn off all authentication methods except PAP, and set the APN to "virginbroadband" lowercase, via the network manager. I also had to disable my wireless (household) temporarily as it was causing chaos with the routing tables.

Sunday, 2 May 2010

Resetting the Startup Applications in GNOME

0 comments
Resetting the Startup Applications in GNOME

Remove ~/.config/autostart, (or any of the *.desktop files therein containing Hidden=true).