KiX Logo

Conferences

php|tek

Photos

www.flickr.com
AnantN's photos More of AnantN's photos

Music

Anant Narayanan

Welcome to my home on the Internet!
I am a freelancing software developer and technical author with a keen interest in emerging Free/Open Source Software. I am also an active developer in various FOSS projects, the most prominent of them being GNU Parted, Gentoo Linux and PHP-GTK 2, among others.

Download/View my Resume: [PDF], [HTML], [TXT]

The best way to contact me is through email: anant [at] kix [dot] in. If you wish to send encrypted email, here's my GPG key. You'll also find me on:

IRCKillerX on Freenode, SlashNet and Gnome
Jabberanant [at] cweiske [dot] de, tg.killerx [at] gmail [dot] com
Yahooanantnarayanan
ICQ237755525

Have a good look around, you might find something interesting! Use the links on the top to navigate. Have Fun!

This website is hosted by the courtesy of Christian Weiske. Thanks Christian!


From my blogs...

Across The Stars |  Summer of CodeTM |  PHPThrowDown 07

View all blog entries at Planet KiX.


Object Oriented PHP Extensions

Before I begin, if you’re using Gentoo Linux, don’t forget to check out the plan9port ebuild I recently made.

The Summer of Code has officially started - and I will begin my blogging with a quick post on creating object-oriented extensions to PHP, which is what the first phase of my project is all about :)

There isn’t much documentation on building OO extensions apart from the README series in the PHP source. If you’re looking to build a conventional procedural extension, however, I’ve found that the 3-part tutorial series on Zend by Sara Golemon is most useful.

I’ve chosen the libixp (pronounced as lib9p, get it?) library to wrap over. libixp is a small and clean C library that helps you write 9P servers and clients and should serve as a great base for the PHP extension. Incidentally, libixp’s current maintainer is Kris Maglione; one of my fellow SoCers! Anyway, the first thing I did was to run the ext_skel script for my new extension but quickly found out that you can’t have PHP extensions that begin with a number (I wanted to name the extension 9P). Rinse and repeat with an extension name of ‘ixp’ instead. Now what?

Marcus Börger had presented a talk on “Implementing PHP 5 OOP extensions” at php|tropics, which, though a bit dated, served well as a guide. The bundled util extension is a good example of some OO code in action. However, as time progresses, I realized that creating a class and setting its properties in itself was getting *very* monotonous. Surely, this wasn’t code that was meant to be typed in by humans; after all, why code when the computer can do it for you?

Yep, Code generation to the rescue! PEAR has a neat package called CodeGen_PECL that takes an XML description of your extension and generates not only the extension code, but also skeletal documentation to go along with it! No more worrying about naming conventions and other such menial stuff - you get straight to coding. Indeed, this is how programming should be. I will recommend this extension to anyone trying to build an extension to PHP, *especially* if you’re creating an OO extension (given the lack of documentation and Zend’s clunky object system for PHP5).

Now that I had a neat little skeleton of my extension (CodeGen_PECL indents and comments the code for you too) all I had to do was to begin actually implementing the methods. The client portion of it wasn’t such a big deal, but when I started to code the classes that would help you create a 9P server, I hit a roadblock. libixp expects me to pass a bunch of function pointers, one each for every 9P operation (read, write, clunk, attach etc… more details in the 9P specification). I now have to think of some way to map that to the PHP way. Tricky, but the answer lay quite close to me.

I’ve been working with the PHP-GTK team for quite some time. In fact, it was my first experience with open-source projects in general. PHP-GTK is an OO extension that wraps over the Gtk+ toolkit. Gtk+ has a ton of functions that expect function pointers, their whole signal-callback system is built that way. PHP-GTK maps this behavior to the PHP way by creating a “marshaller” function for every type of function pointer, that expects the same arguments as the function pointer is given. While this marshaller function is passed to the C-level Gtk+ methods, PHP-GTK maintains a separate callback structure that stores the Zend object for the corresponding PHP-level function. Gtk+ (thankfully) provides an extra gpointer for the developer to pass around their own data to callbacks, and PHP-GTK uses this to pass around the callback structure. When the marshaller function is called, it simply reads the callback structure and invokes the PHP-level function with all the parameters that it received (after appropriate conversion of course).

