c++ stl bitset only useful for known-at-compile-time number of bits

Found in the libstdc++ docs:

Extremely weird solutions. If you have access to the compiler and linker at runtime, you can do something insane, like figuring out just how many bits you need, then writing a temporary source code file. That file contains an instantiation of bitset for the required number of bits, inside some wrapper functions with unchanging signatures. Have your program then call the compiler on that file using Position Independent Code, then open the newly-created object file and load those wrapper functions. You’ll have an instantiation of bitset for the exact N that you need at the time. Don’t forget to delete the temporary files. (Yes, this can be, and has been, done.)

Oh yeah – feel the love.

Brought to you by the stl-is-often-worse-for-you-than-meth dept.

Dodge Avenger furthers the stereotypes of American cars

“Every time it goes around a corner you are going to die” would roughly be an accurate statement.

This is the car I’ve been driving for the past week. Absolutely no feeling in the steering at all (in fact less feeling when cornering).

It also bongs at you seemingly randomly. It especially likes not turning off the headlights when you get out of the car – even after you’ve locked it.

I’m sure it has torque… but only one of them.

Horsepower… sure, just not sure about plural. Foot to the floor and it kind of sits there wondering what you mean.

All this talk of “US carmakers failing” seems to be not a moment too soon.

I think I’m going to have to put a ban on driving American made cars…. except perhaps the Ford GT… I wonder if MySQL Sun Oracle would have a problem with that :)

Getting a file size (on Windows)

The first point I’d like to make is that you’re using a Microsoft Windows API, so you have already lost. You are just not quite aware of how much you have lost.

A quick look around and you say “Ahh… GetFileSize, that’s what I want to do!” Except, of course, you’re wrong. You don’t want to use GetFileSize at all. It has the following signature:

DWORD WINAPI GetFileSize(  __in       HANDLE hFile,

__out_opt  LPDWORD lpFileSizeHigh

);

Yes, it supports larger than 4GB files! How? A pointer to the high-order doubleword is passed in! So how do you know if this errored? Return -1? WRONG! Because the high word could have been set and your file length could legitimately be 0x1ffffffff. So to find out if you actually had an error, you must call GetLastError! Instead of one call, you now have two.

The Microsoft documentation even acknowledges that this is stupid: “Because of this behavior, it is recommended that you use GetFileSizeEx instead.”

GetFileSizeEx is presumably named “Ex” as in “i broke up with my ex because their API sucked.”

You now have something that looks like this:

BOOL WINAPI GetFileSizeEx(  __in   HANDLE hFile,

__out  PLARGE_INTEGER lpFileSize

);

Which starts to look a little bit nicer. For a start, the return code of BOOL seems to indicate success or failure.

You now get to provide a pointer to a LARGE_INTEGER. Which, if you missed it, a LARGE_INTEGER is:

typedef union _LARGE_INTEGER {  struct {

DWORD LowPart;

LONG HighPart;

};

struct {

DWORD LowPart;

LONG HighPart;

} u;

LONGLONG QuadPart;

} LARGE_INTEGER,

*PLARGE_INTEGER;

Why this abomination? Well… ” If your compiler has built-in support for 64-bit integers, use the QuadPart member to store the 64-bit integer. Otherwise, use the LowPart and HighPart members to store the 64-bit integer.”

That’s right kiddies… if you’ve decided to loose from the get-go and have a compiler that doesn’t support 64-bit integers, you can still get the file size! Of course, you’re using a compiler that doesn’t have 64bit integer support… and the Microsoft documentation indicates that the GetFileSizeEx call requires Windows 2000… so it’s post y2k and you’re using a compiler without 64-bit ints? You have already lost.

Oh, but you say something about binary compatibility for apps written in the old days (handwave something like that). Well… let’s see… IRIX will give you 64bit numbers in stat (stat64) unless you build with -o32 – giving you the old ABI. I just can’t see a use for GetFileSize….. somebody please enlighten me.

Which header would you include? Any Linux/UNIX person would think of something logical – say sys/stat.h (Linux man page says sys/types.h, sys/stat.h and unistd.h). No, nothing sensible like that. It’s “Declared in WinBase.h; include Windows.h”.

So… you thought that obviously somebody went through the API and gave you all this Ex function goodness to get rid of mucking about with parts of a 64bit int? You were wrong. Let me say it with this:

