Older blog entries for redi (starting at number 18)

My second mod_virgule hack makes <diary>sab39</> a link to the latest diary entry for sab39. The tag's still <diary> although chalst proposed the tag be <redirect> or <quote>. <recent> might work too. Unfortunately I've had to type these links in by hand. It's much easier on my local mod_virgule with this hack running :-) Also hacked a patch to prevent a couple of segfaults caused by malformed requests.

I'm still ill today so I worked from home, and I got loads done. If I was able to play DJ Shadow insanely loud in the office maybe I'd be that productive every day. Not sure about everyone else in the building though. Mr Scruff's new album is so good I can't go without mentioning it. Jazz for trousers - nice.

22 Sep 2002 (updated 22 Sep 2002 at 20:53 UTC) »

Since Advogato's HTML subset is on topic at the moment, would anyone be interested if I knocked up a patch for mod_virgule to make <person diary="23">redi</> link to a particular diary entry, rather than just to the person's personal page? When referring to something in someone else's diary I prefer to link to the relevant entry, as otherwise cross-referenced diaries become harder to folow once the entry has moved off their personal page and/or recentlog. This would make it easier to link to a particular entry without using an <a> tag and entering the whole URL for the diary entry. Update: not so easy, doesn't look like mod_virgule can handle attributes on it's special_allowed_tags, something like <diary>redi:23</> would be needed.
Update 2: if it's wanted I've got a patch to do exactly that. Contents must be zero or more alpha-numeric characters (account name) followed by a ':' followed by zero or more of numeric characters (diary entry to link to).

I think I'm too ill too do any complicated coding today. I'm looking at more examples in Langer & Kreft's IOStreams book, and despite having made every single correction listed on the book's errata pages, I'm convinced their example code for a streambuf that does buffered input is broken. There are several places where a value is multiplied by sizeof(char_type) so byte-wise functions such as read(2) and memmove(3) will work correctly, but I'm sure they've applied it to the wrong values. Rather than multiplying the number of items by the number of bytes per item (to give the number of bytes) they've multiplied a pointer offset by the bytes per item. This is wrong, as the rules of pointer arithmetic in C++ take care of this anyway. Despite something like 200 errors being listed on the book's website, this hasn't been reported yet, presumably because the code's only been tested where sizeof(char_type) == 1 and so it makes no difference what you multiply by that size. I think I'd better go back to bed until my head's clear enough to decide if I'm right. I assume I'm not and when I read this diary entry with a clear head I'll be terribly embarrassed.

(John, if you read this, output is now fully buffered - just need to finish the input case and correctly switch buffers and states when changing between stdout and stderr - and figure out whether these examples are wrong)

20 Sep 2002 (updated 22 Sep 2002 at 01:22 UTC) »

fxn: re username filters in MyAdvogato, I'm not actually desperate for username filters, all I need to do is resist the temptation to read the latest stupid troll by you-know-who, it's sort of a sick compulsion to see what crap he'll spew next, and just skipping those entries is much easier and saves the trouble of maintaining an ignorelist external to my head. As I understand it your diary ratings report shows other users' ratings as seen by you. If you've rated someone directly the rating will appear with a confidence of 1, otherwise the confidence is a function of the distance (and certs?) between your user and the rated user. Update: It seems that if you've cert'd user A, and A has rated B's diary, then the rating you see for B is strongly affected by A's rating (in other words by cert'ing someone you've implied you trust their ratings more significantly than some random user. Presumably this trust of ratings propogates outwards with the web of cert's.

How I Learned to Stop Reinventing the Wheel and Love UNIX

This is going to read like a sales-pitch written by a marketing dept. but I'm just trying to get some ideas to coalesce. It's been at the back of my mind for a while, but I've only recently realised just how easily PStreams lets you tie together UNIX utilities in the same way as pipes do on the command line or in a shell script, letting you use existing tools directly inside your C++ program. Noone writing a scripting language would write their own text manipulating functions, they'd use an existing tool such as sed, but C++ programmers all-too-often reinvent the wheel, because to call external programs you have to set up the necesary pipes, call fork(), exec(), wait4() etc. With PStreams all you do is instantiate a single object, which takes care of calling and error-checking all those functions, and then you write to and read from the process as with any IOStream object. To be honest I'm rather surprised this hasn't been done a thousand times already. While I was writing it I read an article in CUJ Binary Code Reuse in a Linux Environment where "Traditional UNIX-like filters meet C++" which is pretty similar, but the interface is IMHO far less natural than with PStreams, and it doesn't map as well to the familiar syntax of pipes on the command line. Somehow I seem to have almost accidentally created a useful and powerful way to write C++ programs as you'd write shell scripts, and AFAIK there's no existing Open Source equivalent. Blimey, can that be right? Surely not. All I was doing was scratching an itch.

