Undefined behaviour in C [was Re: The Cost of Dynamism]

Rustom Mody rustompmody at gmail.com
Sat Mar 26 13:43:39 EDT 2016


On Saturday, March 26, 2016 at 4:09:41 PM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 26 Mar 2016 04:30 pm, Rustom Mody wrote:
> 
> > For one thing its good to remember that we wouldn't be here without python
> > Python wouldn't be what it is without CPython
> 
> There is nothing about Python that relies on the C standard being as it is.

Um lets see...
There is this nice piece of OO called the exception hierarchy:
https://docs.python.org/2/library/exceptions.html#exception-hierarchy

So we have
BaseException ⊇ Exception ⊇ EnvironmentError ⊇ IOError
At this point it would have been completely natural for IOError to continue
subclassing to all the typical errors 
- File not found
- No Space left on device
etc etc

But instead we have an integer errno and we must inquire what that is to
figure out what the exact IOError was
Are you suggesting that python's errno module:
https://docs.python.org/2/library/errno.html
And C's http://man7.org/linux/man-pages/man3/errno.3.html
are coincidentally related?

> There are Python implementations that are not written in C or C++:
> 
> Jython (Java)
> IronPython (C# for .Net or Mono)
> CLPython (Lisp)
> Berp (Haskell)

As best as I know 
- Java is written in C
- Lisp is written in C
- Haskell is written in C


Notice a certain pattern?
Yeah some of them may be self-hosting
eg haskell (ghc) is written in ghc
Where did the first bootstrap start from?

And if you think those levels of distance render the C origin irrelevant,
here is a famous Turing award lecture:
https://www.ece.cmu.edu/~ganger/712.fall02/papers/p761-thompson.pdf
by (surprise-surprise!) the creator of C-Unix

... shows how to make a Trojan and ends with

The moral is obvious.  You can't trust code that you did not totally
create yourself.  (Especially code from companies that employ people
like me.)  No amount of source-level verification or scrutiny will
protect you from using untrusted code.

So... Ahem... C is unsafe... Right... Prefer C++ ??<wink>



More information about the Python-list mailing list