Oh the pain

I love Apple. You know that. Without Apple, I’m not sure what sort of life and career path I would have taken.

But… I’ve held off on upgrading to Lion (Mac OS X 10.7) and Xcode 4 for numerous reasons. One is because my day job’s requirements still need some older OS support so we had to hang back on Xcode 3 (which won’t work under Lion). But the other is all the reports of the hell, dreck, and problems in the upgrades.

I’m now in a position where I have to upgrade one dev machine to Lion and Xcode 4 in order to work on some cutting edge iOS stuff.

Oh it hurts.

The worst part of Lion is switching how scrolling works. I understand why it was done, but it still sucks. (Yes I know I can change it).

And then Xcode 4… oh, for all its improvements, all the changes are huge. It’s killing my productivity to make the adjustment. All day long I’ve been dealing with the New World Order of Lion and Xcode 4, and let’s just say I haven’t been all that productive… tho if I could count the string of obscenities spewing from my mouth as productive, then I guess productivity is at an all time high.

*sigh*

It’s just a matter of adapting and getting used to it all. I know. And if this is the worst problem in my life, then life’s pretty good.

Still.. just had to vent.

I keep saying it will all be better, that 10.7.4 or .5 will fix a bunch of things. That Xcode 4.3 will bring back User Scripts. But I’m not holding my breath.

Don’t call yourself a programmer

Cleaning out a bunch of things I’ve wanted to link to.

A great article, “Don’t Call Yourself a Programmer, and Other Career Advice“. It’s long. I’ve only been able to skim it. But it’s chock full of goodness.

HsoiContextualServices 3.1 now available

My company, Hsoi Enterprises LLC, just released a 3.1 update to HsoiContextualServices.

Mac users, check it out! Download and use. It’s free, it’s functional, it’s useful!

Spread the word!

I’m going through changes…

I’ve been reassigned.

Still with the same company I’ve been with for many many years, but I’ve been put onto a new project. It’s radically different from what I’ve done for the past umpteen years, but it’s still writing Mac software. Yet for all the same, it’s very different. I think the hardest transition hit me this morning as I was talking with another engineer on the team. You see, for nearly two decades I’ve developed software direct for the consumer, where anyone could download it or buy it off the shelf at a store. But now, the software is written for enterprise sales and while “Average Joe” still ends up using the software, the process of making things happen, the customer I am directly responsible to isn’t Joe. It’s subtle, but it’s a different paradigm to have to work in, and I have to adjust my mental paradigm.

The project is also higher profile, higher pressure. When I was told of the reassignment (just before Christmas), I wasn’t sure. I had helped out the same project a couple of years ago and it wasn’t the most favorable experience. But time has passed, and I’m happy to see that while yes there’s still problems, there’s a true effort to improve things. The best part? The guy that’s now my boss (and then his boss as well) are very sharp. We’ve only worked together for a couple of weeks but I’m left with nothing but a solid and positive impression. They understand reality, they understand proper development process, they understand how to say “no” (very important), and they understand that their job is to enable me to do my job (getting me what I need, shielding me from what I don’t need). Even better, they understand that while there are important things to get done, we cannot have death marches, we cannot demand 60-80 hours a week every week, that people need to have their non-work lives and have balance overall in their life. This is a welcome thing and gives me hope for this assignment. Sometimes having a good boss makes all the difference in the world. 🙂

It’s been a rough couple weeks to get started, but that’s only due to being dropped into the deep end of the pool and having to swim. Just lots of little things to have to figure out, get in line and get going. But overall, so far so good. That’s one reason I haven’t been blogging much… just had other things to cope with right now. But things appear to be settling into a groove, so here’s hoping.

I am bummed that I cannot pursue working on mobile apps like for iOS and Android, but that’s not too big a worry. So long as that job maintains a healthy role in my life, I can get my mobile work in other venues. And I’m working to do just that.

