I have always been intimated by people who work on Linux kernel. This May I had the opportunity to make my own module. So here is my take on this.
The first thing that is required is the latest kernel on a VM. Yes VM is the most important thing …. you do not want your machine to crash or lose data or get your RAM fried ;). After having the kernel ready (make sure you compile the kernel so that you have the sources and all the kernel development flags are set) go through a good tutorial which helps you with the Hello World module …. you have developed your own module.
Easy right … but the pain is yet to come. Lot of help with sample codes can be found by googling .. but not all can be used directly. Before using the code snippet one needs to make sure about the kernel version thanks to the changing api’s for each release of the kernel. So what do you do from here. Copy the code snippet, compile and hope for the best. If it does not compile, you know you are facing changed API .. the best thing to do in that case is to check the header files and fix the function calls. The comments in the header file are excellent and they guide a noob well on what all needs to be touched and what need not be.
Here are some nice Links which I found:
Some code snippets
TIP: Do not be scared to try out things … worst (and most) case is a reboot 😉
TIP: Install logrotate as the log file will be becoming long very soon
TIP: The kernel stack space is only 4KB do not allocate space that is more than this
I will be adding more tips as and when I remember them till then …..Happy hacking
After I got through GSOC, I was really committed to open source and had decided that I would keep contributing to the community. But come August and things changed. After I started my graudate studies time could no longer be found for open source development. Writing this blog entry after 4 months is a proof of how busy a grad like can be. I was fortunate to have good mentors like Anant and Elizabeth who took phpCairo from where I had left it. I would like to thank and apologize for the same.
On the bright side, I did make some projects that I am going to open source. On of them is a peer to peer file system with no centralized server. Tough this project was made for grading purposes but the spec can be easily changed to what ever is required. It taught me a lot and hope it comes useful to someone else 😛 .
Anyway I am looking forward to mid December to take a big break and if things go as planned I would love to get in touch with phpCairo again.
Yes … After a lot form filling(Trick Form) I have been granted the cvs access where i can push the cairo bindings (which was phpCairo) on to PECL.
Lot of things changed on the way … the entire naming convention of each method was changed to Camel Case … Apart from that I had to remove all the traces of phpCairo and so its only Cairo now (Not so cool) .
One of the best (worst) challenges came when I had to return a CairoContext object from php-gtk … Initially I had not planned for it so I had to do lot of further changes and tested it first on a sample extension and then moved on to php-gtk …. As the methods were not defined in php-gtk I asked my mentor Elizabeth to help me out. After some struggle with php-gtk (a noob in that) I could return the CairoContext object ….
But the problem was far from solved. In spite of getting the object we were having difficulty in getting it printed …Again Elizabeth came to rescue and wrote an excellent gtk+, pygtk converted php program and gave it for test .. Hurray it worked !!!!
As of now it seems everything is working properly but Elizabeth just informed me that C gurus will be checking the cairo extension … so now I am waiting cross-fingered …..
Its time I pushed my extension …. before that I would like to thank both my mentors … Anant and Elizabeth for there support throughout the process …. Thanx for solving my stupid doubts …
Its been a long time since I have posted anything … This might be due to the fact that I have learnt nothing new (which is not possible) or I had no time(Please kick the mentor for that).
After a month of awesome coding finally phpCairo 1.0.1 is complete and is all set to be a part of PECL. The basic functionalities are up and running now only the intricate ones are left to sort out which will be corrected as they are brought forward (The beauty of Open Source).
Along the way there were lot of renaming of files and functions due the the PECL nomenclature which really bugged me but I guess it is required to maintain the uniformity in various extensions.
I could not write the module tests as there are around 300 modules so I have included various examples and there output so that people who want to use phpCairo can learn the syntax fast.
I am looking forward to start my work on php-gtk and use my own extension to integrate with it :).
Thanks a lot Anant and Elizabeth.
This is for my mentor …
The Path class and the Pattern class have been completed ….
I have tested them to some extent .. but intensive tests are still to be carried out …
Any way …
Just thought of documenting all the pit falls that I went through 😉 :
1. For returning an object from a method use init_object_ex() instead of init_object() as this would help one to distinguish the object then and there so that there is no ambiguity.
2. Never forget to increase the reference count of an object so that the object is not destroyed earlier than expected .. believe me it can happen !!!
Well I am not able to think about other pit falls that I came across … but will surely update this as soon as I remember one …
Till then … as my mentor puts it … “Show me the code !!!”
After some struggle with overloading the constructor in “c space” the surface class is also done…. So that make the class count to 2 but now we can draw anything on any surface … So whats left now …
There is a need to finish the pattern class and path class. Apart from that I have not implanted the functions that are new to Cairo 1.6 (‘cause I have to install it first ;)) and lot of testing on different environments.
For overloading the constructor please accept all the parameters by using the function call get_parameters() into an array of zval * … now check for all the parameters and get there corresponding data types ….
Its been a long time since I have taken a break 😉 … so signing of for an awesome weekend ….
Cant stop myself from writing this post … I need to tell someone how the code will look on the php user space 😉
Yes this tutorial is about implementing the Hello World Program 🙂
PHP Code :
$sur = new CairoImageSurface(0,400,400);
$con = new CairoContext($sur);
$con->set_source_rgb(1.0, 0.0, 0.0);
End PHP Code
After lot of frustrating moments (Hey coding is all about that) the context class is complete baring a strict testing ….
The good news is that it has passed the first test and I was able to implement the Hello World program …. 🙂
One major issue that I came across was the representation of various return values … At the moment everything is being returned as associative arrays but this can be changed if the need arises. ….
Forgetting all that it is an accomplishment so ….
After a long break … work has been resumed.
Finally I could see the version number of phpCairo … so I am all set up now to test all the functions that I have written.
The most useless part was the deforestation of the config jungle … added the cairo library and the linking support during compilation.
So things going good for the moment except that I am a week behind my schedule .. need to work harder to compensate for it.