Python and the need for speed

bartc bc at freeuk.com
Wed Apr 19 11:57:20 EDT 2017


On 19/04/2017 15:35, Chris Angelico wrote:
> On Wed, Apr 19, 2017 at 11:46 PM, bartc <bc at freeuk.com> wrote:
>>> You'd be surprised how easy it is to be non-OS-neutral.

I misread that as 'easy to be OS-neutral'. If I turn it around, you're 
saying it is easy to be OS-specific. But we know that! And that is the 
problem.

>> It's not so simple. By OS-neutral I mean code that doesn't depend on special
>> features of either OS (Ie. Windows and Linux). Not conditional code that
>> does either Windows stuff or Linux stuff.
>>
>
> Which means, therefore, that you either can't have any file system
> facilities, or must transparently expose them to the application. You
> also will have a lot of trouble making cross-platform subprocess
> functionality. Even sockets, which are notionally the same on all
> platforms, have a lot of little differences.
>
> To be truly OS-neutral, you basically have to be either nerfed to
> nothing, or so thin you're doing nothing.

Enough works in that 'pcc' project, in terms of file i/o, that it can 
still run plenty of useful programs, such as compilers. (See from line 
3357 of pcc64.c for example; a list of functions that are patched in to 
the host rather linked to an external msvcrt or libc.so shared library.)

In this project, the only OS-specifics it really needs are:

  Windows: use LoadLibrary/GetProcAddr, and msvcrt.dll
  Linux:   use dlopen/dlsym, and libc.so.6

which wouldn't be hard to arrange.

Any other specifics are in the domain of the user programs (different 
libraries for screen i/o for example).

However, getting it to choose between one of those two pairs of 
functions is trivial, compared with the dependencies of a a typical open 
source project.

(I've just downloaded CPython sources from your github link, and the 
first thing I see is an 18,000 line 'configure' script (somewhat bigger 
than my entire C compiler).

This doesn't run on Windows, not without importing most of Linux via 
cygwin or MSYS. But the sources do now appear to support a Windows build:

Step 1: Download Visual Studio Express 2015

Last time I looked, it seemed to be a 5GB to 11GB download (GB not MB!). 
Nevertheless I start the process to get a better idea. It says:

  "Visual Studio requires .NET Framework 4.6 or higher."

Here where I start to think it might be easier to download all the Linux 
stuff after all! As, with my track record, I could download tons of 
stuff, and it still won't work.

FWIW, my mcc64.c file compiles to a 0.2MB executable which is capable of 
compiling that pcc64.c interpreter (I think it does it in 50msec for 
good measure; Tiny C will also do it instantly). /That/ is how simple 
things should be, and can be.

Cue a million excuses for why things have to be the way they are...)

-- 
bartc



More information about the Python-list mailing list