\Microsoft was unexpected at this time

I just spent two days tracking this problem down.

I received my new development machine with Windows7 x64 only a week ago. It all was just pefect – quad core CPU could compile the world in almost no time, and brand new Visual Studio 2010 was just as good as it gets. By the way, I am the Linux guy and prefer vim, automake and gcc any other IDE, so if I call Visual Studio perfect, it means something.

Neverthless, everything good has an end. Yesterday I tried to build bcp.exe tool I needed to dissect boost, and I faced very nasty and very unclear problem. I simply could not. Every time I started the build process, it would fail with the most weird message I ever seen:

\Microsoft was unexpected at this time

Well, I mentioned I am the Linux guy, but I am not a religious fanatic. I just thought that there was a problem of some sort in the boost’s build script and used another machine to build bcp.

Next day I became really concerned. I realized that I could not use “Visual Studio Prompt” from VS 2010 and VS 2008. Every time I tried to start them, they would have that message about unexpected microsoft on them; and environment variables were not set. So I could not build anything! Sadly, this was rather a major problem for me as we had quite a few makefile projects and not being able to set the correct environment for build process was that kind of present I could happily live without.

I spent next four hours to find that this or similar problem was already mentioned several times; but nobody offered a solution that would work and nobody explained what was causing that. Some said that Windows SDK installation could break the batch file vcvars32.bat; some thought there was a bug in the batch file itself. Strangely,  it all worked perfectly on the the neighbor’s machine. I even compared the files and found no difference at all.

The solution came at the end of the day when all my hopes were gone. One guy mentioned that the problem was caused by the parentheses in vcvars32.bat:

@if not "%WindowsSdkDir%" == "" (
	@set "PATH=%WindowsSdkDir%bin\NETFX 4.0 Tools;%WindowsSdkDir%bin;%PATH%"
	@set "INCLUDE=%WindowsSdkDir%include;%INCLUDE%"
	@set "LIB=%WindowsSdkDir%lib;%LIB%"
)

He mentioned that as he found out, one of the directories where SDK was had braces in the name as well, and that broke the statement above completely as batch processor would find nested parentheses in the folder’s name and consider them as the end of the statement.

Needless to mention, may machine had some paths that had braces in them. C:\Program Files (x86). And, needless to mention, it is exactly where Visual Studio is installed. And it also exists in %PATH% environment variable.

By itself, it does not break the script. As I mentioned, it worked perfectly on the other machine which was the biological twin of my PC. But, what if one of the PATH’s members is encolsed in double quotes? (to check how your PATH looks like, type echo %PATH% in command prompt). I checked and that’s what I found:

c:\winutils;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;
c:\Program Files (x86)Microsoft SQL Server\100\Tools\Binn\;
c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;
c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;
"C:\Program Files (x86)Microsoft Visual Studio 9.0\Common7\IDE\";
C:\Program Files (x86)Microsoft Team Foundation Server 2010 Power Tools\;
C:\Program Files (x86)Microsoft Team Foundation Server 2010 Power Tools\Best Practices Analyzer\;
c:\cygwin\bin

Bingo! I found that one entry of PATH was indeed enclosed in double quotes. And, not surprisingly, it had that nasty (x86) in it. It was pointing somewhere inside VS 2008 installation tree, so I think one of VS 2008 tools I have installed recently indeed screwed this up.

So, I simply removed those double quotes. Immediately after that, both VS 2010 and VS 2008 command prompts were fixed.

So, the fist thing you should do if you’re having the same problem: look at your %PATH% environment variable and check if anything is enclosed in double quotes.

Finding this just cost me two days of work, and I hope it it helps you sorting it out much faster.

\Microsoft was unexpected at this time

Plenty of rocks, not so much water

I was hoping there would be more water in Somersby falls.

But this is nice anyway

Somersby falls

Visual Studio 2010: Not so nice improvements in TR1

Just moments after installing VS 2010 I found very nasty bug in its implementation of TR1 libraries:

            typedef struct sTestStruct
            {
                char* pName;
                char* pOtherName;
                sTestStruct* pNext;
            } sTestStruct;

            sTestStruct Struct1 = {"blah", "mlah", 0};

            char* pChar = bind(&sTestStruct::pName, _1)(&Struct1);            // Compiler is happy here

            bind(_stricmp, "blah", bind(&sTestStruct::pName, _1))(&Struct1);  // bang happens here

The error message is simply astonishing:

\microsoft visual studio 10.0\vc\include\functional(447): error C2440: ‘return’ : cannot convert from ‘char *’ to ‘char *&’

