You are here

elliotth's blog

elliotth's blog
Checked: 2 hours 25 min ago
Updated: 2 hours 25 min ago
Update every: 2 hours

Java, C++, Android, Linux, Mac OS, programming. Something for everygeek.
Subscribe to elliotth's blog

How (not) to use readdir_r(3)

elliotth's blog - Fri, 26/10/2012 - 9:15pm

TL;DR: always use readdir(3) instead of readdir_r(3).

I spend most of my time fixing bugs. Often I feel like there's something instructive to say, but I don't want to be that guy who's known for pointing out faults in other people's code, as if his own doesn't have bugs.

Today I have a great one, because although there's a lot of blame to go around, the bug that actually caused enough trouble to get reported is my own.

Here's an AOSP patch: libc: readdir_r smashed the stack.

How to read Dalvik SIGQUIT output

elliotth's blog - Fri, 31/08/2012 - 10:02pm

If you're a long-time Java developer you're probably used to sending SIGQUIT to a Java process (either via kill -3 or hitting ctrl-\) to see what all the threads are doing. You can do the same with Dalvik (via adb shell kill -3), and if you're ANRing the system server will be sending you SIGQUIT too, in which case the output will end up in /data/anr/traces.txt (see the logcat output for details).

Anyway, I've found that very few people actually know what all the output means. I only knew a few of the more important bits until I became a Dalvik maintainer.

gettid on Mac OS

elliotth's blog - Wed, 04/04/2012 - 9:47pm
The Linux kernel has a gettid(2) call that returns the current thread's thread id. These numbers can be handy. They're useful for debugging/diagnostic purposes, they're useful in conjunction with other tools, and they're using for pulling stuff out of /proc/<pid>/task/<tid>/.

But what about code that needs to run on Mac OS too?

operator&lt;&lt; and function pointers

elliotth's blog - Fri, 09/03/2012 - 6:58pm
This one fools me all the time. Maybe if I write it down I'll remember.

