6.2.4.2. mxTools C implementation

Comienzo C section to interscript/core/mxTools.c[1 /30 ] Siguiente Último
     1: #line 77 "mxTools.pak"
     2: 
     3: /*
     4:   mxTools -- Misc. utilities for Python
     5: 
     6:   (c) Marc-Andre Lemburg; All Rights Reserved; see mxTools.html for
     7:   copying information.
     8: */
     9: 
    10: /* Define this to aid in finding memory leaks */
    11: /*#define MAL_MEM_DEBUG*/
    12: /*#define MAL_DEBUG*/
    13: 
    14: /* Logging file used by debugging facility */
    15: #ifndef MAL_DEBUG_OUTPUTFILE
    16: # define MAL_DEBUG_OUTPUTFILE "mxTools.log"
    17: #endif
    18: 
    19: /* We want all our symbols to be exported */
    20: #define MX_BUILDING_MXTOOLS
    21: 
    22: #include "mx.h"
    23: #include "mxTools.h"
    24: 
    25: /* Needed for mxTools_EvalCodeString() */
    26: #include "compile.h"
    27: #include "eval.h"
    28: 
    29: #define VERSION "0.9.1"
    30: 
    31: /* To open up the playground for new ideas... */
    32: /*#define INCLUDE_FUNSTUFF*/
    33: 
    34: /* Maximal size of the code cache used by mxTools_EvalCodeString() */
    35: #define MAX_CODECACHE_SIZE      10
    36: 
    37: /* --- module doc-string -------------------------------------------------- */
    38: 
    39: static char *Module_docstring =
    40: 
    41:  MXTOOLS_MODULE" -- A tool collection. Version "VERSION"\n\n"
    42: 
    43:  "(c) Copyright Marc-Andre Lemburg, 1997,1998, mal@lemburg.com,\n\n"
    44:  "                 All Rights Reserved\n\n"
    45:  "See the documentation for further information on copyrights,\n"
    46:  "or contact the author."
    47: ;
    48: 
    49: /* --- module globals ----------------------------------------------------- */
    50: 
    51: static PyObject *mxTools_Error;                 /* Error Exception
    52:                                                    object */
End C section to interscript/core/mxTools.c[1]
Comienzo python section to interscript/core/mxTools.py[1 /26 ] Siguiente Último
     1: #line 129 "mxTools.pak"
     2: class NotGiven: pass
     3: __version__ = "0.9.1"
     4: from interscript.core.protocols import has_protocol
