Add the co_extra field and accompanying APIs to code objects.

This completes PEP 523.
diff --git a/Include/ceval.h b/Include/ceval.h
index 7607f75..81f4bbf 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -187,6 +187,10 @@
 PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
 #endif
 
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
+#endif
+
 #define Py_BEGIN_ALLOW_THREADS { \
                         PyThreadState *_save; \
                         _save = PyEval_SaveThread();
diff --git a/Include/code.h b/Include/code.h
index a300ead..a054a92 100644
--- a/Include/code.h
+++ b/Include/code.h
@@ -7,6 +7,14 @@
 extern "C" {
 #endif
 
+
+/* Holder for co_extra information */
+typedef struct {
+    Py_ssize_t ce_size;
+    void **ce_extras;
+} _PyCodeObjectExtra;
+
+
 /* Bytecode object */
 typedef struct {
     PyObject_HEAD
@@ -15,6 +23,7 @@
     int co_nlocals;		/* #local variables */
     int co_stacksize;		/* #entries needed for evaluation stack */
     int co_flags;		/* CO_..., see below */
+    int co_firstlineno;   /* first source line number */
     PyObject *co_code;		/* instruction opcodes */
     PyObject *co_consts;	/* list (constants used) */
     PyObject *co_names;		/* list of strings (names used) */
@@ -30,11 +39,12 @@
     unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */
     PyObject *co_filename;	/* unicode (where it was loaded from) */
     PyObject *co_name;		/* unicode (name, for reference) */
-    int co_firstlineno;		/* first source line number */
     PyObject *co_lnotab;	/* string (encoding addr<->lineno mapping) See
 				   Objects/lnotab_notes.txt for details. */
     void *co_zombieframe;     /* for optimization only (see frameobject.c) */
     PyObject *co_weakreflist;   /* to support weakrefs to code objects */
+    /* Scratch space for extra data relating to the code object */
+    _PyCodeObjectExtra *co_extra;
 } PyCodeObject;
 
 /* Masks for co_flags above */
@@ -128,6 +138,14 @@
 PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
                                       PyObject *names, PyObject *lnotab);
 
+
+#ifndef Py_LIMITED_API
+PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
+                                 void **extra);
+PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
+                                 void *extra);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/Include/pystate.h b/Include/pystate.h
index 5a06773..5ab5c98 100644
--- a/Include/pystate.h
+++ b/Include/pystate.h
@@ -8,6 +8,10 @@
 extern "C" {
 #endif
 
+/* This limitation is for performance and simplicity. If needed it can be
+removed (with effort). */
+#define MAX_CO_EXTRA_USERS 255
+
 /* State shared between threads */
 
 struct _ts; /* Forward */
@@ -141,6 +145,9 @@
     PyObject *coroutine_wrapper;
     int in_coroutine_wrapper;
 
+    Py_ssize_t co_extra_user_count;
+    freefunc co_extra_freefuncs[MAX_CO_EXTRA_USERS];
+
     /* XXX signal handlers should also be here */
 
 } PyThreadState;