What is interesting, should I switch C++ toolset to version 9.0 (essentially switching back to VS 2008), the problem went away.

If I could I would suggest that something went horribly wrong when MS were working on rvalues (or were they lvalues?) references business, but there is simply no point guessing around. I just wonder how long will it take MS to fix the problem. Obviously, problems like this could mean that this new version of VS 2010 is not ready to be used in production yet.

Also, reporting bugs to MS has always been not so easy quest.

Use boost to implement inter-class callbacks or delegates

In the software development, the pattern when one object has send a message to another object, where the object that has to be called is given to the first class somehow (usually in constructor), is quite common. In C#, the delegates serve exactly this purpose, but in C++ it is a different story.

The most common way of implementing the class-to-class callback in C++ is to define an interface, which the class that receives the event must implement:

class IInterface
{
public:
virtual void CallbackMethod() = 0;
}

class MyClass:
public IInterface
{
public:
virtual void CallbackMethod()
{
// do something useful
}

class Publisher
{
private:
IInterface* m_pCallee;
public:
Publisher(IInterface* pCallee):
m_pCallee(pCallee)
{
}

private:
void SomeMethod()
{
m_pCallee->CallbackMethod();
}
}
}

It isn’t exactly rocket science, but this method has some downsides, and some of them are quite nasty and not obvious at all. Those are:

  • You may need to define a new interface every time you need a callback function with new signature. Could partly be solved by making the interface class template
  • Each class that interested in callbacks needs to implement corresponding interface(s)
  • In some situations you may end up with a single object that can receive callbacks from many different publishers.

The last one could make you wish you never become a software programmer. The architecture, which seemed so beautiful just moments before, starts to fall into pieces once you find yourself in situation when you realize that your class-subscriber needs to receive same callbacks from different sources and act differently depending on who the caller is.

Let me explain it on the example. Imagine you have a class that implements that callback interface. You also have a lot of providers that take that interface to inform the subscribers, for example, about quote changes. But in your class, you need to track changes on, say, 10 quotes, and depending on which of those 10 changes, take different actions. So, what ’s your options?

Of course, you could just add an additional  parameter to callback method that specifies the sender, but it is not pretty at all, as the subscriber class now faces a new challenge of keeping track of all publishers it is subscribed too. Not mentioning the mess in the callback method needed to get all stuff to work!

Ideally, you want each of those providers to call different methods of your subscriber class, but in a general case it would mean 10 different interfaces and changes in all publishers, which may not be possible and I don’t even want to talk about it. The other option would be to write the proxy, which implements the basic callback interface, subscribes to the only provider and then re-routes the call to certain method on your class.

Thankfully, there is the far better option. boost::bind and boost::function are here to help.

class Publisher{
public:
typedef boost::function<void (int)> typeCallbackType;

void Subscribe(typeCallbackType cb)
{
m_cb = cb;
}

private:
typeCallbackType m_cb;

void SomeDataProcessingMethod()
{
// ....
m_cb(currentPrice);
}

}

And here is a good thing: your subscriber class does not have to implement any custom interface anymore:

class MySubscriber
{
public:
void CalledWhenPriceChanges(int newPrice)
{
// make profit here
}
}

to establish a subscription, simply use boost::bind:

Publisher* pPublisher = GetPublisherFor("someTicker");
MySubscriber Subscriber;

pPublisher->Subscribe(boost::bind(&MySubscriber::CalledWhenPriceChanges, &Subscriber, _1));

That’s all, folks!

Now, once the pPublisher has a new data, a CalledWhenPriceChanged() method of Subscriber instance of a class MySubscriber will be called. It is easy to see how additional publisher could be added if you want to monitor two tickers.

It would not only help solving the problem of multiple publishers-one subscriber. This approach will also do a great job saving you time from not having to define numbers of callback interfaces for different types of data that needs to be passed from publisher to subscriber.

Petrol tanker on F3: epic FAIL

I am officially pissed off.

Did not think that I will ever go on the wrong side on a freeway. Driving on the opposite site of F3 isn’t clearly the best way to get to feel yourself like being in Europe. In any case, the way officials handled the accident wasn’t quite European too.

I left Gordon yesterday at 10:00 pm  only to hit the tail of the most giant traffic queue I ever seen at 10:15. And, I am sure, traffic just started to barely move then. There were plenty of cars with people sleeping in them at the side of the road – they obviously decided not to bother for some more hours.

An guess what? Today’s morning TV news only said that contra-flow was implemented “several hours later”. Please note – it is the true, but there is a catch. This truth is short of some interesting details like while accident happened before noon, the contra-flow was opened only at 8:30 pm. And it was the working Monday. And all peak-hour traffic was in standstill for I don’t even want to know how many hours. See the difference? Most online news sites were citing the same bullshit, at least in the morning. Like nothing serious happened, just a bit of slow traffic on one local country road. Now, when shit finally hit the fan, they all screaming loud that “blame game has started“. Good timing, guys!

So, the F3 was still pretty much the carpark 10 hours after the accident. I would call it “The incompetence”. Obviously, someone also just did not want to take a decision.

What should have been done? I reckon, after an hour or two when it became obvious that there is no way they could move the tanker without unloading it, they should have left it alone for time being. I assume, the tanker itself was safe, but in today’s “news” they said there actually was a small leak!  The peak hour was approaching, and with huge delays already in place, opening the freeway for traffic should be their priority number one. They should have isolated the accident,  put temporary barriers and open as many lines as possible (according to photos, the tanker was only taking one line!), just to let people trough.  Also, the contra-flow had to be operational at 3:00pm the latest!

That would not only help bringing people home, it would also leave them with the whole night to do whatever they were going to do to remove the tanker without having thousands of angry and tired motorists around.

Why it did not happen – I don’t know yet. But, mind you, every incident has the first name and the last name.

P.S. I wonder if everyone who lost money because of the accident (late childcare fees,  extra petrol, you name it) should send the invoices to the RTA.

Ubuntu Linux. No DMA on CD/DVD drive

Some time ago I built myself home media center on MythBuntu 8.04. It works exceptionally well… well, with one exception, if I may be excused. I could not watch my absolutely legally purchased DVDs at all – playback was choppy and jumpy, making watching movies anything but enjoyable.

If you found this post on google, you, probably, are about to give up. I was too. But I found a solution that worked for me. So, if you, like me, have seen zillions of webpages discussing the problem but none of solutions worked for you, keep reading (and please comment if this post helps you to solve your problem).

So the problem was that CD or DVD driver has no DMA enabled and hdparm would report an error:

 HDIO_SET_DMA failed: Operation not permitted

when trying to enable DMA.

I have Intel-based HP desktop with SATA HDD and IDE DVD combo drive. No problem with HDD, but DVD got stuck in PIO mode and hdparm is no help anymore. I have modules ata_piix and libata loaded.

After scanning though many discussions and FAQs, I finally found the most accurate description of the problem that offered a way to fix it. So I did exactly what they told:

# echo options libata atapi_enabled=1>/etc/modprobe.d/atapienable
# update-initramfs -u

and added

combined_mode=libata

option to kernel line in grub’s menu.lst

After reboot DVD drive was finally in UDMA mode!

MuthTV sluggish when buttons pressed on remote?

Recently I built myself a media center of old HP/Compaq computer and MythBuntu. It all worked as a top and I spent weeks learning about great features it has.

This week I was hoping to put some finishing touches on it. The last missing piece arrived – so-called “Vista Rock Remote”.

7.jpg

According to MythBunty HOWTO, this MCE-compatible remote should work out of box, despite some reviews saying it would only work with Vista. Don’t know if it works with Vista though, but it worked in MythBunty just fine. I only had to enable it in Mythbuntu control center. And restart MythTV frontend, of course.

Funnily enough, I noticed the big problem straight away. Every time I put recorded TV show on and tried to use volume up/down buttons on remote, the picture was getting sluggish and jumpy for noticeable time. Actually, it felt so weird I even thought that I might be only one who had that problem. I was not right – there were plenty of similar reports on Internet. And there was a workaround proposed also.

The root cause of the problem is that MythTV pokes X screensaver every time button on remote is pressed. It does not have to do so when you use keyboard, but must do it when you use remote as screensaver has no idea about it. MythTV kicks the screensaver by invoking “gnome-screensaver-command” with parameter –poke, and there are reports it does it twice every time you press the button. It isn’t itself a problem, the problem is that when this command is called often (and it exactly what happens when you try to put volume up or down) XOrg CPU usage jumps to 100%, which causes that unwanted “special effect” in your video.

This bug, however, has already been reported (here and here)  and the fix will probably be included in next MythTV release. For now, the only workaround was to disable screensaver and create a symbolic link to /bin/true with name gnome-screensaver-command somwehre in one of PATH’s directories that comes in front of where the original program resides. Say, if your PATH looks like

/usr/sbin;/usr/bin;/usr/local/bin

and gnome-screensaver-command is in /usr/local/bin, you can stop it from being called by creating link to /bin/true in either/usr/sbin or /usr/bin:

