Page 1 of 1
Complicated port
Posted: Thu Dec 28, 2006 12:32 am
by alex.barylski
Admittedly, I've never ported anything more complicated than well known algorithms (qsort, etc) from C source to PHP...I'm thinking I might look into porting SQLite over to PHP...
Anyways, for the sake of disscussion, I ask. What are some applications/code you have successfully ported from one language to another (preferably C to PHP) and what were some of the complications you encountered?
Cheers

Posted: Thu Dec 28, 2006 2:21 am
by feyd
You mean port the SQLite extension to "pure" PHP?
Well, for myself the most complicated thus far was SHA256. After that was a Trillian decryption widget.
The only complicated parts were pointer logic changes and the fun of how in C literal characters are integers, but in PHP they aren't. SHA256 took about 24 hours to write; Trillian took about two.
Posted: Thu Dec 28, 2006 2:55 am
by alex.barylski
You mean port the SQLite extension to "pure" PHP?
Well not the extension itself but the core engine...SQlite...hehe...it would be really weird and useless to port the PHP bindings for SQLite.
The fact you mention pointers makes me think - when you port you litterally copy-paste and start hacking???
Personally I take a slightly different approach in that I read the code (original) and begin writing from scratch - thus avoiding pointers, syntax, etc...
I actually tried the other way but found It faster and easier in copying the code on a line by line basis rather than byte for byte. I find architecturally a system won't change but obviously at atomic levels (such as pointers, syntax, etc) it's certainly going to...
Did you use any cheats when automating your porting process? Regex to prefix variables with '$' signs, etc?
Cheers

Posted: Thu Dec 28, 2006 3:02 am
by feyd
It was all converted in logic, not by literal code.
The hurdle in the Trillian one was mostly due to the bit level math performed and getting lost in the nested array lookups that were performed mixed in. I pretty much had to pull apart the consolidated lines into precedence statements to get it right after trying to simply do a direct conversion. Nothing overly complicated though.
SQLite will be far more complicated.
Posted: Thu Dec 28, 2006 5:43 am
by Chris Corbyn
I imagine it will be slow. I thought about writing a very simple RDBMS in pure PHP making use of studying exisitng PHP implementations of the b-Tree but it's yet another "idea" I have on the back-burner.
I think it would be useful to write a flat-file storage system in PHP which you can interact with using SQL, but then you're walking into DBMS territory anyway since you need to know what you're storing and how much space to allocate on disk for it.
Posted: Thu Dec 28, 2006 10:09 am
by alex.barylski
feyd wrote:SQLite will be far more complicated.
Yup...but an interesting challenge
d11wtq wrote:I think it would be useful to write a flat-file storage system in PHP
Having a PHP based DBMS would be Kick @$$ IMHO...

Posted: Thu Dec 28, 2006 11:38 am
by Ambush Commander
And here am I thinking that I should port HTML Purifier from PHP to C++.

Posted: Fri Dec 29, 2006 3:41 pm
by alex.barylski
Ambush Commander wrote:And here am I thinking that I should port HTML Purifier from PHP to C++.

I haven't played with...but why would you? Speed?
I'm finding PHP has serious limits with anything complicated in terms of parsing, etc...not that I didn't know this before...as it's obvious a scripted language would run significantly slower...but when you actually try and see the difference...it makes you wonder...
Alot of what I want to do could likely be cached, but the initial stage...I dunno
Posted: Fri Dec 29, 2006 3:44 pm
by Ambush Commander
Yeah, speed would be the real big thing. Having a C++ library also facilitates getting it as a PHP extension or used in other scripted programming language.
No worries though. Something like that probably will not happen for a looong time, given my current skill at C++.
Posted: Fri Dec 29, 2006 3:59 pm
by alex.barylski
Hmmmm you should port it over to a C extension...could be worth investigating