Cool, I could do the same thing with libixp! Except libixp doesn’t allow me pass custom data to callbacks:

typedef struct Ixp9Srv {
  void (*attach)(Ixp9Req *r);
  void (*clunk)(Ixp9Req *r);
  void (*create)(Ixp9Req *r);
  void (*flush)(Ixp9Req *r);
  void (*open)(Ixp9Req *r);
  void (*read)(Ixp9Req *r);
  void (*remove)(Ixp9Req *r);
  void (*stat)(Ixp9Req *r);
  void (*walk)(Ixp9Req *r);
  void (*write)(Ixp9Req *r);
  void (*freefid)(Fid *f);
} Ixp9Srv;

Hmm. Luckily, I’m bundling the libixp sources with the extension; it’s a –with extension, not a –enable one ;)
I guess I can hack up the libixp sources to allow for passing this extra data around to the callbacks. Let’s see how this goes!

Until next time, Happy Hacking!

Back to Top


Experience Plan 9 on Linux!

Plan9 is an operating system that is designed to make up for all the mistakes that UNIX made. And it’s quite different from any of the current UNIX clones, be it any of the BSDs or Linux. To ease the migration, there’s a project called Plan9Port; which is essentially a port of several Plan9 utilities to the POSIX platform.

I recently made an ebuild for  Plan9Port, also called Plan from User Space. Just ‘emerge plan9port’ and spread the Plan9 love!

Speaking of which, my Summer of Code project for Plan9 is progressing well. More details on my SoC blog, or the aggregator at KiX. Laters!

Back to Top


And so it begins

Yay, the Summer of Code has officially started! The last one month has been really fun for me - I’ve been hanging out with the folks at Plan 9 from Bell Labs and it’s been an amazing experience.

The Plan9 philosophy is a lot different that any of the other UNIXes. I mean, a *lot*. Not surprising though, since Plan9 is meant to *replace* UNIX. The one thing I love about Plan 9 and its associated applications is the way that the code is written. Almost all of the UNIX applications were re-written in Plan 9, and all of the code is written precisely with the notion that other people are going to be reading it. Plan 9 subscribes to the KISS philosophy (critics of Plan9 call it the Worse-Is-Better philosophy!), and would rather maintain cleanliness and readability of code than anything else. Again, not surprising; the chief architects of the Plan 9 system are also the authors of “The Practice of Programming“, an awesome book that teaches you how to write *good* code :)

Plan9 is also rich in documentation. It’s split into two Volumes: Volume 1 consists of the traditional programmer’s manual - the whole set the manual pages in the system, while Volume 2 is basically a collection of papers written by several people involved in the development of Plan 9 over the years on variu

Every time I ask a question on #plan9, the response is almost always RTFM. Not all projects can claim that, you know! Coming in from “lunix-land” (that’s how the Plan 9 developers put it), I was bound to have a lot of questions. Apparently, using Linux over the years has clouded my thinking ;)

It feels great to be working on something that is the direct product of some of the greatest people in the field of Computer Science. While looking through the 9fans mailing list, I came across some really great posts. Here’s a sampler: this one is by John Carmack on whether porting Quake to Plan9 will be a good idea, and this one by Charles Forsyth on why Plan9 is different from Linux.

Just yesterday, I had a rather long debate with my mentor on whether patents were actually evil or not. Which goes to say that we don’t always talk about technical stuff - conversations in #plan9 are always animated.

I’m loving it!

Back to Top


Unlimited Humor

If you’re feeling bored of the Internet, check this site out. I guarantee you hours and hours of laughter. ’nuff said :)

Back to Top