[Zope-CVS] CVS: Packages/cZPT/TAL - .cvsignore:1.1 Makefile:1.1 cTALInterpreter.c:1.1 t.py:1.1
Shane Hathaway
shane@cvs.zope.org
Mon, 16 Sep 2002 11:44:34 -0400
Update of /cvs-repository/Packages/cZPT/TAL
In directory cvs.zope.org:/tmp/cvs-serv23309/TAL
Added Files:
.cvsignore Makefile cTALInterpreter.c t.py
Log Message:
Optimized TALInterpreter and restrictedTraverse() in C.
This code is just educational for now. Before doing much more, we should
write performance tests and try out Pyrex.
=== Added File Packages/cZPT/TAL/.cvsignore ===
*.so
*.pyc
=== Added File Packages/cZPT/TAL/Makefile ===
all: cTALInterpreter.so
cTALInterpreter.so: cTALInterpreter.c
gcc -g -Wall -I /usr/local/include/python2.1 -shared -o \
cTALInterpreter.so cTALInterpreter.c
=== Added File Packages/cZPT/TAL/cTALInterpreter.c === (2961/3061 lines abridged)
/*****************************************************************************
Copyright (c) 2002 Zope Corporation and Contributors.
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE
****************************************************************************/
/*
$Id: cTALInterpreter.c,v 1.1 2002/09/16 15:44:33 shane Exp $
Based on revision 1.69 of TALInterpreter.py
*/
#include <Python.h>
#ifndef BOOL
#define BOOL int
#endif
#define CHECKPTR(expr) if ((expr) == NULL) goto error
#define CHECKINT(expr) if ((expr) < 0) goto error
#define DECREF_ASSIGN(var, value) Py_DECREF(var); (var) = (value)
#define DECREF2_CHECK(owned, maybe_owned) \
Py_DECREF(owned); CHECKPTR(maybe_owned); Py_DECREF(maybe_owned)
#define RETURN_NONE Py_INCREF(Py_None); return Py_None
#define SANITY_CHECK_VALUE 12345
staticforward PyTypeObject TALInterpreterType;
typedef struct {
PyObject_HEAD
PyObject *program;
PyObject *macros;
PyObject *engine;
PyObject *Default;
PyObject *stream;
PyObject *_stream_write;
BOOL debug;
BOOL wrap;
BOOL metal;
BOOL tal;
[-=- -=- -=- 2961 lines omitted -=- -=- -=-]
initcTALInterpreter(void)
{
PyObject *m; /* borrowed */
PyObject *other=NULL; /* owned */
m = Py_InitModule3("cTALInterpreter", module_functions, module___doc__);
if (m == NULL)
return;
TALInterpreterType.ob_type = &PyType_Type;
INIT_STRING(py_startsep, "<");
INIT_STRING(py_endsep_basic, ">");
INIT_STRING(py_endsep_slash, "/>");
INIT_STRING(py_endsep_spaceslash, " />");
INIT_STRING(py_newline, "\n");
INIT_STRING(py_space, " ");
INIT_STRING(py_error, "error");
INIT_STRING(py_use_macro, "use-macro");
INIT_STRING(py_slot, "slot");
INIT_STRING(py_attrs, "attrs");
INIT_STRING(py_macro_incompat_version,
"macro %s has incompatible version %s");
INIT_STRING(py_macro_incompat_mode,
"macro %s has incompatible mode %s");
INIT_UNICODE(py_u_newline, "\n");
CHECKPTR(py_0 = PyInt_FromLong(0));
CHECKPTR(py_1 = PyInt_FromLong(1));
other = PyImport_ImportModule("cStringIO");
if (!other) {
PyErr_Clear();
CHECKPTR(other = PyImport_ImportModule("StringIO"));
}
CHECKPTR(StringIO = PyObject_GetAttrString(other, "StringIO"));
Py_DECREF(other);
CHECKPTR(other = PyImport_ImportModule("TALDefs"));
CHECKPTR(METALError = PyObject_GetAttrString(other, "METALError"));
CHECKPTR(TALError = PyObject_GetAttrString(other, "TALError"));
CHECKPTR(TAL_VERSION = PyObject_GetAttrString(other, "TAL_VERSION"));
Py_DECREF(other);
other = NULL;
error:
Py_XDECREF(other);
}
=== Added File Packages/cZPT/TAL/t.py ===
from cTALInterpreter import new_TALInterpreter
class Engine:
def getDefault(self):
return self
engine = Engine()
program = (
('version', "1.3.2"),
('mode', 'html'),
)
interp = new_TALInterpreter(program, None, engine)
interp()