ln -s /bin/true /usr/bin/gnome-screensaver-command

But it would only work if you decide to disable the screensaver. You can try not to, but once display goes to sleep, you won’t be able to wake it up by using remote. So I decided to invent something more sophisticated.

Of course, I could  download sources, fix the bug and build MythTV myself, but I decided to leave it to mythbuntu team. Instead, I written small program that simply does not allow screensaver to be poked more often than once in a minute, which fixed the problem.

The good news: you can download it from this site: Mythtv screensaver proxy

The bad news: you must build it yourself. So, installing build-essentials first would be a good idea.

Download cpp file above somewhere in your home directory and then follow simple steps described in file header:

/*
 * Usage:
 *      1. execute "which gnome-screensaver-comand"
 *      If output is different from what you find below in
 *      DEF_PROGRAM, modify this macro accordingly.
 *
 *      2. build the program:
 *      g++ myth-screensaver-proxy.cpp -o gnome-screensaver-command
 *
 *      3. Find what directory original gnome-screensaver-command is in
 *              (/usr/bin/ by default).
 *
 *      4. Look at your PATH settings (printenv | grep PATH).
 *
 *      5. copy binary buld on step 2 to any of the directories that
 *      come in PATH before original gnome-screensaver-command directory.
 *
 */

A coolest gadget I ever heard of.

It seems ViewSonic wants to grab some of the pie already shared by Asus, Acer and MSI. They just announced a new netbook

I bet this computer will not leave any chances to competitiors in Russia. Its name “VieBook” sounds somewhat between “I will rock you book” and funny statement of intentions of sexual character.

Another example why global market can be a pain in the ass for marketologists.

New airport for Sydney in Somersby. Is it for real?

A few years ago we became proud owners of a book called “Sydney Region Outline Plan”. The book, printed in 1968 is nothing else but a large 111-page report about what Sydney and surroundings looked like back then and how they were expected to look today. Surprisingly enough, that was rather interesting reading.

In “Transport” chapter a few paragraphs were focused on that by 2000′ a second airport should be built in Sydney. No doubts it should have already happened. But it did not. I remember how amused I was when I learnt that the largest and busyiest air hub in southern hemisphere is closing for any flights every night. Well, to be honest, I could hardly imagine a modern city with the airport nearly in its center before!

Anyway, that book pointed a few options where second airport could have had been built. Of course, we already heard of options like “somewhere on West” or “in Richmond” but there was another interesting option – they were also talking about Wyong shire and even considered it as one of the prefferred options. Never happened though. Yet (?).

Well, this is all about a front cover of today’s “Central Coast Sun Weekly” – it says that the government is once again revisiting plans to build a new airport for Sydney and there  are “many feasible reasons” why it should be build in Somersby. Not far away from Wyong, but nothing new – they already shortlisted in in 1969 and there was a 500-people demonstration against it back in 1971 (see aph.gov.au).

I am not quite sure how feasible is it really – from my impression landscape here on Central Coast is anything but suitable for airports. I am not airport architect and I don’t know all the details – may be Somersby plateau is large enough for long runways required for A380, but that besides the point. Even the fact that some businesses have already backed the proposal (which is understandable) so as that it is not know yet how would it change the face of Central coast and affect the enfironment are not important yet. I rather curious about whether they decide or not finally? This discussion already seems to last for over 50 years.

Useful C++ template magic. Hiding nasty global static’s

In C++, often there is a need to provide and support single instance of certain class, accessible on demand from anywhere in the program. That is encyclopedic example given in many books promoting singleton pattern. For instance, if your program has a log file, it is strongly recommended that you make a class that encapsulates all logging and make it singleton. This approach, without any doubts, is much much better than making global static instance of the logger and then referring to it from whatever you need as it reduces number of cross-dependencies, an issue that stays among the most bad techniques making code less maintainable.

This is easy to understand – while there is nothing wrong in static variable, even in global static variable, we must ensure that it is initialized before it is used first, which is especially important if the object has to be created dynamically. And this is the problem Singleton pattern solves.

Take the example

// SomeSourceFile.h
#include "CoffeePlantation.h"
static CoffeePlantation g_Plantation;

// SomeSourceFile.cpp
#include "SomeSourceFile.h"
// Initialize the instance
g_Plantation = CoffeePlantation();

Note: coffee plantation…

9 visitors online now
9 guests, 0 members
Max visitors today: 9 at 05:13 am MST
This month: 30 at 09-01-2010 12:31 am MST
This year: 41 at 01-23-2010 03:43 am MST
All time: 41 at 01-23-2010 03:43 am MST