德国开元华人社区 开元周游
标题:
[news] Linus' First Analysis of the Files
[打印本页]
作者:
cyan
时间:
23.12.2003 12:10
Linus' First Analysis of the Files <br> <br>Monday, December 22 2003 @ 05:41 PM EST <br><br>Linus has taken a quick look at the files and has given permission for us to publish his first analysis. There will be more to say later, but the bottom line is that SCO appears to have made a copyright claim to some files that Linus wrote himself. I'll let him tell you about it, by reproducing his initial email to me from earlier today.<br><br>***************************************************************<br><br>I have a very strong memory of having written the original "errno.h" <br>myself too, and I really think that at least the i386 version of errno.h <br>actually has different numbers from "real UNIX". Some of the first ones <br>match, but not the rest. That one I explain by just having a list of error <br>codes, and just giving numbers in order, but maybe I'm wrong.<br><br>I have this distinct memory of figuring out only later that I _should_<br>have made the numbers be the same, so that I could have been binary<br>compatible. After all, I do actually have the book "Intel386 Family Binary<br>Compatibility Specification 2" (copyright Intel corporation, btw, not <br>SCO), and it lists the error numbers right there. They are different from <br>what Linux uses on x86.<br><br>Other architectures fixed that mistake, but the point is that the history <br>of "errno.h" is definitely _not_ from UNIX sources.<br><br>Linus<br><br>-----<br><br>For example, SCO lists the files "include/linux/ctype.h" and<br>"lib/ctype.h", and some trivial digging shows that those files are<br>actually there in the original 0.01 distribution of Linux (ie September of<br>1991). And I can state <br><br>- I wrote them (and looking at the original ones, I'm a bit ashamed: <br>the "toupper()" and "tolower()" macros are so horribly ugly that I <br>wouldn't admit to writing them if it wasn't because somebody else <br>claimed to have done so <!--emo&;)--><img src='http://210.51.184.178/kaiyuan/modules/ipboard/html/emoticons/wink.gif' border='0' style='vertical-align:middle' alt='wink.gif' /><!--endemo--><br><br>- writing them is no more than five minutes of work (you can verify that <br>with any C programmer, so you don't have to take my word for it)<br><br>- the details in them aren't even the same as in the BSD/UNIX files (the <br>approach is the same, but if you look at actual implementation details <br>you will notice that it's not just that my original "tolower/toupper" <br>were embarrassingly ugly, a number of other details differ too).<br><br>In short: for the files where I personally checked the history, I can<br>definitely say that those files are trivially written by me personally,<br>with no copying from any UNIX code _ever_.<br><br>So it's definitely not a question of "all derivative branches". It's a<br>question of the fact that I can show (and SCO should have been able to<br>see) that the list they show clearly shows original work, not "copied".<br><br><br>Analysis of "lib/ctype.c" and "include/linux/ctype.h".<br><br><br>First, some background: the "ctype" name comes "character type", and the<br>whole point of "ctype.h" and "ctype.c" is to test what kind of character<br>we're dealing with. In other words, those files implement tests for doing<br>things like asking "is this character a digit" or "is this character an<br>uppercase letter" etc. So you can write thing like<br><br>if (isdigit©) {<br>.. we do something with the digit ..<br><br>and the ctype files implement that logic.<br><br>Those files exist (in very similar form) in the original Linux-0.01 <br>release under the names "lib/ctype.c" and "include/ctype.h". That kernel <br>was released in September of 1991, and contains no code except for mine <br>(and Lars Wirzenius, who co-wrote "kernel/vsprintf.c").<br><br>In fact, you can look at the files today and 12 years ago, and you can see <br>clearly that they are largely the same: the modern files have been cleaned <br>up and fix a number of really ugly things (tolower/toupper works <br>properly), but they are clearly incremental improvement on the original <br>one.<br><br>And the original one does NOT look like the unix source one. It has <br>several similarities, but they are clearly due to:<br><br>- the "ctype" interfaces are defined by the C standard library.<br><br>- the C standard also specifies what kinds of names a system library <br>interface can use internally. In particular, the C standard specifies <br>that names that start with an underscore and a capital letter are <br>"internal" to the library. This is important, because it explains why<br>both the Linux implementation _and_ the UNIX implementation used a<br>particular naming scheme for the flags.<br><br>- algorithmically, there aren't that many ways to test whether a <br>character is a number or not. That's _especially_ true in<br>C, where a macro must not use it's argument more than once. So for <br>example, the "obvious" implementation of "isdigit()" (which tests for <br>whether a character is a digit or not) would be<br><br>#define isdigit(x) (<!--emo&(x)--><img src='http://210.51.184.178/kaiyuan/modules/ipboard/html/emoticons/girl_handsacrossamerica.gif' border='0' style='vertical-align:middle' alt='girl_handsacrossamerica.gif' /><!--endemo--> >= '0' && <!--emo&(x)--><img src='http://210.51.184.178/kaiyuan/modules/ipboard/html/emoticons/girl_handsacrossamerica.gif' border='0' style='vertical-align:middle' alt='girl_handsacrossamerica.gif' /><!--endemo--> <= '9')<br><br>but this is not actually allowed by the C standard (because 'x' is used <br>twice).<br><br>This explains why both Linux and traditional UNIX use the "other" <br>obvious implementation: having an array that describes what each of the <br>possible 256 characters are, and testing the contents of that array<br>(indexed by the character) instead. That way the macro argument is only <br>used once.<br><br>The above things basically explain the similarities. There simply aren't<br>that many ways to do a standard C "ctype" implementation, in other words.<br><br>Now, let's look at the _differences_ in Linux and traditional UNIX:<br><br>- both Linux and traditional unix use a naming scheme of "underscore and <br>a capital letter" for the flag names. There are flags for "is upper <br>case" (_U) and "is lower case" (_L), and surprise surprise, both UNIX <br>and Linux use the same name. But think about it - if you wanted to use <br>a short flag name, and you were limited by the C standard naming, what <br>names _would_ you use? Maybe you'd select "U" for "Upper case" and "L" <br>for "Lower case"?<br><br>Looking at the other flags, Linux uses "_D" for "Digit", while<br>traditional UNIX instead uses "_N" for "Number". Both make sense, but <br>they are different. I personally think that the Linux naming makes more <br>sense (the function that tests for a digit is called "isdigit()", not<br>"isnumber()"), but on the other hand I can certainly understand why <br>UNIX uses "_N" - the function that checs for whether a character is <br>"alphanumeric" is called "isalnum()", and that checks whether the <br>character is a upper case letter, a lower-case letter _or_ a digit (aka <br>"number").<br><br>In short: there aren't that many ways you can choose the names, and <br>there is lots of overlap, but it's clearly not 100%.<br><br>- The original Linux ctype.h/ctype.c file has obvious deficiencies, which <br>pretty much point to somebody new to C making mistakes (me) rather than <br>any old and respected source. For example, the "toupper()/tolower()" <br>macros are just totally broken, and nobody would write the "isascii()" <br>and "toascii()" the way they were written in that original Linux. And<br>you can see that they got fixed later on in Linux development, even <br>though you can also see that the files otherwise didn't change.<br><br>For example: remember how C macros must only use their argument once <br>(never mind why - you really don't care, so just take it on faith, for<br>now). So let's say that you wanted to change an upper case character <br>into a lower case one, which is what "tolower()" does. Normal use is <br>just a fairly obvious<br><br>newchar = tolower(oldchar);<br><br>and the original Linux code does<br><br>extern char _ctmp;<br>#define tolower© (_ctmp=c,isupper(_ctmp)?_ctmp+('a'+'A'):_ctmp)<br><br>which is not very pretty, but notice how we have a "temporary <br>character" _ctmp (remember that internal header names should start with<br>an underscore and an upper case character - this is already slightly <br>broken in itself). That's there so that we can use the argument "c" <br>only once - to assign it to the new temporary - and then later on we <br>use that temporary several times.<br><br>Now, the reason this is broken is <br><br>- it's not thread-safe (if two different threads try to do this at <br>once, they will stomp on each others temporary variable)<br><br>- the argument © might be a complex expression, and as such it<br>should really be parenthesized. The above gets several valid <br>(but unusual) expressions wrong.<br><br>Basically, the above is _exactly_ the kinds of mistakes a young programmer <br>would make. It's classic.<br><br>And I bet it's _not_ what the UNIX code looked like, even in 1991. UNIX by<br>then was 20 years old, and I _think_ that it uses a simple table lookup<br>(which makes a lot more sense anyway and solves all problems). I'd be very<br>susprised if it had those kinds of "beginner mistakes" in it, but I don't <br>actually have access to the code, so what do I know? (I can look up some <br>BSD code on the web, it definitely does _not_ do anythign like the above).<br><br>The lack of proper parenthesis exists in other places of the original <br>Linux ctype.h file too: isascii() and toascii() are similarly broken.<br><br>In other words: there are _lots_ of indications that the code was not <br>copied, but was written from scratch. Bugs and all.<br><br>Oh, another detail: try searching the web (google is your friend) for <br>"_ctmp". It's unique enough that you'll notice that all the returned hits <br>are all Linux-related. No UNIX hits anywhere. Doing a google for<br><br>_ctmp -linux<br><br>shows more Linux pages (that just don't happen to have "linux" in them),<br>except for one which is the L4 microkernel, and that one shows that they<br>used the Linux header file (it still says "_LINUX_CTYPE_H" in it).<br><br>So there is definitely a lot of proof that my ctype.h is original work. <br>
欢迎光临 德国开元华人社区 开元周游 (https://bbs.kaiyuan.cn/)
Powered by Discuz! X3.2