Wednesday, October 31, 2007

The Perfect Poker Player



A friend sent me this funny commercial, advertising... wait a minute? Could the guy in the video be possibly bluffing? (The dialogue is a bonus for Romanian speakers).

Tuesday, October 30, 2007

Handling Invalid UTF-8 in ZeroBUGS


Based on suggestions from users I have changed the way ZeroBUGS deals with invalid UTF8 code when loading source files. The GtkSourceView widget uses ustrings internally, and when passed single-byte strings will assume UTF-8 encoding and convert them.

In order to prevent accidents such as loading a binary file instead of a source file by the users, I had my UI reject outright any invalid UTF-8 text.

But it turns that sometimes this restriction is too strong, and I have added a dialog that asks before rejecting the file.

Saturday, October 27, 2007

Who Needs Geography



"Who Needs Facebook" asks Forbes' Evelyn M. Rusli. And who needs geography? I should add.

Dear Evelyn, I know that Google is omnipotent and they can move Redmond to California should they decide to, but for the time being it has not been moved.

I think you got owned.

It Was a Very Good Year

When I was twenty-eight,
It was a very good year
It was a very good year for Internet hacks
Who were full of air
With all those flowers in their hair
And it came undone
In nineteen ninety eight.

On June 25 Microsoft released Windows 98 First Edition.

On November 24 America Online announced its intent to acquire Netscape Communications in a stock-for-stock transaction worth US$4.2 billion.

The Browser Wars thus approached conclusion. We all know how much market share Netscape initially had, and how little share Mozilla with all of its derivatives has today.

So whenever I hear all that buzz about how great and awesome and strong and cool and supercalifragilistic Google is, I like to point out that (for whatever strange reasons) history tends to repeat itself.

Wednesday, October 24, 2007

Linurix: Linux Limericks

I like to improve my English as a second language every chance I get. For example, when I am stuck in traffic I practice making limericks.

Today I came up with something new: linurix (plural linurix). Limericks about Linux. They go something like this:

There is a man from Stellenbosch
Who's never seen a Macintosh,
Because Winnie Mandela
Once told the poor fella
That Ubuntu Linux was posh.

There is a guy in Tennessee
Who owns two Macs but no PC.
He thinks RedHat from Raleigh
And the Pope are unholy.
And this is religion, you see.

Charles Simony circled the Earth.
On his way back he came forth
And called his attorney
"Hey man, this journey
Confirms: Ubuntu is shuttle-worth!"


Tuesday, October 23, 2007

Wide Strings Debugger Support



This past weekend I worked on adding support for visualizing wide standard strings and QT strings in the ZeroBUGS debugger. For convenience, they can be displayed as if they where regular C strings.

This feature can be turned off and on from the Edit / Options menu. Under the Language tab, if the checkbox for Qt strings is unchecked, the inner structure of the object is shown. Otherwise Qt strings are displayed as regular strings. std::string and std::wstring instances are handled in a similar fashion.

Before implementing this feature, the values of the variables displayed by the debugger where being represented as C strings.

The solution for wide strings keeps the existing design: I read the Unicode strings from the target process' memory, then call wcsrtombs to UTF-8 encode them.

And Glib::ustring takes it from there:
GTK+ and GNOME chose to implement Unicode using UTF-8, and that's what is wrapped by Glib::ustring. It provides almost exactly the same interface as std::string, along with automatic conversions to and from std::string.

It is still a new feature and it needs more testing and possibly, ahem, some debugging but overall I am pleased with the results.

And if you have any feedback regarding what features should I work on next, please take the poll in the right hand side bar, or leave a comment. Or both. Merci.

Sunday, October 14, 2007

AMD's CodeAnalyst

Now that I have stabilized the features of ZeroBUGS, I am looking into improving the overall performance and implicitly the user experience.

This weekend I live searched for profiling tools and I found AMD's CodeAnalyst.

On Linux, Code Analyst uses oprofile.

I downloaded the source code for version 2.6.22 of CodeAnalyst and proceeded to build it on a Fedora 5, 64-bit system equipped with an Athlon processor. It is not clear to me whether the 2.6.22 version is a coincidence. Has the kernel version to be an exact match for best results?