DWORD WINAPI GetCompressedFileSizeTransacted(
  __in       LPCTSTR lpFileName,
  __out_opt  LPDWORD lpFileSizeHigh,
  __in       HANDLE hTransaction
);

I’ll now tell you that this was introduced in Vista/Server 2008.

Obviously, you want to be able to use Transaction NTFS on Windows Vista with a compiler that doesn’t have 64 bit ints. Oh, and you must then make another function call to see if something went wrong?

But you know what… perhaps we can get away from this complete and utter world of madness and use stat()…. or rather… perhaps _stati64().

Well… you’d be fine except for the fact that these seem to lie to you (at least on Windows Server 2003 and Vista) – it seems that even Explorer can lie to you.

But perhaps you’ve been barking up the wrong tree… you obviously don’t want to find the file size at all – what you want is to FindFirstFile! No, you don’t want FindFirstFileEx (in this case, Ex is for Extremely complicated). It’s meant to be faster too… you know, maybe.

So remember kids, smoke your crack pipe – you’re going to need it if using this thing called the Microsoft Windows File Management Functions.

Enabling bluetooth on a hp laptop (6710b IIRC)

A friend of mine has a HP 6710b (if i remember the model name correctly). Bluetooth wasn’t working. Nada… not even a USB device showing up in lsusb for the inbuilt bluetooth.

It turns out, if you disable the bluetooth radio from the Windows thingy, it does something you cannot undo from Linux (at least with Ubuntu Gutsy) .

Except… after hours of fucking around, we reset the BIOS to default settings and this made it work.

Yep, no option in the BIOS setup to do this (there’s an Enable/Disable switch… but that doesn’t fix this problem). But a reset does it.

I really hope this saves somebody else the hours of “fun” we had.

How not to get a sensible response on a mailing list/web forum

For a start, you shouldn’t be using a web forum. Are you too stupid to use email or what?

Ask yourself, does your question boil down to “pls do my job 4 me. kthxbye” (because it’s in stupid speak because it’s an obviously stupid question to be asking). If it does, don’t post it. Instead, RTFFM (where F is for Fine…. at least one of them is anyway), look at the archives. You will then find approximately eleventy-billion messages pointing you to exactly the right tool and docs to let you answer your question – easily.

New Intel mobo not even booting….

This morning, found this blog post:

Herman Bos » Blog Archive » Got new hardware (DG965WH); yay; doesn’t even boot
Normally Linux doesn’t need to have its partition marked with the boot flag (windows does), so I didn’t really guess something like this myself. But it seems that the Intel BIOS checks the partition table and only agrees to boot from a disk if a partition is marked with the boot flag.

Intel, you utter, utter cocks.

kpresenter, doesn’t

(after apt-get install kpresenter)

$ kpresenter
X Error: BadDevice, invalid or uninitialized input device 170
Major opcode:  146
Minor opcode:  3
Resource id:  0x0
Failed to open device
X Error: BadDevice, invalid or uninitialized input device 170
Major opcode:  146
Minor opcode:  3
Resource id:  0x0
Failed to open device
koffice (lib kofficecore): ERROR: kpresenterpart.desktop not found.
koffice (lib kofficecore): ERROR: Run ‘kde-config –path services’ to see which directories were searched, assuming kde startup had the same environment as your current shell.
koffice (lib kofficecore): ERROR: Check your installation (did you install KOffice in a different prefix than KDE, without adding the prefix to /etc/kderc ?)
$

Ubuntu and more than 1 audio device

Welcome to a new category of blog post: heart-it-or-fart it.

This is an extenstion on the “Inciting Hatred” category, also allowing for praise.

I have a headphone socket on my laptop that seems a bit loose or a connection is dodgy. So, I’ve pulled out my old-and-trusty iMic – a device that came around so you could (for example) have sound input on a bunch of Macs that didn’t come with it (like my old 500mhz iBook). It also happens to have great audio out.

So, plug it in. little thing pops up saying “found new sound device, would you like to open the sound preferences panel”. So far, so good. So that’s what I do, open it, select my audio device and close it.

Then, if i’m lucky, it’s actually seleted it. More likely I have to go back and select it again, kilall esd, select it, relaunch rhythmbox.

Then i can play.

Maybe one song.

Then it skips over everything else in the playlist without playing them.

Quit rhythmbox, start it up again, works. for one song.

rinse, repeat.

Or, if you’re more lucky, you’ll get a fraction of a second of sound out of rhythmbox before it skips over everything. you even get a red stop icon next to the song. If you click on it, you see “Playback Error. Not negotiated”. Hrrm… not a very good error message there.