Life is full of surprises. You roll with the tide. You play the hand you’re dealt, and all those clichĂ©s. I’m working to find what’s good, what’s ultimately best for me and my family. At first I wasn’t sure this move was going to be good, but it’s actually turning out to be alright. Onwards….

Daemon schism

Daemon schism.

I posted a Facebook status message yesterday:

Well, I’m feeling more optimistic about the “daemon schism”.

which would make no sense to anyone but me and my teammate at work. Someone commented on the status update saying they had a Google fail on the phrase. So… I figured I would post it to the blog to it and claim the coining of the phrase “daemon schism”.

And for those curious, I’m splitting a daemon in two.

Still can’t GetLabel()

So we’re at a point in our development cycle where we can finally upgrade our toolset. Installed Xcode 3.2.3, using the LLVM-GCC4.2 compiler, the 10.6 SDK, and setting 10.5 as our minimum OS.

Of course now I compile code and lots of OS function deprecation warnings come up. Time to clean up the source code.

If you need to obtain a Finder label, the old-school way was to use GetLabel(). Even today we still have to use GetLabel(), despite the fact they have deprecated it since 10.5. And while they deprecated it in 10.5, they didn’t provide a replacement API until 10.6. Unfortunately this replacement API isn’t 100% workable.

1. It’s an Objective-C API, in AppKit. Specifically: -[NSWorkspace fileLabels] (and -fileLabelColors).

The old API was a pure C API so you could easily use it anywhere, and we use it in a pure C++ library. Fine. I can create a .mm file with an extern “C” function to provide my own C wrapper and mimic GetLabel()‘s API. But it’s just extra work.

2. It’s only available as of Mac OS X 10.6.

It’s not a huge problem, but it’s irritating they deprecate the old way and didn’t provide a new way until the next OS revision.

3. -fileLabels crashes.

Isn’t that wonderful? They provide a new API and the new API doesn’t work.

And it’s not like it’s any sort of difficult API to work with either. It’s just a simple call.

But how can you get it to crash? Simple. Call [[NSWorkspace sharedWorkspace] fileLabels] 3 times. The first time will be OK. The second time might generate the crash but could also just generate console messages. The third time, you should crash or certainly generate bad messages in the console. If you didn’t crash the third time, certainly on the fourth you should. But typically 3 calls and boom.

-fileLabelColors doesn’t have this problem.

Investigating it, it seems there’s something being double-released/freed/deleted inside of -fileLabels. You can turn on garbage collection and it won’t crash, but lots of ugly console messages are generated.

What also bugs me? How did this API ship with such a bug?  Didn’t they test it? Didn’t they unit test it? Did they only test it under garbage collection? Did they write the API only for the Finder and figure if the Finder wasn’t crashing that was a good enough test to say a public API for the OS would work?  I mean, I can understand complex bugs, I can understand how code paths can be what they are and how bugs can ship (been a professional software engineer for over 15 years). But something like this? I can’t see how this managed to get out the door.

*sigh*

rdar://problem/8301881 Seems it was also reported as rdar://problem/8084710.

So… there’s no GetLabel() replacement for me until they fix it, 10.7 if I’m lucky. Yes I’ve considered other workarounds, no they won’t work in my particular context, or with a lot of work I could get it working but it’s not mission critical and I have bigger issues to deal with.

Updated: Apple DTS wrote back saying this is a known issue being tracked under its original number: rdar://problem/7287108, which as you can see is at least the third report of the problem. So we can only hope Apple’s going to fix it, but I bet we won’t see it until 10.7 at the earliest.

Named pipes and unwanted hangs

The past few days I’ve been dealing with a wonderful little problem.

They’re called “named pipes“.

The main product I work on in my day job was doing some filesystem scans and would hang for some unknown reason. After much investigation we noticed the file it was hanging on was a named pipe file way down in the bowels of the system (a temporary file created by the com.apple.notify process). What was happening was well… it’s a pipe. Something in my app was opening that pipe and thus the app “hung” because it was now wanting to read from the pipe. Thing is, my app doesn’t care about pipes at all, it’s just working with files. As well, we weren’t explicitly opening the file; we would call some other OS routine and somehow somewhere in that OS function’s implementation it called open() and thus we hung.