I am running 2.6.20 on that box, and the program ran but collected no samples, as per this message
Oprofile engine has encounter error genrating system view

I grepped for the message and found it here:



void opdata_handler091::read_op_module_data()
{
string session = m_session;
vector <string> non_options;

reset_data();

for (size_t i = 0; i < m_op_events.size (); i++) {
non_options.clear ();
non_options.insert (non_options.begin (), m_op_events[i]);
non_options.insert (non_options.begin (), session.data ());

try {
generate_apps_summary(non_options, i);
} catch (op_fatal_error const & e) {
string msg =
"Oprofile engine has encounter error genrating system view:\n\n";
msg += e.what();
m_ca_display->update_display(msg.c_str());
reset_data();
break;
}
}
}


(File /src/ca/libs/libopdata/op091/opdata_handler091.cpp). The reason I am showing the code snippet here (broken English not withstanding) is that I noticed a bad coding idiom: the catch block is doing quite a lot of stuff, and I see several things that could possibly throw.

Nit-picking aside, I rebooted the machine in a different configuration (Ubuntu 6.06, 32-bit, running kernel 2.6.15) and this time I got luckier. I even found a few interesting bottlenecks in ZeroBUGS.

I concluded that the oprofiled / 2.6.20 64-bit kernel combination must be the culprit of my initial lack of success.

It definitely looks like CodeAnalyst is a useful tool, once one gets past the initial small road blocks.

Wednesday, October 10, 2007

Gnomes

Following my disgruntled post on Gnome and GtkSourceView last night protests broke in Europe (and even in France).

Seriously, some people may think that I am talking nonsense and they are entitled to their opinion.

But I am considering rewriting the UI for ZeroBUGS using KDE. I am sick of this game of ever shifting APIs. Say what you want about Windows, but the Win32 API stayed backwards compatible for as long as I can remember.

Those folks do not get it: when you break the API you generate more work for developers like me: I have to carefully track the changes, decide whether to stay with one library or change my code to the new API? is the end-user going to have all the dependencies easily resolved or do I need to ship additional shared libraries? Merde.

Ed: Max wrote a very intriguing comment about http://www.fltk.org/. Worth considering, thank you kindly, sir!

Who Developed The Linux Hart?

Oh, a stud named Linus Torvalds. According to this source, he was studding (sic) in 1991, when "Linus felt he could do better than the Minix".

And the next page reads:
How to get Linux?

Linux available for download over the net, this is useful if your internet connection is fast. Another way is order the CD-ROMs which saves time
,

CD-ROM that saves time? Is he talking about the Caldera distro, perchance?

And it continues (emphasis mine):

What Kernel Is?
Kernel is hart of Linux Os.

It manages resource of Linux Os. Resources means facilities available in Linux

And ppplease, no PC lecture. English is not my native tongue either.

Tuesday, October 09, 2007

Gnome My Foot

I have not been paying much attention to the (old) Gnome versus KDE debate until yesterday (I just assumed that Linus is nit-picking and brushed it off).

But after installing OpenSUSE 10.3 I realized that the API for the gtksourceview component has changed. In the process, a part that is important to me (source markers) was dropped. It is not a show-stopper or enough reason for me to part with Gnome, because for the time being I have got some options, and the GtkSourceView team will reintroduce the dropped features by version 2.22.

But I understand now how people get upset over dropped features and interface changes.

As always, Linus was right.

All Mac Users


How many Mac users can you fit in one auditorium? All of them, apparently, as it may be seen in this picture from http://www.pizdaus.com/

Monday, October 08, 2007

OpenSUSE 10.3 First Impressions

This past weekend I have installed OpenSUSE 10.3

My first impressions: it looks very polished, albeit a bit slow (but then again, I installed it on a virtual machine, on a USB external drive). It installed some services that I do not care about such as SMB and power management. The Beagle thing seems to have an initial crawl phase (I guess that it indexes a whole bunch of stuff) and I had to kill and remove it.

And I was annoyed that there is no gtkhtml3-devel package (but I found what I needed here, so no biggie).

On the nice side, OpenSUSE 10.3 comes in the box with GCC 4.2, unlike Ubuntu 7.10 that ships with 4.1.3 (at least in the tribe pre releases, we still have to see what the official release contains).