Oh, the other thing, if you succeed in playing your playlist, you then get, at the end, ALL OTHER SOUND EVENTS that happened for the ENTIRE TIME your playlist was playing. Because what pleases me more than ever is hearing 80minutes worth of gaim sounds one after another.

In the old days i would just “killell esd; esd -d /dev/dsp1”. This doesn’t seem to work anymore.

Verdict: fart it.

(oh, and before anybody says anything – i will be filing a bug report. just the sort of bug that you’re amazed that it was let out as a non-beta release)

Welcome – Ubuntu Linux 6.06LTS

Welcome – Ubuntu Linux

I took the plunge and last night I upgraded my laptop (my primary work machine – as in it cannot be busted[1]) to Ubuntu 6.06LTS (otherwise known as Dapper Drake. The LTS is for Long Term Support). It went pretty smoothly.

I had to remove irda-utils after the upgrade as a module being loaded was causing a panic (which showed itself by having everything freeze about 4 seconds after gdm started up and you’re about to enter your username). I should report a bug for that…

It’s slightly annoying that I had to disable gdm so i could see the panic to find out what was crashing. Perhaps we need either:

  • crash dumps (a-la IRIX and others where you can then run a debugger on an image of the crashed system)
  • panic over the top of X (a-la early MacOS X)

I have to say though, I am very pleased with the upgrade. Everything seems a bit snappier (much welcome) and NetworkManager works! I haven’t tried to suspend my laptop yet though.. so we’ll see if that works.

But a recent version of f-spot is welcome, I’m thinking I’m going to start using it for my photos. The next trick is going to be when i completely run out of disk space on my laptop for them.

The new Rhythmbox has me using it again. Disappointed not to see google talk support in gaim (although maybe i’m just not looking right).

The Window List still exists – a UI element I solemly think should die a quick death. It didn’t work in Microsoft Windows 95 with more than a few windows  open and it doesn’t work any better now (okay,  a little, but not much).

I want to take a second and marvel at the look of the new Human theme. It is rather lickable and, as we know, the only thing that matters with UI is how much you are licking your monitor. Even without wizz-bang GL compositing powered by cold fusion bucky ball quantum knot computers, it seems nice.

gnome-xchat is taking a little bit of getting used to, but the toast that pops up when somebody “stewart: hey”‘s me is useful.

Epiphany has received some updates too which are quite welcome. A bunch of elements used in phpBMS for Web 2.0 stuff are a lot faster. In previous blog entries I’ve said why I’m using Epiphany and not Firefox. I may re-asses this at some point, but I’m not really in any mood to manually move over saved passwords.

Evolution seems to suck up a bit less memory. Started out only using about 247MB. Now 338MB+52MB for evolution-data-server though…. maybe I’m just not feeling it as much due to other things chewing up less. WHY THE FUCK DOES IT TAKE 390MB FOR A PUNY 10GB[2] OR SO OF MAIL?

On the other hand though, there’s been a bunch of UI improvements in Evolution that are really welcome. I’m quite pleased with the upgrade.

My Bluetooth seems to have broken (my send image from phone to laptop didn’t work). I haven’t had time to debug yet.

Is it just me or do fonts look a bit better too?

I’m probably going to run beagle soon too.

The new version of Deskbar seems to work a lot better. I’ve noticed I’m using it more. Although is it worth 37MB of RES memory?
Tomboy seems to have gotten a bit better, but I’m still experiencing a bug where if i click anywhere that there isn’t text in my “Start Here” note I get a new note with some random large chunk of text from my “start here” note. I credit tomboy with a lot – namely a boost to productivity and not loosing notes. I massively heart it.

I’ll be trying MonoDevelop again to see how easy it really is to whip up something quickly. In breezy things seemed to crash too often to be useful.

The support for switching between audio output devices is much welcomed. However, there still seems to be some bugs – especially related to USB audio devices. I have an iMic here that I bought years ago and am again using since the headphone port on my laptop seems to be having problems (electrical connection related, not software).

Liferea (feed reader) has a lot of improvements. I think it’s chewing less RAM too.