And so, what a bear this is.

In the end we decided to check for and avoid pipe and socket files at all costs. Any means by which a file can “get into” the app, we put up a wall at the perimeter so no such files can even get in. We figure we keep them out at the wall, then we don’t have to spend lots of CPU cycles internally to constantly deal with them (tho critical code should still perform checks). Plus, since one big part of the problem is we can’t control what others do and if they might open() the file, we have to nip it in the bud as soon we become aware of the file and minimize how much “work” is done on the file in case some other function might open() the file and we risk hanging.

To check is pretty simple. Code something like this (NB: I tried using the “code” tags and less-than/greater-than signs for the #include, but WordPress’ editor seems to get confused… so I just used the “pre” tag, which isn’t quite giving me the results I want either… oh well.).

#include "sys/stat.h"

bool
FileUtilities::IsUnsupportedFilesystemItem(
const char*    inPath)
{
    bool is = true; // assume failure, because if we fail on such 
                    // a simple operation something really has to be wrong
    if (inPath != NULL)
    {
        struct stat statInfo;
        int retval = lstat(inPath, &statInfo); // use lstat() instead of stat() because 
                                                   // we want to minimize resolutions or other "work"
        if (retval == 0)
        {
            if (!S_ISFIFO(statInfo.st_mode) && !S_ISSOCK(stat.st_mode))
            {
                is = false;
            }
        }
    }
    return is;
}

How you actually cope with it or if you consider them problems or not is up to you and your code and your situation. The key of the above is to get the file’s mode then check the FIFO and SOCK flags. If set, reject the file.

For most people, this isn’t going to be an issue or a problem. I mean, we went around for quite some time and never dealt with the issue. And in daily use, most people aren’t going to see pipe or socket files.

But it’s worth noting and thinking about. Nothing wrong with being a little defensive.

xml standalone

Apple changed the NSXML/CFXML implementation in Snow Leopard to use libxml. Generally a good move, but so far it appears to have caused some problems:

  • The notion of -[NSXMLDocument isStandalone] changed, at least in the sample code I’m using as a reproducible case for the bugs. In 10.5 the value is NO, in 10.6 it’s YES.
  • Having the XML declaration contain standalone="yes", at least in the sample code, eventually causes the libxml parser to crash. Maybe not always, but if you send the sample code an AppleScript of
    tell application "SimpleScriptingPlugin"
        beep
    end tell

    the sample app will crash. Force [myNSXMLDocument setStandalone:NO] and no more crash. Or run it under Leopard regardless of the standalone setting and no crash.

It’s taken many months of investigation and going back and forth with Apple to figure out this OS bug, mostly because due to how the problem comes up we were chasing down other avenues (was this an AppleScripting problem? Still could be, at least in part.). But for now, it seems we’ve a few issues with how NSXMLDocument generates XML, how NSXMLDocument regards being standalone (and across the OS versions), and then how libxml ungracefully handles that specification. Hopefully with my further information, Apple will be able to properly remedy all of this. Yes, it’s all properly filed with Apple, so they’re aware.

I tell you. This crash problem has been plaguing me and our users for quite a while. We’ve been able to provide the users with ways to work around things, but it’s not optimal. My hope is now with this information we can provide a better solution in our code and hope that Apple will soon fix this in the OS. Finally hitting upon this last night was quite the euphoric moment. 🙂  Granted, there may still be other things to deal with for this, and I could be premature in celebrating… but certainly it’s more info for Apple towards fixing the problem, and it’s still a hopeful step in the right direction for me and the users of my product.

Buried in treemaps

I realized the day was half-way over and I hadn’t written anything here.

Why?

I’ve been buried in documentation on the concept of treemaps. Lots of reading, studying of code and algorithms. It’s neat stuff.. at least to a geek like me.

I’ll be working on my own implementation soon. For what? Well… just can’t say. 🙂