bpo-40421: Add PyFrame_GetCode() function (GH-19757)

PyFrame_GetCode(frame): return a borrowed reference to the frame
code.

Replace frame->f_code with PyFrame_GetCode(frame) in most code,
except in frameobject.c, genobject.c and ceval.c.

Also add PyFrame_GetLineNumber() to the limited C API.
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index 7115fee..39cf6e1 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -1,5 +1,4 @@
 #include "Python.h"
-#include "frameobject.h"
 #include "rotatingtree.h"
 
 /************************************************************/
@@ -388,14 +387,16 @@
 
     /* the 'frame' of a called function is about to start its execution */
     case PyTrace_CALL:
-        ptrace_enter_call(self, (void *)frame->f_code,
-                                (PyObject *)frame->f_code);
+    {
+        PyCodeObject *code = PyFrame_GetCode(frame);
+        ptrace_enter_call(self, (void *)code, (PyObject *)code);
         break;
+    }
 
     /* the 'frame' of a called function is about to finish
        (either normally or with an exception) */
     case PyTrace_RETURN:
-        ptrace_leave_call(self, (void *)frame->f_code);
+        ptrace_leave_call(self, (void *)PyFrame_GetCode(frame));
         break;
 
     /* case PyTrace_EXCEPTION:
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index dbae107..3593bae 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -346,7 +346,7 @@
         lineno = 0;
     frame->lineno = (unsigned int)lineno;
 
-    code = pyframe->f_code;
+    code = PyFrame_GetCode(pyframe);
     if (code == NULL) {
 #ifdef TRACE_DEBUG
         tracemalloc_error("failed to get the code object of the frame");