I had to fiddle with my keyboard layout things to get my DVORAK layout working properly. It still seems as though Ctrl-Alt-Left Arrow (and Right) to switch between Workspaces only works for the left cntrl and alt – not the right ones (that are closer to the arrows). Although now the little keyboard applet shows “USA” for Dvorak, “USA*” for QWERTY and “Swe” for Swedish.
My build of MySQL that I use (for important things – i.e. my invoices that make sure I get paid) that is typically a close-to-top-of-tree 5.1 install kept working after the upgrade – i.e .binary compatibility didn’t get boned. I did, however, need to rebuild some of my MySQL source trees afterwards (some linking with SSL foo failed, clean build fixed it).

I also did a fresh install from the Desktop CD under VMWARE on another machine. Quite nice installer.

I feel like I’ll move my Mum’s machine over to 6.06LTS very soon (this weekend) as I’m confident it’ll be a great release for her. I’m sure she’s going to love f-spot. I’m also going to introduce her to rhythmbox, Sound Juicer and possibly last.fm as she now has speakers plugged into her computer and a CD player in her car (okay, had it for a while, just slack in getting her up and running burning copies of CDs for the car).

I didn’t get Avahi out of the box after the upgrade… I wonder if I need this manually for the “Share my Music” feature of Rhythmbox to work. Installing now, so I’ll soon know.

I haven’t tried Ekiga (GnomeMeeting, but new name) Internet Phone yet with any SIP things. Since I have a physical SIP phone (a SNOM-190) I may not really use it (except when travelling). Good to test at some point though.

The real OpenOffice.org 2.0 is much overdue – as I’ve sworn rabidly about before. Big difference being this version actually works.

A very worthwhile upgrade IMHO.

The next box to get the upgrade will by my MythTV box – or Mum’s. But probably both this upcoming (long) weekend.

[1] I, of course, have up to date backups and a quick disaster recovery process (get machine, xfsrestore / and /home, continue working). However, this is a pain in the arse.
[2] This may be wrong… “du -sh Maildir” just takes too damn long. My Maildir is currently 1.7GB in a tar.bz2 archive.

RealNetworks is still clueless (and amazingly not broke yet)

(note that this entry is in the “Inciting Hatred” category. it is not meant to be well argued or anything. I’m ranting. get-over-it).

RealNetworks rep to Linux: DRM or die!

You need DRM about as much as you need anything containing the word “rectal”. Nothing good is prefixed by the word “rectal”. Even if you like it that way – the only time the word rectal is ever used in that context is to do with disease.

Mind you, if you consider all the shit music that’s pumped out these days, maybe if it’s all locked up in DRM and I never see or hear it the world will be a better place. That’s right Robbie Williams, I’m looking at you.

Can anybody remember a time when Real shipped a product that anybody actually wanted to use? No? Well, that’s because they never have. Apart from the wow factor of being able to get audio (and then video) over the Interweb (err… net it was back then)  it just felt like they hated you. I am still bitter about that linux ppc build that couldn’t even pause reliably.

Even Microsoft did better with their Windows Masterba…err.. Media Player. For a start, I’ve seen somebody use it in the past six years.

So an irrelevant company is saying something stupid and wants to rob me of my freedom.
Say NO to DRM. Also say no to drugs – but mostly say NO to DRM.

crash halfway through upgrading Ubuntu breezy to dapper

see BUG#37430 for some details. Also see BUG#37435 for why it gets really painful later on.
Basically, if your machine crashes around the time of the dist-upgrade, you’re totally screwed. mkfs and re-install.

I’d hate to have not made /home a different partition from /.

I currently don’t have much confidence in an easy upgrade for my laptop considering what I’ve just gone through for my desktop. I’m now downloading the flight 5 install CD so i can re-install from stractch. urgh. not happy jan.

My recommendation for upgrade is a full backup of everything beforehand and if anything even remotely goes wrong, restore the backup.

Naturally I didn’t do this for the desktop. but hey, the laptop is more critical. I’ll be doing it for that, as I always do.

OpenOffice.org2 frustrates me like paper cuts

Possibly Ubuntu’s fault too for shipping the not-latest un-bugfixed release. But either way, it’s really annoying seeing the “Document Recovery” screen more than the edit text widget.

Copy and Paste slides in Impress is not flakey – it’s damn right crushed to pieces. Occationally it does something useful – like paste and not crash.

update: yes, i am just using it to put together presentations for our upcoming devconf – as well as the user conference. Why these things are so hard to do is beyond me. A simple app that didn’t crash *cough* magicpoint *cough* is looking rather superior at the moment.

update part 2: yes, the title changed. arguably i like this one better. although adding “right under the fingernail” is tempting