Archive for the ‘code’ Category

Knowledge++

Sunday, April 4th, 2010

Nine days ago, I made an off-hand remark in #content that I might be able to get the geolocation service working in Fennectrolysis by the end of the day if my plans worked out. I also remember referring to the process as “not a big deal.” Since that moment, I have put in a significant amount of work (at least several hours every day), and learned:

  • My estimating skills are severely underdeveloped
  • How to make use of the cycle collector
  • How weak references work
  • Best practices for XPCOM reference counting
  • There’s a confusing thing called nsIClassInfo which I should learn more about, but I know enough to force it to do my bidding for now
  • How non-modal prompts work
  • The meaning of obscure GCC linker errors like “undefined reference to vtable”
  • How to implement an XPCOM object in Javascript
  • Implementing XPCOM objects in Javascript frequently results in much more pleasant code than C++

Having said all that, yesterday I got the Fennec geolocation permission prompt to appear when triggered by a content page, and the proper callback was called when I allowed or canceled the request, so I’m confident that I can have a patch up for review by the end of the holiday weekend. Of course, given my track record, that means it might be up by the end of the week.

Faster mercurial patch queue merging with emacs

Monday, March 1st, 2010

As a follow-up to my previous post about merging mq reject in emacs, I thought I’d share some improvements to the process that I’ve made since then.

(defun switch-hg-reject ()
  (interactive)
  (let ((other-file
     (if (string= (substring (buffer-file-name) -4 nil) ".rej")
         (substring (buffer-file-name) 0 -4)
       (concat (buffer-file-name) ".rej"))))
    (if (file-exists-p other-file)
    (save-selected-window
      (switch-to-buffer-other-window (find-file-noselect other-file)))
      (message "No alternate reject file found"))))

(defun kill-hg-reject ()
  (interactive)
  (let ((reject-file (concat (buffer-file-name) ".rej")))
    (kill-buffer
     (find-buffer-visiting reject-file))))

(global-set-key (kbd "C-c r") ’switch-hg-reject)
(global-set-key (kbd "C-x r") ‘kill-hg-reject)

It turns out that swapping back and forth between the reject and the original in a single window felt was quite inefficient. With these changes, the reject opens up in another window (think emacs terminology here) on C-c r, and I can kill it later with C-x r. This also works better with other modules like uniquify – the code from the previous post would fail when trying to access rejects associated with buffers name “Makefile.in|ipc”. No longer must you suffer the indignity of process! Merging can, and should, be fun! BEHOLD MY WORKS AND DESPAIR.

Cross-compiling with MinGW on Fedora

Tuesday, February 2nd, 2010

My goodness, I’m impressed. Having released the first iteration of my robotic debugger, I was informed that the fork()/exec() combo isn’t portable to Windows. Nobody volunteered any patches immediately, so I decided to read up on cross-compiling since I really dislike having to reboot into my other partition. Turns out that the entire MinGW stack has been packaged up for Fedora, meaning that all I had to do in the end was:
# yum install mingw32-gcc mingw32-gcc-c++ mingw32-libpng mingw32-SDL
$ mingw32-make -j2

It wasn’t quite that easy – since Megazeux uses a non-standard configure script, I had to correct a few faulty assumptions. I never figured out the correct way to use

/usr/i686-pc-mingw32/sys-root/mingw/bin/sdl-config

instead of the default one, so that got hardcoded somewhere. Also, Megazeux relies on libogg and libvorbis, which haven’t been pushed to the fedora repository yet (packaging limbo ahoy!), but I was able to grab some rpms that the mingw32 packager helpfully left lying around. All in all, a very successful and satisfying experience.

Dealing with mercurial patch queue rejects in emacs

Wednesday, January 27th, 2010

Since Mozilla has embraced mercurial, and especially patch queues, with open arms, I get to deal with rebasing patches frequently. There are two ways this can happen – either you set up an external merge tool like meld to handle each conflict, or the rejected changes are dumped in a filename.ext.rej in the same directory as the file being patched. Since I do all of my work in emacs, I’ve finally got around to writing an elisp function to allow me to switch to a reject file from the original quickly and painlessly:

(defun switch-hg-reject ()
  (interactive)
  (let ((other-file
     (if (string= (substring (buffer-file-name) -4 nil) ".rej")
         (substring (buffer-file-name) 0 -4)
       (concat (buffer-file-name) ".rej"))))    
    (if (file-exists-p other-file)
      (switch-to-buffer (find-file-noselect other-file))
      (message (format "No alternate reject file found" other-file)))))

(global-set-key (kbd "C-c r") ’switch-hg-reject)

A simple C-c r is all it takes to switch from nsFrameLoader.cpp to nsFrameLoader.cpp.rej in the current buffer, and another C-c r will take me back to the original. Now that’s convenience!

Building Rosegarden trunk

Friday, January 15th, 2010

I’m working my way through building Rosegarden from SVN on Fedora 12, and thought I would jot down my settings for posterity. My default QTDIR was incorrect for Qt4 (/usr/lib/qt-3.3), which made configure fail. Following a patch in a gentoo bug for the ebuild package, I ran configure with the following inscrutable command line:
./configure --prefix=/usr/local --with-qtdir=$(pkg-config --variable=prefix Qt) --with-qtdir=/usr