My plans for the library are to abstract the creation and control of the new process from the I/O facilities of the existing classes, which would provide a general-purpose process management class for C++, that could be used to implement the PStreams classes. Someone please stop me now if this has been done (well) already.

It's a good thing this is only a tiny project (in terms of lines of code) as I'd never finish it otherwise. It'd be done in a week if I stopped getting wasted every night and finished adding buffering to the stream classes. Not tonight though, it's friday, so I'm going for a pint.

18 Sep 2002 (updated 18 Sep 2002 at 17:53 UTC) »
joy: FreeBSD 4.6 uses its own release of GCC (2.95.4 20020320 [FreeBSD]), which includes <sstream> and has a standard-comforming std::string. Hoorah! Since our development where I work is done on FreeBSD and we can't just switch to GCC 3 (adding std:: quals alone would take weeks!) this is great news as far as I'm concerned. I can track down and remove all my comments along the lines of "have to do it this way because of GCC 2.95". This has also reminded me to check if GCC 3 supports covariant return types on virtual functions yet...

bugs: Found (and reported, of course) another possible bug in MySQL. I still need to find time to prepare a test case for an issue that was crashing our web sites, where DELETE FROM tbl_name WHERE column IN (...) doesn't complete. Also found what I think is a security hole in FreeBSD, but I need to do a bit of testing and check if it's still there in 4.6 to be sure. (Updated: I should point out the most likely explanation is I'm completely wrong, so don't panic :)

fxn: re filters in MyAdvogato, I think name-based filters are my most wanted feature. 'nuff said.

Going home in a minute to watch some footy and maybe hack some PStreams.

I'm adding buffering to the PStreams stream buffer class (it's currently unbuffered, which isn't an oxymoron, honest) and have found some errors in Langer & Kreft's IOStream book so I went to find the errata, and found that my first printing has quite a few errors. This isn't the first time I've wished I could exchange a 1st printing for a discount on a corrected one, as these things ain't cheap. I'll have to be more patient and wait for a reprint of the next new book I want to buy. Unless I find way to patch hardcopy I'll have to take sharp pencil to the book tomorrow.

I've also started abstracting the creation and control of the child process to a separate class to separate the responsibilities of the streambuf. I keep being pleased with the results of applying received programming wisdom even on such a small set of classes as I'm writing. The code is so much simpler when the design is right.

14 Sep 2002 (updated 11 Oct 2002 at 14:33 UTC) »

Finally got djbdns running at home. For some reason it took me ages as I kept putting the wrong addresses in resolv.conf, or the dnscache environment, or something else over and over again. I think setting bind up would have taken me longer, and I wouldn't have been confident I'd done it securely. Learning a bit about DNS doesn't really make up for being ill and missing a band on a friday night, but my computer's a bit better now. bah. I think I quite like DJ Bernstein's svscan alternative to init.d for starting and stopping services.

bgeiger: to get Mozilla to do a tooltip style popup use the title attribute. The standard specifically says it can be rendered as a tooltip in visual browsers, it says no such thing for alt. title can also be applied to any element, not just <img>, try it with <span> around some text (in a good browser anyway). If you must use tooltips you can put the same text for alt and title to do a tooltip that works in Netscape4, Mozilla, Konqueror, Opera and IE. And that's why Mozilla won't change. A more accessible reference here
Update: oops, that "more accessible reference" was a local file on my hard drive! Fixed to point to the online version

11 Sep 2002 (updated 14 Sep 2002 at 15:22 UTC) »

A fair bit of work on PStreams over the weekend, not much sleep, but lots of big ideas for where to take it once the current work is done and it's feature complete. More on this soon, once I've thunked a bit more and need to make some notes for myself. I had to get out of bed the other night to scribble some ideas down that had come to me as I was drifting of to sleep. I would have been able to remember them fine in the morning, but they were burning a whole in my head and I had to write them down to so I could go to sleep. I've learnt a lot from doing this project (what's used in the code is only a fraction of it) and it's interesting to look at the progression of my ideas and how they and the classes coalesced into the current design. Interesting for me anyway. I don't expect anyone else is even reading this. Go read a good book instead if you are, you'll get a lot more out of it.

Reminder: track down SIGPIPEs on Solaris and see why they're raised there and not on other platforms. Hmm.

Reminder: check the latest code into CVS. It's functionally better than the previous version, has more features, and I'll not be able to implement my big ideas for the future until it's in. done

Some responses...
goingware: Happy birthday to your mother and aunt. I'm about to go see a friend who's birthday it is today as well. I don't think he's been looking forward to it much, with the other significance this date has now. He owns a pub though, so I imagine we'll all get into birthday mood eventually. You can't let every birthday be ruined because something tragic happened on that date. There's no logical reason why today should be any more upsetting than the 100 day anniversary, or 1000 days. But that's logic for you.
fxn: Glad to hear there'll be a filter on recentlog. I'm not sure I'd use it often (some unrated people have interesting things to say) but it could be useful sometimes. Will it only work on diary ratings? Or on cert level and/or username as well? The diary ratings include other people's ratings, which might someone who's scribblings you enjoy reading are filtered out because everyone else has rated them down. Ignore me for now, I'll have a look when you release it.
mtearle: I got someone to download OpenOffice to install at their workplace today. I'd mentioned it before, and he phoned me up to ask about it, as he didn't want the hassle of finding out whether they were licensed to install another copy of Office, and the hassle of using Office! I hope he's happy with it.

4 Sep 2002 (updated 4 Sep 2002 at 18:16 UTC) »
mathieu: I was only half paying attention. Yes, line 3 might not behave as expected. You probably know this already, but I'm explaining for my own benefit as much as anything! The array initialisation in line 2 creates an array on the stack, of size strlen("this is a string you can modify")+1, and copies the characters in the string literal into the array. Line 1 assigns the address of the string literal to p. a is therefore an array of non-const chars that can be modified and line 3 is fine. p points to the actual string literal, which is an array of non-modifiable chars and so line 4 invokes undefined behaviour (on my OS the literal is in the text section of the executable, which can't be modified, but that's an implementation detail).

I agree that the code shouldn't be valid; if string literals in C had type const char [] instead of being "non-modifiable char" [] the problem wouldn't exist. Bjarne Stroustrup's doing an interesting series of articles in the C/C++ Users Journal at the moment about C/C++ compatibility and why C++ retains this sort of gotcha from C, rather than fixing the mistake and abandoning compatibility.

bjf: Have you looked at WML?
3 Sep 2002 (updated 3 Sep 2002 at 10:35 UTC) »

Passed the technical test thing I took last week for a job, so I'm in for an interview. I'm quite surprised, as although the test was very easy, I spent too long on the C++ section crafting the perfect answers and stupidly ran out of time and didn't write anything for some other chunks of it (and wrote complete rubbish for the database bit as I rushed to scribble something down.) Nevermind, I'm the only person to get through to the interview. Which is nice.

mathieu:

You're modifying a string literal. String literals in C have type (non-const) char*, but are non-modifiable, doing so invokes the dreaded undefined behaviour, so a coredump isn't too bad, you should think yourself lucky you didn't rupture a hole in the fabric of the universe. In C++ string literals are const, but as Stroustrup The Wise explains:

The type of a string literal is "array of the appropriate number of const characters," so "Bohr" is of type const char[5].
A string literal can be assigned to a char*. This is allowed because in previous definitions of C and C++, the type of a string literal was char*. Allowing this assignment of a string literal to a char* ensures that millions of lines of C and C++ remain valid. It is, however, an error to try to modify a string literal through such a pointer:
void f()
{
    char* p = "Plato";
    p[4] = 'e';  // error: assigment to const; result is undefined
}
This kind of error cannot in general be caught until run-time, and implementations differ in their enforcement of this rule.
Stroustrup, C++PL3E, ยง5.2.2

amars:

"Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians."
Edsger Dijkstra
I'm not sure I agree, but who am I to argue with Dijkstra?

9 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!