What does this code output?
#include <iostream>
int main() {
std::cout << main << std::endl;
return 0;

When I see a function pointer shown as "1", my first thought is "Thumb2 bug". ARM processors use odd addresses to mean "there's Thumb2 code at (address & ~1)", so a code address of 1 looks like someone accidentally did (NULL | 1).

Beware convenience methods

elliotth's blog - Sun, 01/01/2012 - 11:09pm
The Android documentation links from various methods to Beware the default locale. It's great advice, but most people don't know they need it.

I've never been a great fan of convenience methods (or default parameters), and methods that supply a default locale are a prime example of when not to offer a [supposed] convenience method.

ThinkPad &quot;plugged in, not charging&quot;

elliotth's blog - Fri, 23/12/2011 - 6:30pm
The web is full of all kinds of advice if you find yourself with a ThinkPad running Windows 7 that refuses to charge. The message "plugged in, not charging" being what you see in the tool tip if you hover over the battery icon in the system tray. (The Windows battery icon, that is, not the Lenovo one next door. I love the way Lenovo ship their own battery and wifi widgets, so you get two of each, and I really love the way that -- unlike the Microsoft ones -- the Lenovo ones get stretched and blurry at screen resolutions that Lenovo ship. Nice touch.

How can I get a thread's stack bounds?

elliotth's blog - Thu, 22/09/2011 - 5:18am
I've had to work out how to get the current thread's stack bounds a couple of times lately, so it's time I wrote it down.

Language-induced brain damage is better than the alternative

elliotth's blog - Sun, 29/05/2011 - 12:03am
Whenever old uncle Edsger had had a skinful, he'd rant about the harmful effects of bad languages on programmers. As a kid, I was never particularly convinced. He was too old to be all that concerned about C, and Ada hadn't even been invented yet, let alone Java, so his rants about Fortran, PL/I, Cobol and APL all seemed comically anachronistic. The languages he'd talk about were all pretty moribund anyway, at least for the purposes of a software engineer (as opposed to, say, a physicist).

Fuck Sony

elliotth's blog - Thu, 19/05/2011 - 4:55am
So the only reason I use my PS3 any more is for Netflix. It sucks hard when it comes to anything else. It's a crap DVD player compared to the 360, cross-platform games are usually better on the 360, the platform exclusives are usually more interesting on the 360, and the PS3 doesn't even work as reliably with my Harmony remote as the 360 does.

And that's ignoring the PS3's UI shitfest.

Ubuntu 11.04

elliotth's blog - Sun, 15/05/2011 - 8:39pm
If Mac OS is the continuing evolution of Steve Jobs' vision of how we should use our computers, it's becoming increasingly clear that Ubuntu is Mark Shuttleworth's indirect request that we all just fuck off and get ourselves an OS from someone who actually gives a shit.


signal(2) versus sigaction(2)

elliotth's blog - Wed, 04/05/2011 - 10:00pm
Normally, I'm pretty gung-ho about abandoning old API. I don't have head space for every crappy API I've ever come across, so any time there's a chance to clear out useless old junk, I'll take it.

Java benchmarks

elliotth's blog - Tue, 14/09/2010 - 5:14am
Performance is half my job. The other half is correctness. Both are important, but it's performance that tends to grab the headlines.

I admit: not all comments are crap

elliotth's blog - Sat, 03/07/2010 - 6:42pm
This very week in meatspace, I claimed that adding a commenting facility to a website is like handing out marker pens to everyone who enters a public toilet. The results are obvious, and with very rare exceptions, don't really improve anything for anyone.

Keep Enjoying Great Gold Benefits

elliotth's blog - Sun, 18/04/2010 - 1:56am
Judging by the way my Xbox keeps hinting I might want to renew my Xbox Live Gold subscription (USD50/year), I'm guessing my Xbox Live Gold subscription is soon to run out. To help persuade me, there's a sort of "click here for an ad" thing in the Xbox's UI, and when I click (or, in this case, hit OK on the remote), I get, under the title "Keep Enjoying Great Gold Benefits" this list:

  • Online multiplayer
  • facebook
  • twitter

A system software update is required

elliotth's blog - Sat, 20/03/2010 - 4:26am
I turned the PS3 on this evening, for the first time in months. I wanted to try the Heavy Rain demo. My PS3 didn't want to play with me:

A system software update is required.

Go to [Settings] > [System Update] and perform the update.

o Back

Review: Uncharted (PS3)

elliotth's blog - Thu, 17/12/2009 - 5:02am
I didn't get "Uncharted" from playing just the first half hour, it took me a while longer. In fact, I didn't really get it until I had to shoot a barrel on the back of truck, causing both the barrel and the truck to explode, at which point the truck somersaulted toward me, falling neatly into a gap between two stone pillars and allowing me to safely pass from one pillar to another.

In retrospect I should have noticed earlier, but it wasn't until that point that it finally clicked: "I'm playing an action movie!".

Review: PS3

elliotth's blog - Mon, 02/11/2009 - 2:41am
The day Netflix and Sony announced Netflix streaming videos were coming to the PS3, my 360 died. Not metaphorically; it hung while playing a DVD, and power-cycling got me the red ring of death I thought I'd escaped.

Giving up on .dmg

elliotth's blog - Sun, 04/10/2009 - 6:47pm
Alexander Limi recently wrote Improving the Mac installer for Firefox (and also a part 2), where he basically explains all the ways in which .dmg is an awful choice.

John Gruber followed up with How Should Mac Apps Be Distributed?, in which he praised "the resurgent trend of delivering Mac apps as simple .zip archives".

Review: &quot;JavaScript: The Good Parts&quot;

elliotth's blog - Mon, 21/09/2009 - 10:33pm
JavaScript has always been a bit of a mystery to me. Every time I've had any contact with it, I've been left wondering why anyone in their right mind would have anything to do with it. Let alone what kind of criminal mind would have originally conceived of such an abortion. I've never found (or heard tell of) anything good about it, other than its ubiquity. The fact that JavaScript is built in to every browser, but no alternative is. As far as I can tell, it's this ubiquity that helps JavaScript cling to life like a daglock, despite being little more than hair matted with dried shite.

Farewell to Java 5?

elliotth's blog - Sun, 06/09/2009 - 9:52pm

You've probably read that Mac OS 10.6 has finally made Java 6 the default, and you may also have read that there are both 32-bit and 64-bit JVMs. (That latter part will only seem surprising to you if you'd been using Java 6 on 10.5.)

What I didn't know until I read Things Removed in Snow Leopard was that Java 1.4 and Java 5 have actually been removed from 10.5.

Java on a thousand cores

elliotth's blog - Fri, 21/08/2009 - 12:05am
Cliff Click wrote a recent blog post that started "warning: no technical content", which wasn't true. Buried 3/4 of the way through was a link to the PDF slides for the "Java on 1000 cores" talk he's been giving recently. I was in the audience of the specific instance of the talk he mentioned, but if you weren't, you can now watch the video on YouTube.

Removing the title bar from your Android Activity

elliotth's blog - Mon, 27/07/2009 - 5:42am

Sometimes you have a good use for the title bar – the gray strip beneath the system status bar – in your Android app. The Gmail app, for example, uses it to tell you which folder you're looking at and how many threads with unread mails are in that folder, for instance: "Inbox (52)".

Other times, you've got nothing worth saying.

Why find(1) doesn't like big directories

elliotth's blog - Thu, 16/07/2009 - 5:14am

A friend had trouble recently trying to use find(1) on a directory containing millions of entries. He expected it to start pumping out results straight away, but found instead that it went away for a long time. A quick strace(1) showed it steadily reading directory entries.

We could speculate about what's going on, or we could look at the source. Let's start by finding find(1):

$ which find

Then we ask the Debian packaging system which package installed that file:

$ dpkg -S /usr/bin/find
findutils: /usr/bin/find


elliotth's blog - Thu, 11/06/2009 - 5:58am

For some reason, I was under the impression that jvisualvm(1) was just a rebranding of jconsole(1). It turns out that it isn't, and that – unlike jconsole(1) – it's not a waste of space.

It's not very clever about dividing up space between its various graphs, but other than that it looks pretty nice. I thought I wanted a quick heap profile to see why one of my applications ate so much memory that my machine always felt swappy afterwards.

xargs -P

elliotth's blog - Wed, 10/06/2009 - 7:07am

Another entry in my occasional series of options Unix never had when I were a lad (last time: tail -F)...

I needed to use xargs(1) the other day to run lots of really cheap jobs, each of which had a high latency.

This was taking a long time until a friendly youngster suggested I use GNU xargs' -P option. Starting again with -P 32, my job finished in less time than I'd already wasted.


Subscribe to elliotth's blog