End python section to interscript/core/mxTools.py[1]
Comienzo C section to interscript/core/mxTools.c[2 /30 ] Siguiente Previo Primero Último
    53: #line 133 "mxTools.pak"
    54: 
    55: static PyObject *mxNotGiven;                    /* NotGiven singleton */
    56: 
    57: /* --- forward declarations ----------------------------------------------- */
    58: 
    59: /* --- internal macros ---------------------------------------------------- */
    60: 
    61: /* --- module helpers ----------------------------------------------------- */
    62: 
    63: /* Create an exception object, insert it into the module dictionary
    64:    under the given name and return the object pointer; this is NULL in
    65:    case an error occurred. */
    66: 
    67: static
    68: PyObject *insexc(PyObject *moddict,
    69:                  char *name)
    70: {
    71:     PyObject *v;
    72:     char fullname[256];
    73: 
    74:     sprintf(fullname,MXTOOLS_MODULE".%s",name);
    75:     v = PyErr_NewException(fullname, NULL, NULL);
    76:     if (v == NULL)
    77:         return NULL;
    78:     if (PyDict_SetItemString(moddict,name,v))
    79:         return NULL;
    80:     return v;
    81: }
    82: 
    83: #if 0
    84: /* Helper for adding integer constants. Check for errors with
    85:    PyErr_Occurred() */
    86: static
    87: void insint(PyObject *dict,
    88:             char *name,
    89:             int value)
    90: {
    91:     PyObject *v = PyInt_FromLong((long)value);
    92:     PyDict_SetItemString(dict, name, v);
    93:     Py_XDECREF(v);
    94: }
    95: #endif
    96: 
    97: /* Helper for adding string constants to a dictionary. Check for
    98:    errors with PyErr_Occurred() */
    99: static
   100: void insstr(PyObject *dict,
   101:             char *name,
   102:             char *value)
   103: {
   104:     PyObject *v = PyString_FromString(value);
   105:     PyDict_SetItemString(dict, name, v);
   106:     Py_XDECREF(v);
   107: }
   108: 
   109: static
   110: PyObject *notimplemented1(PyObject *v)
   111: {
   112:     Py_Error(PyExc_TypeError,
   113:              "operation not implemented");
   114:  onError:
   115:     return NULL;
   116: }
   117: 
   118: static
   119: PyObject *notimplemented2(PyObject *v, PyObject *w)
   120: {
   121:     Py_Error(PyExc_TypeError,
   122:              "operation not implemented");
   123:  onError:
   124:     return NULL;
   125: }
   126: 
   127: static
   128: PyObject *notimplemented3(PyObject *u, PyObject *v, PyObject *w)
   129: {
   130:     Py_Error(PyExc_TypeError,
   131:              "operation not implemented");
   132:  onError:
   133:     return NULL;
   134: }
   135: 
   136: /* --- Internal Functions ------------------------------------------------- */
   137: 
   138: #ifdef INCLUDE_FUNSTUFF
   139: static
   140: PyObject *mxTools_EvalCodeString(PyObject *codestr)
   141: {
   142:     static PyObject *codecache;
   143:     PyObject *code;
   144:     PyObject *v;
   145: 
   146:     Py_Assert(PyString_Check(codestr),
   147:               PyExc_SystemError,
   148:               "Bad internal call to mxTools_EvalCodeString");
   149: 
   150:     /* Init. codecache dictionary */
   151:     if (codecache == NULL) {
   152:         codecache = PyDict_New();
   153:         if (!codecache)
   154:             goto onError;
   155:     }
   156: 
   157:     /* Get code object or compile the string */
   158:     code = PyDict_GetItem(codecache,codestr);
   159:     if (!code) {
   160:         code = Py_CompileString(PyString_AS_STRING(codestr),
   161:                                 "<string>", Py_eval_input);
   162:         if (!code)
   163:             goto onError;
   164:         if (PyDict_Size(codecache) >= MAX_CODECACHE_SIZE)
   165:             PyDict_Clear(codecache);
   166:         PyDict_SetItem(codecache,codestr,code);
   167:     }
   168:     else
   169:         Py_INCREF(code);
   170: 
   171:     /* Run the code in the current context */
   172:     v = PyEval_EvalCode((PyCodeObject *)code,
   173:                         PyEval_GetGlobals(),
   174:                         PyEval_GetLocals());
   175:     Py_DECREF(code);
   176:     return v;
   177: 
   178:  onError:
   179:     return NULL;
   180: }
   181: #endif
   182: 
   183: /* --- Interface ---------------------------------------------------------- */
End C section to interscript/core/mxTools.c[2]


6.2.4.2.1. napply
6.2.4.2.2. mapply
6.2.4.2.3. method_mapply
6.2.4.2.4. trange
6.2.4.2.5. indices
6.2.4.2.6. range_len
6.2.4.2.7. irange
6.2.4.2.8. get
6.2.4.2.9. extract
6.2.4.2.10. ifilter
6.2.4.2.11. tuples
6.2.4.2.12. lists
6.2.4.2.13. count
6.2.4.2.14. exists
6.2.4.2.15. forall
6.2.4.2.16. index
6.2.4.2.17. sizeof
6.2.4.2.18. findattr
6.2.4.2.19. attrlist
6.2.4.2.20. dict
6.2.4.2.21. setdict
6.2.4.2.22. invdict
6.2.4.2.23. reverse
6.2.4.2.24. acquire
6.2.4.2.25. verbosity
6.2.4.2.26. optimsation
6.2.4.2.27. NotGiven
6.2.4.2.28. module