Overall, a nice system, packed with apps and looking slick and crisp.

Speaking of Ubuntu, it is not a bad distribution either, but it is getting credit and hype for work that the upstream distro (Debian) is doing, and everybody knows that the heavy lifting in kernel development happens at RedHat, Novell, and IBM.

Thursday, October 04, 2007

RMS is Titanic

It turns out that reports of RMS GPL-ing himself (several times a day) are not new. I found this one (allegedly faked by a humorist) dated 2001:
On the other hand, Richard M. Stallman is always available for comment at press time. He issued this statement: "Unlike Linus Torvalds, I have made my signature available to the public under the GNU General Public License. It may be freely copied, distributed, and modified. However, I do request that users continue to write my signature as 'GNU/Richard M. Stallman'."

Sounds very much like someone who charges for autographs, as dug here, would say.

And this RMS sank down below a long time ago.

RIP, RMS

Tuesday, October 02, 2007

The Strange Tale of Two Exits

Since my early days as a C programmer, I have been always confused by standard library functions that came in two flavors, just one leading underscore apart (as in open and _open). A simple rule of thumb, “choose either one for the job at hand”, makes life easier (or almost).

There are exceptions to this rule. For example, what is the difference between _exit and exit?

If you answered “unlike exit, _exit doesn't cleanup global objects” then congratulations, you may skip this article; go do something fun. But if you thought that _exit is the ISO standard synonym for exit then I beg you to read on.

Both functions will cause the application to… well, exit and the operating system reclaims all resources held by the process (memory, file handles, and so on).

The underscore variant does just that, without further ado. The non-underscore form, however, does a little bit more: before yielding control back to the operating system, it loops through all the functions that have been previously registered with atexit, and calls them in the reverse order of their registration.

Let’s take a look at the following C program:

1 #include <stdio.h>
2 #include <stdlib.h>
3
4 void finish(void)
5 {
6 const char msg[] = "Good Bye.\n";
7 write(1, msg, sizeof msg);
8 }
9
10 int main()
11 {
12 atexit(finish);
13 fprintf(stdout, "returning from main...\n");
14 exit(0);
15 }


Line 14 is equivalent to saying “return 0”; when the function main() returns, control is transferred to the C runtime which invokes exit(), passing it the return code.

The output of this program is:

returning from main...
Good Bye.


If the exit call in line 14 is replaced with _exit, the finish function will not be called, and the “Good Bye” message does not show in the output.

But how does this old C stuff affect us, C++ programmers? The short answer is that global objects (which live outside function main(), are cleaned up by functions registered with atexit().

Let's consider the following code:

1 #include <stdio.h>
2 #include <unistd.h> // use <stdlib.h> on Windows
3
4 struct Fred
5 {
6 ~Fred()
7 {
8 fprintf(stderr, "Good Bye\n");
9 }
10 };
11
12 Fred fred;
13
14 int main()
15 {
16 fprintf(stderr, "Returning from main...\n");
17 exit(0);
18 }


Again, line 17 is equivalent to saying “return 0”; this program behaves the same as our first example. If we change line 17 to read _exit(0) we may observe that the string “Good Bye” is never printed.

“But we are not registering anything with atexit!” you may say. True, we are not, but the compiler is, on our behalf. Because an instance of Fred is being constructed outside of main(), the compiler generates some cleanup code, arranging for the destructor to be invoked as if it were registered with atexit.

And you might not even be aware that you are calling exit; maybe all you do is invoke a third-party library, or a library function developed by some other person or group in your company; that function may call exit when it encounters an error.

This may become a serious issue in a multithreaded program that has global objects, if any thread calls exit(). This may lead to the untimely demise of a global object that another thread is depending upon (such as a global mutex wrapper class instance).

My Two Cents (and Two Buck Chuck)


While visiting a couple of wineries in Oregon last week, I read this fun article on Fred Franzia. It got me to thinking that either I have a thick palate (and thus cannot tell things apart once the bottle goes above $35), or all that "fruity flavors with accents of oak and Mediterranean spices" on the label is just chickenshit.

Is it all about pretense, and feeling smug, kind of like this piece of coprolite video in which Steve Jobs asserts that the Borg have no taste?

Who knows? Cheers!