I downloaded the python source

I may not see it right away, but I downloaded the python source. (It may be better to download the source of 3.4, but for now, I'm downloading the source of 2.7 (Python-2.7.7) I'm using) In the future, you may even see the contents of the source by checking (as an aid to) the specifications.

First, try to find main

For the time being, look for the entrance of python.exe.

First, search with main (). Some mains were found, including Demo. You can get a rough idea of the file name, but also look at the Makefile to confirm the search results.

As a result of the search, the following line was found in PC / os2emx / Makefile.

PYTHON.EXE=	python.exe

Where I'm building this guy

$(PYTHON.EXE): $(SRC.EXE) $(PYTHON.EXEIMP) $(OUT)python.def
	$(CC) -Zmt $(LDMODE.EXE) -Zcrtdll -Wall $(INCLUDE) -L. -lgcc -o $@ $(SRC.EXE) $(PYTHON.EXEIMP) $(LIBS) $(OUT)python.def
	$(EXEOPT) -aq $(PYTHON.EXE) -h$(NFILES)

So, the definition of SRC.EXE is

SRC.EXE=	$(TOP)Modules/python.c

The contents of this source (Modules / python.c) are as follows.

/* Minimal main program -- everything is loaded from the library */

#include "Python.h"

#ifdef __FreeBSD__
#include <floatingpoint.h>
#endif

int
main(int argc, char **argv)
{
	/* 754 requires that FP exceptions run in "no stop" mode by default,
	 * and until C vendors implement C99's ways to control FP exceptions,
	 * Python requires non-stop mode.  Alas, some platforms enable FP
	 * exceptions by default.  Here we disable them.
	 */
#ifdef __FreeBSD__
	fp_except_t m;

	m = fpgetmask();
	fpsetmask(m & ~FP_X_OFL);
#endif
	return Py_Main(argc, argv);
}

API While examining the above, I thought that the python API had an entry defined in python.def. The contents of python.def look like this. (Excerpt)

LIBRARY        PYTHON24 INITINSTANCE TERMINSTANCE
DESCRIPTION    'Python 2.4 Core DLL'
PROTMODE
DATA           MULTIPLE NONSHARED

EXPORTS
               ; Data
               PyCFunction_Type
・ ・ ・
               ; Code
               PyArg_Parse
・ ・ ・
               Py_Initialize
               Py_IsInitialized
               Py_Main
               Py_MakePendingCalls
               Py_Malloc
               Py_NewInterpreter
               Py_Realloc
・ ・ ・

Of course, there is also an API reference site.

-Python / C API Reference Manual

If you're looking at the source, you might want to start with an API entry.

In the Demo folder in the downloaded source, there was something like sample code using the API. I don't know if I will use the API, but it may be helpful if I use it.

When I tried to read the python source, I searched the site for the analyzed information, but I haven't found it so far. It would be helpful if I could understand the outline. If I investigate a little more and find interesting material, I may post an article.

Recommended Posts

I downloaded the python source
I liked the tweet with python. ..
I wrote the queue in Python
[Python] Read the Flask source code
I wrote the stack in Python
I just changed the sample source of Python a little.
I started python
I didn't know the basics of Python
[Python] I personally summarized the basic grammar.
Python: I tried the traveling salesman problem
The Python project template I think of.
[Python beginner] I collected the articles I wrote
I tried the Python Tornado Testing Framework
I tried "smoothing" the image with Python + OpenCV
[Python] Read the source code of Bottle Part 2
[Python] I tried substituting the function name for the function name
vprof --I tried using the profiler for Python
I tried "differentiating" the image with Python + OpenCV
I tried simulating the "birthday paradox" in Python
I tried the least squares method in Python
I tried python programming for the first time.
[Python] Read the source code of Bottle Part 1
Try the free version of Progate [Python I]
I tried "binarizing" the image with Python + OpenCV
I tried using the Datetime module by Python
I touched some of the new features of Python 3.8 ①
I can't click the Selenium checkbox Python VBA
I implemented the inverse gamma function in python
[Python] I will upload the FTP to the FTP server.
I want to display the progress in Python!
Find the maximum Python
I tried Python> autopep8
the zen of Python
Install python from source
I implemented Python Logging
[Python] Split the date
I counted the grains
I tried Python> decorator
Why I chose Python
I compared Python more-itertools 2.5 → 2.6
Easy way to check the source of Python modules
I tried to graph the packages installed in Python
[Trainer's Recipe] I touched the flame of the Python framework.
What I got into Python for the first time
I tried Python on Mac for the first time.
I tried to touch the CSV file with Python
I tried python on heroku for the first time
I wanted to use the Python library from MATLAB
I checked out the versions of Blender and Python
I want to inherit to the back with python dataclass
[Python] I tried to graph the top 10 eyeshadow rankings
I want to write in Python! (3) Utilize the mock
A memo that I touched the Datastore with python
I tried to solve the problem with Python Vol.1
I felt that I ported the Python code to C ++ 98.
I want to use the R dataset in python
I moved the automatic summarization API "summpy" with python3.
I tried hitting the API with echonest's python client
I tried to summarize the string operations of Python
I tried to find the entropy of the image with python
I tried fp-growth with python