1

I've been trying to search the source code of CPython for the names of various built-in functions. What I'm interested in is locating the lines that define the names of these functions, what the Python interpreter's "look-up" procedure looks at when it encounters a function. If I change these lines, then I should be able to change the names of the functions, too.

In this case, I tried searching for the abs function in the C source code files on the GitHub page for CPython. This is the link to the search query I was using. There are 30 results, but none of them contains a string like "abs" or anything like that aside from what looks like strings for documentation.

How would I go about finding these particular lines of code?

5
  • 1
    What are you actually trying to achieve, here? Commented Jan 8, 2016 at 22:43
  • This search result from Python/clinic/bltinmodule.c.h looks like the starting place: #define BUILTIN_ABS_METHODDEF \ {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, Commented Jan 8, 2016 at 22:46
  • @jonrsharpe Learning how interpreters work. Commented Jan 8, 2016 at 22:47
  • Then I think something that takes a ten-hour video series is too broad to cover on SO. Commented Jan 8, 2016 at 22:48
  • Put the code down and step away slowly, no Python functionality needs to die here today. Commented Jan 9, 2016 at 0:39

1 Answer 1

2

Here's the part of the search results that specifies the association between the name abs and the function that implements it.

Python/clinic/bltinmodule.c.h 
Showing the top six matches. Last indexed on Oct 1, 2015.

11  #define BUILTIN_ABS_METHODDEF    \
12      {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__},

If you go to bltinmodule.c.h you'll find similar definitions for all the built-in Python methods.

Sign up to request clarification or add additional context in comments.

2 Comments

Could this be extended to looking for things like the methods associated with various built-in classes like strings and numbers?
There's probably similar types of macros for them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.