Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ebed7511
Commit
ebed7511
authored
May 16, 1995
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Templates converted to new naming conventions (thanks to Chak Tan)
parent
52e02998
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
100 additions
and
131 deletions
+100
-131
Tools/modulator/README
Tools/modulator/README
+6
-2
Tools/modulator/Templates/module_head
Tools/modulator/Templates/module_head
+3
-3
Tools/modulator/Templates/module_method
Tools/modulator/Templates/module_method
+6
-6
Tools/modulator/Templates/module_tail
Tools/modulator/Templates/module_tail
+11
-10
Tools/modulator/Templates/object_head
Tools/modulator/Templates/object_head
+4
-3
Tools/modulator/Templates/object_method
Tools/modulator/Templates/object_method
+6
-5
Tools/modulator/Templates/object_mlist
Tools/modulator/Templates/object_mlist
+4
-3
Tools/modulator/Templates/object_new
Tools/modulator/Templates/object_new
+2
-1
Tools/modulator/Templates/object_structure
Tools/modulator/Templates/object_structure
+10
-9
Tools/modulator/Templates/object_tail
Tools/modulator/Templates/object_tail
+3
-2
Tools/modulator/Templates/object_tp_as_mapping
Tools/modulator/Templates/object_tp_as_mapping
+5
-4
Tools/modulator/Templates/object_tp_as_number
Tools/modulator/Templates/object_tp_as_number
+25
-68
Tools/modulator/Templates/object_tp_as_sequence
Tools/modulator/Templates/object_tp_as_sequence
+9
-9
Tools/modulator/Templates/object_tp_dealloc
Tools/modulator/Templates/object_tp_dealloc
+1
-1
Tools/modulator/Templates/object_tp_getattr
Tools/modulator/Templates/object_tp_getattr
+2
-2
Tools/modulator/Templates/object_tp_repr
Tools/modulator/Templates/object_tp_repr
+2
-2
Tools/modulator/Templates/object_tp_setattr
Tools/modulator/Templates/object_tp_setattr
+1
-1
No files found.
Tools/modulator/README
View file @
ebed7511
This is release 1.
0
of modulator, a generator of boilerplate code for
This is release 1.
1
of modulator, a generator of boilerplate code for
modules to be written in C.
Usage when you have tk is *reall* simple: start modulator, fill out
There is only one difference with release 1.0, really: the templates
now use "new-style" naming conventions. Many thanks to Chak Tan
<tan@ee.rochester.edu> for supplying them.
Usage when you have tk is *really* simple: start modulator, fill out
the forms specifying all the objects and methods, tell modulator
whether objects should also be accessible as sequences, etc and press
'generate code'. It will write a complete skeleton module for you.
...
...
Tools/modulator/Templates/module_head
View file @
ebed7511
#include "
allobjects
.h"
#include "modsupport.h" /* For getargs() etc. */
#include "
Python
.h"
/*
#include "modsupport.h" /* For getargs() etc. */
static
o
bject *ErrorObject;
static
PyO
bject *ErrorObject;
/* ----------------------------------------------------- */
Tools/modulator/Templates/module_method
View file @
ebed7511
static
o
bject *
static
PyO
bject *
$abbrev$_$method$(self, args)
o
bject *self; /* Not used */
o
bject *args;
PyO
bject *self; /* Not used */
PyO
bject *args;
{
if (!
newgetargs
(args, ""))
if (!
PyArg_ParseTuple
(args, ""))
return NULL;
INCREF(
None);
return None;
Py_INCREF(Py_
None);
return
Py_
None;
}
Tools/modulator/Templates/module_tail
View file @
ebed7511
/* List of methods defined in the module */
static struct
methodlist
$abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
static struct
PyMethodDef
$abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
};
...
...
@@ -12,19 +12,20 @@ static struct methodlist $abbrev$_methods[] = {
void
init$name$()
{
o
bject *m, *d;
PyO
bject *m, *d;
/* Create the module and add the functions */
m =
initm
odule("$name$", $abbrev$_methods);
m =
Py_InitM
odule("$name$", $abbrev$_methods);
/* Add some symbolic constants to the module */
d =
getmoduled
ict(m);
ErrorObject =
newstringobject
("$name$.error");
dictinsert
(d, "error", ErrorObject);
d =
PyModule_GetD
ict(m);
ErrorObject =
PyString_FromString
("$name$.error");
PyDict_SetItemString
(d, "error", ErrorObject);
/* XXXX Add constants here */
/* Check for errors */
if (
err_o
ccurred())
fatal
("can't initialize module $name$");
if (
PyErr_O
ccurred())
Py_FatalError
("can't initialize module $name$");
}
Tools/modulator/Templates/object_head
View file @
ebed7511
/* Declarations for objects of type $name$ */
typedef struct {
OB
_HEAD
PyObject
_HEAD
/* XXXX Add your own stuff here */
} $abbrev$object;
staticforward typeobject $Abbrev$type;
staticforward PyTypeObject $Abbrev$type;
#define is_$abbrev$object(v) ((v)->ob_type == &$Abbrev$type)
/* ---------------------------------------------------------------- */
Tools/modulator/Templates/object_method
View file @
ebed7511
static
o
bject *
static
PyO
bject *
$abbrev$_$method$(self, args)
$abbrev$object *self;
o
bject *args;
PyO
bject *args;
{
if (!
newgetargs
(args, ""))
if (!
PyArg_ParseTuple
(args, ""))
return NULL;
INCREF(
None);
return None;
Py_INCREF(Py_
None);
return
Py_
None;
}
Tools/modulator/Templates/object_mlist
View file @
ebed7511
static struct
methodlist
$abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
static struct
PyMethodDef
$abbrev$_methods[] = {
$methodlist$
{NULL, NULL} /* sentinel */
};
/* ---------- */
Tools/modulator/Templates/object_new
View file @
ebed7511
...
...
@@ -4,9 +4,10 @@ new$abbrev$object()
{
$abbrev$object *self;
self =
NEWOBJ
($abbrev$object, &$Abbrev$type);
self =
PyObject_NEW
($abbrev$object, &$Abbrev$type);
if (self == NULL)
return NULL;
/* XXXX Add your own initializers here */
return self;
}
Tools/modulator/Templates/object_structure
View file @
ebed7511
/* Code to access structure members by accessing attributes */
#include "structmember.h"
...
...
@@ -6,22 +7,23 @@
static struct memberlist $abbrev$_memberlist[] = {
/* XXXX Add lines like { "foo", T_INT, OFF(foo), RO } */
{NULL} /* Sentinel */
};
static
o
bject *
static
PyO
bject *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
{
o
bject *rv;
PyO
bject *rv;
/* XXXX Add your own getattr code here */
rv =
getmember
((char *)/*XXXX*/0, $abbrev$_memberlist, name);
rv =
PyMember_Get
((char *)/*XXXX*/0, $abbrev$_memberlist, name);
if (rv)
return rv;
err_c
lear();
return
findmethod($abbrev$_methods, (o
bject *)self, name);
PyErr_C
lear();
return
Py_FindMethod($abbrev$_methods, (PyO
bject *)self, name);
}
...
...
@@ -29,13 +31,12 @@ static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
o
bject *v;
PyO
bject *v;
{
/* XXXX Add your own setattr code here */
if ( v == NULL ) {
err_setstr(
AttributeError, "Cannot delete attribute");
PyErr_SetString(PyExc_
AttributeError, "Cannot delete attribute");
return -1;
}
return
setmember
((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
return
PyMember_Set
((char *)/*XXXX*/0, $abbrev$_memberlist, name, v);
}
Tools/modulator/Templates/object_tail
View file @
ebed7511
static
typeo
bject $Abbrev$type = {
OB_HEAD_INIT(&Typet
ype)
static
PyTypeO
bject $Abbrev$type = {
PyObject_HEAD_INIT(&PyType_T
ype)
0, /*ob_size*/
"$name$", /*tp_name*/
sizeof($abbrev$object), /*tp_basicsize*/
...
...
@@ -20,3 +20,4 @@ static typeobject $Abbrev$type = {
/* End of code for $name$ objects */
/* -------------------------------------------------------- */
Tools/modulator/Templates/object_tp_as_mapping
View file @
ebed7511
/* Code to access $name$ objects as mappings */
static int
...
...
@@ -7,10 +8,10 @@ $abbrev$_length(self)
/* XXXX Return the size of the mapping */
}
static
o
bject *
static
PyO
bject *
$abbrev$_subscript(self, key)
$abbrev$object *self;
o
bject *key;
PyO
bject *key;
{
/* XXXX Return the item of self indexed by key */
}
...
...
@@ -18,13 +19,13 @@ $abbrev$_subscript(self, key)
static int
$abbrev$_ass_sub(self, v, w)
$abbrev$object *self;
o
bject *v, *w;
PyO
bject *v, *w;
{
/* XXXX Put w in self under key v */
return 0;
}
static
mapping_m
ethods $abbrev$_as_mapping = {
static
PyMappingM
ethods $abbrev$_as_mapping = {
(inquiry)$abbrev$_length, /*mp_length*/
(binaryfunc)$abbrev$_subscript, /*mp_subscript*/
(objobjargproc)$abbrev$_ass_sub, /*mp_ass_subscript*/
...
...
Tools/modulator/Templates/object_tp_as_number
View file @
ebed7511
/* Code to access $name$ objects as numbers */
static
o
bject *
static
PyO
bject *
$abbrev$_add(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Add them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_sub(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Subtract them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_mul(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX Multiply them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_div(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Divide them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_mod(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Modulo them */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_divmod(x, y)
$abbrev$object *x;
$abbrev$object *y;
{
/* XXXX Return 2-tuple with div and mod */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_pow(v, w, z)
$abbrev$object *v;
$abbrev$object *w;
$abbrev$object *z;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_neg(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_pos(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_abs(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static int
...
...
@@ -103,124 +84,100 @@ $abbrev$_nonzero(v)
$abbrev$object *v;
{
/* XXXX Return 1 if non-zero */
err_setstr(SystemError, "not implemented");
return -1;
}
static
o
bject *
static
PyO
bject *
$abbrev$_invert(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_lshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_rshift(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_and(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_xor(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_or(v, w)
$abbrev$object *v;
$abbrev$object *w;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static int
$abbrev$_coerce(pv, pw)
o
bject **pv;
o
bject **pw;
PyO
bject **pv;
PyO
bject **pw;
{
/* XXXX I haven't a clue... */
return 1;
}
static
o
bject *
static
PyO
bject *
$abbrev$_int(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_long(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_float(v)
$abbrev$object *v;
{
/* XXXX */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_oct(v)
$abbrev$object *v;
{
/* XXXX Return object as octal stringobject */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
o
bject *
static
PyO
bject *
$abbrev$_hex(v)
$abbrev$object *v;
{
/* XXXX Return object as hex stringobject */
err_setstr(SystemError, "not implemented");
return NULL;
}
static
number_m
ethods $abbrev$_as_number = {
static
PyNumberM
ethods $abbrev$_as_number = {
(binaryfunc)$abbrev$_add, /*nb_add*/
(binaryfunc)$abbrev$_sub, /*nb_subtract*/
(binaryfunc)$abbrev$_mul, /*nb_multiply*/
...
...
Tools/modulator/Templates/object_tp_as_sequence
View file @
ebed7511
...
...
@@ -8,15 +8,15 @@ $abbrev$_length(self)
/* XXXX Return the size of the object */
}
static
o
bject *
static
PyO
bject *
$abbrev$_concat(self, bb)
$abbrev$object *self;
o
bject *bb;
PyO
bject *bb;
{
/* XXXX Return the concatenation of self and bb */
}
static
o
bject *
static
PyO
bject *
$abbrev$_repeat(self, n)
$abbrev$object *self;
int n;
...
...
@@ -24,7 +24,7 @@ $abbrev$_repeat(self, n)
/* XXXX Return a new object that is n times self */
}
static
o
bject *
static
PyO
bject *
$abbrev$_item(self, i)
$abbrev$object *self;
int i;
...
...
@@ -32,7 +32,7 @@ $abbrev$_item(self, i)
/* XXXX Return the i-th object of self */
}
static
o
bject *
static
PyO
bject *
$abbrev$_slice(self, ilow, ihigh)
$abbrev$object *self;
int ilow, ihigh;
...
...
@@ -44,7 +44,7 @@ static int
$abbrev$_ass_item(self, i, v)
$abbrev$object *self;
int i;
o
bject *v;
PyO
bject *v;
{
/* XXXX Assign to the i-th element of self */
return 0;
...
...
@@ -52,15 +52,15 @@ $abbrev$_ass_item(self, i, v)
static int
$abbrev$_ass_slice(self, ilow, ihigh, v)
listo
bject *self;
PyListO
bject *self;
int ilow, ihigh;
o
bject *v;
PyO
bject *v;
{
/* XXXX Replace ilow..ihigh slice of self with v */
return 0;
}
static
sequence_m
ethods $abbrev$_as_sequence = {
static
PySequenceM
ethods $abbrev$_as_sequence = {
(inquiry)$abbrev$_length, /*sq_length*/
(binaryfunc)$abbrev$_concat, /*sq_concat*/
(intargfunc)$abbrev$_repeat, /*sq_repeat*/
...
...
Tools/modulator/Templates/object_tp_dealloc
View file @
ebed7511
...
...
@@ -4,5 +4,5 @@ $abbrev$_dealloc(self)
$abbrev$object *self;
{
/* XXXX Add your own cleanup code here */
DEL(self);
PyMem_
DEL(self);
}
Tools/modulator/Templates/object_tp_getattr
View file @
ebed7511
static
o
bject *
static
PyO
bject *
$abbrev$_getattr(self, name)
$abbrev$object *self;
char *name;
{
/* XXXX Add your own getattr code here */
return
findmethod($abbrev$_methods, (o
bject *)self, name);
return
Py_FindMethod($abbrev$_methods, (PyO
bject *)self, name);
}
Tools/modulator/Templates/object_tp_repr
View file @
ebed7511
static
o
bject *
static
PyO
bject *
$abbrev$_repr(self)
$abbrev$object *self;
{
o
bject *s;
PyO
bject *s;
/* XXXX Add code here to put self into s */
return s;
...
...
Tools/modulator/Templates/object_tp_setattr
View file @
ebed7511
...
...
@@ -3,7 +3,7 @@ static int
$abbrev$_setattr(self, name, v)
$abbrev$object *self;
char *name;
o
bject *v;
PyO
bject *v;
{
/* XXXX Add your own setattr code here */
return -1;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment