Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
f2637647
Commit
f2637647
authored
Feb 20, 2001
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved source files to src directory
parent
7dbb8830
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
0 additions
and
7546 deletions
+0
-7546
lib/Components/ExtensionClass/Acquisition.c
lib/Components/ExtensionClass/Acquisition.c
+0
-1466
lib/Components/ExtensionClass/ComputedAttribute.c
lib/Components/ExtensionClass/ComputedAttribute.c
+0
-166
lib/Components/ExtensionClass/ExtensionClass.c
lib/Components/ExtensionClass/ExtensionClass.c
+0
-3570
lib/Components/ExtensionClass/ExtensionClass.h
lib/Components/ExtensionClass/ExtensionClass.h
+0
-453
lib/Components/ExtensionClass/MethodObject.c
lib/Components/ExtensionClass/MethodObject.c
+0
-97
lib/Components/ExtensionClass/Missing.c
lib/Components/ExtensionClass/Missing.c
+0
-377
lib/Components/ExtensionClass/MultiMapping.c
lib/Components/ExtensionClass/MultiMapping.c
+0
-251
lib/Components/ExtensionClass/Record.c
lib/Components/ExtensionClass/Record.c
+0
-694
lib/Components/ExtensionClass/Sync.c
lib/Components/ExtensionClass/Sync.c
+0
-147
lib/Components/ExtensionClass/ThreadLock.c
lib/Components/ExtensionClass/ThreadLock.c
+0
-325
No files found.
lib/Components/ExtensionClass/Acquisition.c
deleted
100644 → 0
View file @
7dbb8830
This diff is collapsed.
Click to expand it.
lib/Components/ExtensionClass/ComputedAttribute.c
deleted
100644 → 0
View file @
7dbb8830
/*
Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions, and the disclaimer that follows.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
o Neither the name of Digital Creations nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
$Id: ComputedAttribute.c,v 1.4 2001/01/23 14:37:20 jim Exp $
If you have questions regarding this software,
contact:
Digital Creations L.C.
info@digicool.com
(540) 371-6909
*/
#include "ExtensionClass.h"
static
void
PyVar_Assign
(
PyObject
**
v
,
PyObject
*
e
)
{
Py_XDECREF
(
*
v
);
*
v
=
e
;
}
#define ASSIGN(V,E) PyVar_Assign(&(V),(E))
#define UNLESS(E) if(!(E))
#define UNLESS_ASSIGN(V,E) ASSIGN(V,E); UNLESS(V)
#define OBJECT(O) ((PyObject*)(O))
typedef
struct
{
PyObject_HEAD
PyObject
*
callable
;
int
level
;
}
CA
;
static
PyObject
*
CA__init__
(
CA
*
self
,
PyObject
*
args
)
{
PyObject
*
callable
;
int
level
=
0
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"O|i"
,
&
callable
,
&
level
))
return
NULL
;
if
(
level
>
0
)
{
callable
=
PyObject_CallFunction
(
OBJECT
(
self
->
ob_type
),
"Oi"
,
callable
,
self
->
level
-
1
);
UNLESS
(
callable
)
return
NULL
;
self
->
level
=
level
;
}
else
{
Py_INCREF
(
callable
);
self
->
level
=
0
;
}
self
->
callable
=
callable
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
void
CA_dealloc
(
CA
*
self
)
{
Py_DECREF
(
self
->
callable
);
Py_DECREF
(
self
->
ob_type
);
PyMem_DEL
(
self
);
}
static
PyObject
*
CA_of
(
CA
*
self
,
PyObject
*
args
)
{
if
(
self
->
level
>
0
)
{
Py_INCREF
(
self
->
callable
);
return
self
->
callable
;
}
if
(
PyString_Check
(
self
->
callable
))
{
/* Special case string as simple alias. */
PyObject
*
o
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"O"
,
&
o
))
return
NULL
;
return
PyObject_GetAttr
(
o
,
self
->
callable
);
}
return
PyObject_CallObject
(
self
->
callable
,
args
);
}
static
struct
PyMethodDef
CA_methods
[]
=
{
{
"__init__"
,(
PyCFunction
)
CA__init__
,
METH_VARARGS
,
""
},
{
"__of__"
,
(
PyCFunction
)
CA_of
,
METH_VARARGS
,
""
},
{
NULL
,
NULL
}
/* sentinel */
};
static
PyExtensionClass
ComputedAttributeType
=
{
PyObject_HEAD_INIT
(
NULL
)
0
,
"ComputedAttribute"
,
sizeof
(
CA
),
0
,
(
destructor
)
CA_dealloc
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
"ComputedAttribute(callable) -- Create a computed attribute"
,
METHOD_CHAIN
(
CA_methods
),
EXTENSIONCLASS_BINDABLE_FLAG
};
static
struct
PyMethodDef
methods
[]
=
{
{
NULL
,
NULL
}
};
void
initComputedAttribute
()
{
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.4 $"
;
UNLESS
(
ExtensionClassImported
)
return
;
ComputedAttributeType
.
tp_getattro
=
(
getattrofunc
)
PyExtensionClassCAPI
->
getattro
;
/* Create the module and add the functions */
m
=
Py_InitModule4
(
"ComputedAttribute"
,
methods
,
"Provide Computed Attributes
\n\n
"
"$Id: ComputedAttribute.c,v 1.4 2001/01/23 14:37:20 jim Exp $
\n
"
,
OBJECT
(
NULL
),
PYTHON_API_VERSION
);
d
=
PyModule_GetDict
(
m
);
PyExtensionClass_Export
(
d
,
"ComputedAttribute"
,
ComputedAttributeType
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
CHECK_FOR_ERRORS
(
"can't initialize module Acquisition"
);
}
lib/Components/ExtensionClass/ExtensionClass.c
deleted
100644 → 0
View file @
7dbb8830
This diff is collapsed.
Click to expand it.
lib/Components/ExtensionClass/ExtensionClass.h
deleted
100644 → 0
View file @
7dbb8830
This diff is collapsed.
Click to expand it.
lib/Components/ExtensionClass/MethodObject.c
deleted
100644 → 0
View file @
7dbb8830
/*
Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions, and the disclaimer that follows.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
o Neither the name of Digital Creations nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
$Id: MethodObject.c,v 1.5 1998/11/17 19:50:20 jim Exp $
If you have questions regarding this software,
contact:
Digital Creations L.C.
info@digicool.com
(540) 371-6909
*/
#include "ExtensionClass.h"
static
PyObject
*
of
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
inst
;
if
(
PyArg_Parse
(
args
,
"O"
,
&
inst
))
return
PyECMethod_New
(
self
,
inst
);
else
return
NULL
;
}
struct
PyMethodDef
Method_methods
[]
=
{
{
"__of__"
,(
PyCFunction
)
of
,
0
,
""
},
{
NULL
,
NULL
}
/* sentinel */
};
static
struct
PyMethodDef
methods
[]
=
{{
NULL
,
NULL
}};
void
initMethodObject
()
{
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.5 $"
;
PURE_MIXIN_CLASS
(
Method
,
"Base class for objects that want to be treated as methods
\n
"
"
\n
"
"The method class provides a method, __of__, that
\n
"
"binds an object to an instance. If a method is a subobject
\n
"
"of an extension-class instance, the the method will be bound
\n
"
"to the instance and when the resulting object is called, it
\n
"
"will call the method and pass the instance in addition to
\n
"
"other arguments. It is the responsibility of Method objects
\n
"
"to implement (or inherit) a __call__ method.
\n
"
,
Method_methods
);
/* Create the module and add the functions */
m
=
Py_InitModule4
(
"MethodObject"
,
methods
,
"Method-object mix-in class module
\n\n
"
"$Id: MethodObject.c,v 1.5 1998/11/17 19:50:20 jim Exp $
\n
"
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
d
=
PyModule_GetDict
(
m
);
PyExtensionClass_Export
(
d
,
"Method"
,
MethodType
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
/* Check for errors */
CHECK_FOR_ERRORS
(
"can't initialize module MethodObject"
);
}
lib/Components/ExtensionClass/Missing.c
deleted
100644 → 0
View file @
7dbb8830
/*
Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions, and the disclaimer that follows.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
o Neither the name of Digital Creations nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
$Id: Missing.c,v 1.10 1999/08/25 20:15:29 jim Exp $
If you have questions regarding this software,
contact:
Digital Creations L.C.
info@digicool.com
(540) 371-6909
*/
static
char
Missing_module_documentation
[]
=
""
"
\n
$Id: Missing.c,v 1.10 1999/08/25 20:15:29 jim Exp $"
;
#include <string.h>
#include "ExtensionClass.h"
/* Declarations for objects of type Missing */
typedef
struct
{
PyObject_HEAD
}
Missing
;
static
PyObject
*
vname
=
0
,
*
Missing_dot_Value
=
0
,
*
empty_string
=
0
,
*
reduce
=
0
;
static
PyObject
*
theValue
;
static
void
Missing_dealloc
(
Missing
*
self
)
{
Py_DECREF
(
self
->
ob_type
);
PyMem_DEL
(
self
);
}
static
PyObject
*
Missing_repr
(
Missing
*
self
)
{
Py_INCREF
(
Missing_dot_Value
);
return
Missing_dot_Value
;
}
static
PyObject
*
Missing_str
(
Missing
*
self
)
{
Py_INCREF
(
empty_string
);
return
empty_string
;
}
/* Code to access Missing objects as numbers */
static
PyObject
*
Missing_bin
(
PyObject
*
v
,
PyObject
*
w
)
{
Py_INCREF
(
v
);
return
v
;
}
static
PyObject
*
Missing_pow
(
PyObject
*
v
,
PyObject
*
w
,
PyObject
*
z
)
{
Py_INCREF
(
v
);
return
v
;
}
static
PyObject
*
Missing_un
(
PyObject
*
v
)
{
Py_INCREF
(
v
);
return
v
;
}
static
int
Missing_nonzero
(
PyObject
*
v
)
{
return
0
;
}
static
int
Missing_coerce
(
PyObject
**
pv
,
PyObject
**
pw
)
{
Py_INCREF
(
*
pv
);
Py_INCREF
(
*
pw
);
return
0
;
}
static
PyObject
*
Missing_int
(
Missing
*
v
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Missing objects do not support conversion to integer"
);
return
NULL
;
}
static
PyObject
*
Missing_long
(
Missing
*
v
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Missing objects do not support conversion to long"
);
return
NULL
;
}
static
PyObject
*
Missing_float
(
Missing
*
v
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Missing objects do not support conversion to float"
);
return
NULL
;
}
static
PyObject
*
Missing_oct
(
Missing
*
v
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Missing objects do not support conversion to an octal string"
);
return
NULL
;
}
static
PyObject
*
Missing_hex
(
Missing
*
v
)
{
PyErr_SetString
(
PyExc_TypeError
,
"Missing objects do not support conversion to hexadecimal strings"
);
return
NULL
;
}
static
PyNumberMethods
Missing_as_number
=
{
(
binaryfunc
)
Missing_bin
,
/*nb_add*/
(
binaryfunc
)
Missing_bin
,
/*nb_subtract*/
(
binaryfunc
)
Missing_bin
,
/*nb_multiply*/
(
binaryfunc
)
Missing_bin
,
/*nb_divide*/
(
binaryfunc
)
Missing_bin
,
/*nb_remainder*/
(
binaryfunc
)
Missing_bin
,
/*nb_divmod*/
(
ternaryfunc
)
Missing_pow
,
/*nb_power*/
(
unaryfunc
)
Missing_un
,
/*nb_negative*/
(
unaryfunc
)
Missing_un
,
/*nb_positive*/
(
unaryfunc
)
Missing_un
,
/*nb_absolute*/
(
inquiry
)
Missing_nonzero
,
/*nb_nonzero*/
(
unaryfunc
)
Missing_un
,
/*nb_invert*/
(
binaryfunc
)
Missing_bin
,
/*nb_lshift*/
(
binaryfunc
)
Missing_bin
,
/*nb_rshift*/
(
binaryfunc
)
Missing_bin
,
/*nb_and*/
(
binaryfunc
)
Missing_bin
,
/*nb_xor*/
(
binaryfunc
)
Missing_bin
,
/*nb_or*/
(
coercion
)
Missing_coerce
,
/*nb_coerce*/
(
unaryfunc
)
Missing_int
,
/*nb_int*/
(
unaryfunc
)
Missing_long
,
/*nb_long*/
(
unaryfunc
)
Missing_float
,
/*nb_float*/
(
unaryfunc
)
Missing_oct
,
/*nb_oct*/
(
unaryfunc
)
Missing_hex
,
/*nb_hex*/
};
/* ------------------------------------------------------- */
static
PyObject
*
Missing_reduce
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kw
)
{
if
(
self
==
theValue
)
{
Py_INCREF
(
vname
);
return
vname
;
}
return
Py_BuildValue
(
"O()"
,
self
->
ob_type
);
}
static
struct
PyMethodDef
reduce_ml
[]
=
{
{
"__reduce__"
,
(
PyCFunction
)
Missing_reduce
,
1
,
"Return a missing value reduced to standard python objects"
}
};
static
PyObject
*
Missing_getattr
(
PyObject
*
self
,
PyObject
*
name
)
{
char
*
c
,
*
legal
;
if
(
!
(
c
=
PyString_AsString
(
name
)))
return
NULL
;
legal
=
c
;
if
(
strchr
(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
,
*
legal
)
!=
NULL
)
{
for
(
legal
++
;
*
legal
;
legal
++
)
if
(
strchr
(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"
,
*
legal
)
==
NULL
)
{
legal
=
NULL
;
break
;
}
}
else
legal
=
NULL
;
if
(
!
legal
)
{
if
(
strcmp
(
c
,
"__reduce__"
)
==
0
)
{
if
(
self
==
theValue
)
{
Py_INCREF
(
reduce
);
return
reduce
;
}
return
PyCFunction_New
(
reduce_ml
,
self
);
}
PyErr_SetObject
(
PyExc_AttributeError
,
name
);
return
NULL
;
}
Py_INCREF
(
self
);
return
self
;
}
static
PyObject
*
Missing_call
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kw
)
{
Py_INCREF
(
self
);
return
self
;
}
static
int
Missing_cmp
(
Missing
*
m1
,
Missing
*
m2
)
{
return
m1
->
ob_type
!=
m2
->
ob_type
;
}
static
PyExtensionClass
MissingType
=
{
PyObject_HEAD_INIT
(
NULL
)
0
,
/*ob_size*/
"Missing"
,
/*tp_name*/
sizeof
(
Missing
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
Missing_dealloc
,
/*tp_dealloc*/
(
printfunc
)
0
,
/*tp_print*/
(
getattrfunc
)
0
,
/*obsolete tp_getattr*/
(
setattrfunc
)
0
,
/*obsolete tp_setattr*/
(
cmpfunc
)
Missing_cmp
,
/*tp_compare*/
(
reprfunc
)
Missing_repr
,
/*tp_repr*/
&
Missing_as_number
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
(
hashfunc
)
0
,
/*tp_hash*/
(
ternaryfunc
)
Missing_call
,
/*tp_call*/
(
reprfunc
)
Missing_str
,
/*tp_str*/
(
getattrofunc
)
Missing_getattr
,
/*tp_getattro*/
(
setattrofunc
)
0
,
/*tp_setattro*/
/* Space for future expansion */
0L
,
0L
,
"Represent totally unknown quantities
\n
"
"
\n
"
"Missing values are used to represent numberic quantities that are
\n
"
"unknown. They support all mathematical operations except
\n
"
"conversions by returning themselves.
\n
"
,
METHOD_CHAIN
(
NULL
)
};
/* End of code for Missing objects */
/* -------------------------------------------------------- */
/* List of methods defined in the module */
static
struct
PyMethodDef
Module_Level__methods
[]
=
{
{
NULL
,
(
PyCFunction
)
NULL
,
0
,
NULL
}
/* sentinel */
};
void
initMissing
()
{
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.10 $"
;
if
(
!
((
vname
=
PyString_FromString
(
"V"
))
&&
(
Missing_dot_Value
=
PyString_FromString
(
"Missing.Value"
))
&&
(
empty_string
=
PyString_FromString
(
""
))
))
return
;
/* Create the module and add the functions */
m
=
Py_InitModule4
(
"Missing"
,
Module_Level__methods
,
Missing_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
/* Add some symbolic constants to the module */
d
=
PyModule_GetDict
(
m
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
PyExtensionClass_Export
(
d
,
"Missing"
,
MissingType
);
theValue
=
PyObject_CallObject
((
PyObject
*
)
&
MissingType
,
NULL
);
reduce
=
PyCFunction_New
(
reduce_ml
,
theValue
);
PyDict_SetItemString
(
d
,
"Value"
,
theValue
);
PyDict_SetItemString
(
d
,
"V"
,
theValue
);
PyDict_SetItemString
(
d
,
"MV"
,
theValue
);
/* Check for errors */
if
(
PyErr_Occurred
())
Py_FatalError
(
"can't initialize module Missing"
);
}
/*****************************************************************************
Revision Log:
$Log: Missing.c,v $
Revision 1.10 1999/08/25 20:15:29 jim
Made getattr a bit pickler to prevent getting attributes like "%f5.3".
Revision 1.9 1999/06/10 20:09:47 jim
Updated to use new ExtensionClass destructor protocol.
Revision 1.8 1998/11/17 19:54:33 jim
new copyright.
Revision 1.7 1997/10/03 14:43:27 jim
Fixed comparison bug, again :-(
Revision 1.6 1997/09/23 16:06:03 jim
Added MV member.
Revision 1.5 1997/09/23 15:17:12 jim
Added cmp.
Revision 1.4 1997/09/18 21:01:33 jim
Added check to getattr to fail on methods that begin with underscore.
Note that Missing really defeats testing from protocols by testing for
attributes.
Revision 1.3 1997/09/17 22:49:35 jim
Fixed refcount bug.
Added logic so: Missing.Value.spam() returns Missing.Value.
Added logic to make Missing.Value picklable.
Revision 1.2 1997/07/02 20:19:37 jim
Got rid of unused macros and ErrorObject.
Revision 1.1 1997/07/01 21:36:34 jim
*****************************************************************************/
lib/Components/ExtensionClass/MultiMapping.c
deleted
100644 → 0
View file @
7dbb8830
/*
Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions, and the disclaimer that follows.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
o Neither the name of Digital Creations nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
$Id: MultiMapping.c,v 1.8 1999/06/10 20:10:46 jim Exp $
If you have questions regarding this software,
contact:
Digital Creations L.C.
info@digicool.com
(540) 371-6909
*/
#include "Python.h"
#include "ExtensionClass.h"
#define UNLESS(E) if(!(E))
typedef
struct
{
PyObject_HEAD
PyObject
*
data
;
}
MMobject
;
staticforward
PyExtensionClass
MMtype
;
static
PyObject
*
MM_push
(
MMobject
*
self
,
PyObject
*
args
)
{
PyObject
*
src
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"O"
,
&
src
))
return
NULL
;
UNLESS
(
-
1
!=
PyList_Append
(
self
->
data
,
src
))
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
MM_pop
(
MMobject
*
self
,
PyObject
*
args
)
{
int
i
=
1
,
l
;
PyObject
*
r
;
if
(
args
)
UNLESS
(
PyArg_ParseTuple
(
args
,
"|i"
,
&
i
))
return
NULL
;
if
((
l
=
PyList_Size
(
self
->
data
))
<
0
)
return
NULL
;
i
=
l
-
i
;
UNLESS
(
r
=
PySequence_GetItem
(
self
->
data
,
l
-
1
))
return
NULL
;
if
(
PyList_SetSlice
(
self
->
data
,
i
,
l
,
NULL
)
<
0
)
goto
err
;
return
r
;
err:
Py_DECREF
(
r
);
return
NULL
;
}
static
PyObject
*
MM__init__
(
MMobject
*
self
,
PyObject
*
args
)
{
UNLESS
(
self
->
data
=
PyList_New
(
0
))
return
NULL
;
if
(
args
)
{
int
l
,
i
;
if
((
l
=
PyTuple_Size
(
args
))
<
0
)
return
NULL
;
for
(
i
=
0
;
i
<
l
;
i
++
)
if
(
PyList_Append
(
self
->
data
,
PyTuple_GET_ITEM
(
args
,
i
))
<
0
)
return
NULL
;
}
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
MM_subscript
(
MMobject
*
self
,
PyObject
*
key
)
{
long
i
;
PyObject
*
e
;
UNLESS
(
-
1
!=
(
i
=
PyList_Size
(
self
->
data
)))
return
NULL
;
while
(
--
i
>=
0
)
{
e
=
PyList_GetItem
(
self
->
data
,
i
);
if
((
e
=
PyObject_GetItem
(
e
,
key
)))
return
e
;
PyErr_Clear
();
}
PyErr_SetObject
(
PyExc_KeyError
,
key
);
return
NULL
;
}
static
PyObject
*
MM_has_key
(
MMobject
*
self
,
PyObject
*
args
)
{
PyObject
*
key
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"O"
,
&
key
))
return
NULL
;
if
((
key
=
MM_subscript
(
self
,
key
)))
{
Py_DECREF
(
key
);
return
PyInt_FromLong
(
1
);
}
PyErr_Clear
();
return
PyInt_FromLong
(
0
);
}
static
PyObject
*
MM_get
(
MMobject
*
self
,
PyObject
*
args
)
{
PyObject
*
key
,
*
d
=
Py_None
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"O|O"
,
&
key
,
&
d
))
return
NULL
;
if
((
key
=
MM_subscript
(
self
,
key
)))
return
key
;
PyErr_Clear
();
Py_INCREF
(
d
);
return
d
;
}
static
struct
PyMethodDef
MM_methods
[]
=
{
{
"__init__"
,
(
PyCFunction
)
MM__init__
,
METH_VARARGS
,
"__init__([m1, m2, ...]) -- Create a new empty multi-mapping"
},
{
"get"
,
(
PyCFunction
)
MM_get
,
METH_VARARGS
,
"get(key,[default]) -- Return a value for the given key or a default"
},
{
"has_key"
,
(
PyCFunction
)
MM_has_key
,
METH_VARARGS
,
"has_key(key) -- Return 1 if the mapping has the key, and 0 otherwise"
},
{
"push"
,
(
PyCFunction
)
MM_push
,
METH_VARARGS
,
"push(mapping_object) -- Add a data source"
},
{
"pop"
,
(
PyCFunction
)
MM_pop
,
METH_VARARGS
,
"pop([n]) -- Remove and return the last data source added"
},
{
NULL
,
NULL
}
/* sentinel */
};
static
void
MM_dealloc
(
MMobject
*
self
)
{
Py_XDECREF
(
self
->
data
);
Py_DECREF
(
self
->
ob_type
);
PyMem_DEL
(
self
);
}
static
PyObject
*
MM_getattr
(
MMobject
*
self
,
char
*
name
)
{
return
Py_FindMethod
(
MM_methods
,
(
PyObject
*
)
self
,
name
);
}
static
int
MM_length
(
MMobject
*
self
)
{
long
l
=
0
,
el
,
i
;
PyObject
*
e
=
0
;
UNLESS
(
-
1
!=
(
i
=
PyList_Size
(
self
->
data
)))
return
-
1
;
while
(
--
i
>=
0
)
{
e
=
PyList_GetItem
(
self
->
data
,
i
);
UNLESS
(
-
1
!=
(
el
=
PyObject_Length
(
e
)))
return
-
1
;
l
+=
el
;
}
return
l
;
}
static
PyMappingMethods
MM_as_mapping
=
{
(
inquiry
)
MM_length
,
/*mp_length*/
(
binaryfunc
)
MM_subscript
,
/*mp_subscript*/
(
objobjargproc
)
NULL
,
/*mp_ass_subscript*/
};
/* -------------------------------------------------------- */
static
char
MMtype__doc__
[]
=
"MultiMapping -- Combine multiple mapping objects for lookup"
;
static
PyExtensionClass
MMtype
=
{
PyObject_HEAD_INIT
(
NULL
)
0
,
/*ob_size*/
"MultiMapping"
,
/*tp_name*/
sizeof
(
MMobject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
MM_dealloc
,
/*tp_dealloc*/
(
printfunc
)
0
,
/*tp_print*/
(
getattrfunc
)
MM_getattr
,
/*tp_getattr*/
(
setattrfunc
)
0
,
/*tp_setattr*/
(
cmpfunc
)
0
,
/*tp_compare*/
(
reprfunc
)
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
&
MM_as_mapping
,
/*tp_as_mapping*/
(
hashfunc
)
0
,
/*tp_hash*/
(
ternaryfunc
)
0
,
/*tp_call*/
(
reprfunc
)
0
,
/*tp_str*/
/* Space for future expansion */
0L
,
0L
,
0L
,
0L
,
MMtype__doc__
,
/* Documentation string */
METHOD_CHAIN
(
MM_methods
)
};
static
struct
PyMethodDef
MultiMapping_methods
[]
=
{
{
NULL
,
NULL
}
/* sentinel */
};
void
initMultiMapping
()
{
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.8 $"
;
m
=
Py_InitModule4
(
"MultiMapping"
,
MultiMapping_methods
,
"MultiMapping -- Wrap multiple mapping objects for lookup"
"
\n\n
"
"$Id: MultiMapping.c,v 1.8 1999/06/10 20:10:46 jim Exp $
\n
"
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
d
=
PyModule_GetDict
(
m
);
PyExtensionClass_Export
(
d
,
"MultiMapping"
,
MMtype
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
if
(
PyErr_Occurred
())
Py_FatalError
(
"can't initialize module MultiMapping"
);
}
lib/Components/ExtensionClass/Record.c
deleted
100644 → 0
View file @
7dbb8830
This diff is collapsed.
Click to expand it.
lib/Components/ExtensionClass/Sync.c
deleted
100644 → 0
View file @
7dbb8830
/*
Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions, and the disclaimer that follows.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
o Neither the name of Digital Creations nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
$Id: Sync.c,v 1.2 1998/11/17 20:22:34 jim Exp $
If you have questions regarding this software,
contact:
Digital Creations L.C.
info@digicool.com
(540) 371-6909
*/
static
char
Sync_module_documentation
[]
=
""
"
\n
$Id: Sync.c,v 1.2 1998/11/17 20:22:34 jim Exp $"
;
#include "ExtensionClass.h"
static
PyObject
*
ErrorObject
;
/* ----------------------------------------------------- */
static
void
PyVar_Assign
(
PyObject
**
v
,
PyObject
*
e
)
{
Py_XDECREF
(
*
v
);
*
v
=
e
;}
#define ASSIGN(V,E) PyVar_Assign(&(V),(E))
#define UNLESS(E) if(!(E))
#define UNLESS_ASSIGN(V,E) ASSIGN(V,E); UNLESS(V)
#define OBJECT(O) ((PyObject*)(O))
PyObject
*
lockstr
,
*
aqstr
,
*
restr
,
*
newlock
;
static
PyObject
*
Synchronized___call_method__
(
PyObject
*
self
,
PyObject
*
args
)
{
PyObject
*
f
,
*
a
,
*
k
=
0
,
*
l
=
0
,
*
aq
=
0
,
*
t
,
*
v
,
*
tb
,
*
r
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"OO|O"
,
&
f
,
&
a
,
&
k
))
return
NULL
;
UNLESS
(
l
=
PyObject_GetAttr
(
self
,
lockstr
))
{
PyErr_Clear
();
UNLESS
(
l
=
PyObject_CallObject
(
newlock
,
NULL
))
return
NULL
;
if
(
PyObject_SetAttr
(
self
,
lockstr
,
l
)
<
0
)
goto
err
;
}
UNLESS
(
aq
=
PyObject_GetAttr
(
l
,
aqstr
))
goto
err
;
UNLESS_ASSIGN
(
aq
,
PyObject_CallObject
(
aq
,
NULL
))
goto
err
;
if
(
k
)
r
=
PyEval_CallObjectWithKeywords
(
f
,
a
,
k
);
else
r
=
PyObject_CallObject
(
f
,
a
);
PyErr_Fetch
(
&
t
,
&
v
,
&
tb
);
ASSIGN
(
aq
,
PyObject_GetAttr
(
l
,
restr
));
if
(
aq
)
ASSIGN
(
aq
,
PyObject_CallObject
(
aq
,
NULL
));
Py_XDECREF
(
aq
);
Py_DECREF
(
l
);
PyErr_Restore
(
t
,
v
,
tb
);
return
r
;
err:
Py_DECREF
(
l
);
return
NULL
;
}
static
struct
PyMethodDef
Synchronized_methods
[]
=
{
{
"__call_method__"
,
(
PyCFunction
)
Synchronized___call_method__
,
METH_VARARGS
,
"Call a method by first getting a thread lock"
},
{
NULL
,
NULL
}
};
static
struct
PyMethodDef
Module_Level__methods
[]
=
{
{
NULL
,
(
PyCFunction
)
NULL
,
0
,
NULL
}
};
void
initSync
()
{
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.2 $"
;
PURE_MIXIN_CLASS
(
Synchronized
,
"Mix-in class that provides synchonization of method calls
\n
"
"
\n
"
"Only one thread is allowed to call a synchronized
\n
"
"object's methods.
\n
"
,
Synchronized_methods
);
UNLESS
((
lockstr
=
PyString_FromString
(
"_sync__lock"
))
&&
(
aqstr
=
PyString_FromString
(
"acquire"
))
&&
(
restr
=
PyString_FromString
(
"release"
))
&&
(
newlock
=
PyImport_ImportModule
(
"ThreadLock"
))
)
return
;
ASSIGN
(
newlock
,
PyObject_GetAttrString
(
newlock
,
"allocate_lock"
));
UNLESS
(
newlock
)
return
;
m
=
Py_InitModule4
(
"Sync"
,
Module_Level__methods
,
Sync_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
d
=
PyModule_GetDict
(
m
);
PyExtensionClass_Export
(
d
,
"Synchronized"
,
SynchronizedType
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
CHECK_FOR_ERRORS
(
"can't initialize module MethodObject"
);
}
lib/Components/ExtensionClass/ThreadLock.c
deleted
100644 → 0
View file @
7dbb8830
/*
Copyright (c) 1996-1998, Digital Creations, Fredericksburg, VA, USA.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
o Redistributions of source code must retain the above copyright
notice, this list of conditions, and the disclaimer that follows.
o Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
o Neither the name of Digital Creations nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS AND CONTRIBUTORS *AS
IS* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL
CREATIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
$Id: ThreadLock.c,v 1.7 1999/02/19 16:10:05 jim Exp $
If you have questions regarding this software,
contact:
Digital Creations L.C.
info@digicool.com
(540) 371-6909
*/
static
char
ThreadLock_module_documentation
[]
=
""
"
\n
$Id: ThreadLock.c,v 1.7 1999/02/19 16:10:05 jim Exp $"
;
#include "Python.h"
#ifdef WITH_THREAD
#include "listobject.h"
#ifdef PyList_SET_ITEM
#include "pythread.h"
#define get_thread_ident PyThread_get_thread_ident
#define acquire_lock PyThread_acquire_lock
#define release_lock PyThread_release_lock
#define type_lock PyThread_type_lock
#define free_lock PyThread_free_lock
#define allocate_lock PyThread_allocate_lock
#else
#include "thread.h"
#endif
#endif
static
PyObject
*
ErrorObject
;
/* ----------------------------------------------------- */
#define UNLESS(E) if(!(E))
/* Declarations for objects of type ThreadLock */
typedef
struct
{
PyObject_HEAD
int
count
;
long
id
;
#ifdef WITH_THREAD
type_lock
lock
;
#endif
}
ThreadLockObject
;
staticforward
PyTypeObject
ThreadLockType
;
static
int
cacquire
(
ThreadLockObject
*
self
)
{
#ifdef WITH_THREAD
long
id
=
get_thread_ident
();
#else
long
id
=
1
;
#endif
if
(
self
->
count
>=
0
&&
self
->
id
==
id
)
{
/* Somebody has locked me. It is either the current thread or
another thread. */
/* So this thread has it. I can't have a race condition, because,
if another thread had the lock, then the id would not be this
one. */
self
->
count
++
;
}
else
{
#ifdef WITH_THREAD
Py_BEGIN_ALLOW_THREADS
acquire_lock
(
self
->
lock
,
1
);
Py_END_ALLOW_THREADS
#endif
self
->
count
=
0
;
self
->
id
=
id
;
}
return
0
;
}
static
PyObject
*
acquire
(
ThreadLockObject
*
self
,
PyObject
*
args
)
{
if
(
cacquire
(
self
)
<
0
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
int
crelease
(
ThreadLockObject
*
self
)
{
#ifdef WITH_THREAD
long
id
=
get_thread_ident
();
#else
long
id
=
1
;
#endif
if
(
self
->
count
>=
0
&&
self
->
id
==
id
)
{
/* Somebody has locked me. It is either the current thread or
another thread. */
/* So this thread has it. I can't have a race condition, because,
if another thread had the lock, then the id would not be this
one. */
self
->
count
--
;
#ifdef WITH_THREAD
if
(
self
->
count
<
0
)
release_lock
(
self
->
lock
);
#endif
}
else
{
PyErr_SetString
(
ErrorObject
,
"release unlocked lock"
);
return
-
1
;
}
return
0
;
}
static
PyObject
*
release
(
ThreadLockObject
*
self
,
PyObject
*
args
)
{
if
(
crelease
(
self
)
<
0
)
return
NULL
;
Py_INCREF
(
Py_None
);
return
Py_None
;
}
static
PyObject
*
call_method
(
ThreadLockObject
*
self
,
PyObject
*
args
)
{
PyObject
*
f
,
*
a
=
0
,
*
k
=
0
;
UNLESS
(
PyArg_ParseTuple
(
args
,
"OO|O"
,
&
f
,
&
a
,
&
k
))
return
NULL
;
if
(
cacquire
(
self
)
<
0
)
return
NULL
;
f
=
PyEval_CallObjectWithKeywords
(
f
,
a
,
k
);
if
(
crelease
(
self
)
<
0
)
{
Py_XDECREF
(
f
);
f
=
NULL
;
}
return
f
;
}
static
struct
PyMethodDef
ThreadLock_methods
[]
=
{
{
"guarded_apply"
,
(
PyCFunction
)
call_method
,
1
,
"guarded_apply(FUNCTION, ARGS[, KEYWORDS]) -- Make a guarded function call
\n
"
"
\n
"
"Acquire the lock, call the function, and then release the lock.
\n
"
},
{
"acquire"
,
(
PyCFunction
)
acquire
,
1
,
"acquire() -- Acquire a lock, taking the thread ID into account"
},
{
"release"
,
(
PyCFunction
)
release
,
1
,
"release() -- Release a lock, taking the thread ID into account"
},
{
NULL
,
NULL
}
/* sentinel */
};
static
void
ThreadLock_dealloc
(
ThreadLockObject
*
self
)
{
#ifdef WITH_THREAD
free_lock
(
self
->
lock
);
#endif
PyMem_DEL
(
self
);
}
static
PyObject
*
ThreadLock_getattr
(
ThreadLockObject
*
self
,
PyObject
*
name
)
{
char
*
cname
;
if
((
cname
=
PyString_AsString
(
name
)))
{
if
(
*
cname
==
'c'
&&
strcmp
(
cname
,
"count"
)
==
0
)
return
PyInt_FromLong
(
self
->
count
);
if
(
*
cname
==
'i'
&&
strcmp
(
cname
,
"id"
)
==
0
)
return
PyInt_FromLong
(
self
->
id
);
return
Py_FindMethod
(
ThreadLock_methods
,
(
PyObject
*
)
self
,
cname
);
}
PyErr_SetObject
(
PyExc_AttributeError
,
name
);
return
NULL
;
}
static
PyTypeObject
ThreadLockType
=
{
PyObject_HEAD_INIT
(
NULL
)
0
,
/*ob_size*/
"ThreadLock"
,
/*tp_name*/
sizeof
(
ThreadLockObject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
/* methods */
(
destructor
)
ThreadLock_dealloc
,
/*tp_dealloc*/
(
printfunc
)
0
,
/*tp_print*/
(
getattrfunc
)
0
,
/*obsolete tp_getattr*/
(
setattrfunc
)
0
,
/*obsolete tp_setattr*/
(
cmpfunc
)
0
,
/*tp_compare*/
(
reprfunc
)
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
(
hashfunc
)
0
,
/*tp_hash*/
(
ternaryfunc
)
0
,
/*tp_call*/
(
reprfunc
)
0
,
/*tp_str*/
(
getattrofunc
)
ThreadLock_getattr
,
/*tp_getattro*/
0
,
/*tp_setattro*/
/* Space for future expansion */
0L
,
0L
,
"Thread-based lock objects
\n
"
"
\n
"
"These lock objects may be allocated multiple times by the same
\n
"
"thread, but may only be allocated by one thread at a time.
\n
"
"This is useful for locking instances in possibly nested method calls
\n
"
};
static
PyObject
*
newThreadLockObject
(
ThreadLockObject
*
self
,
PyObject
*
args
)
{
UNLESS
(
PyArg_ParseTuple
(
args
,
""
))
return
NULL
;
UNLESS
(
self
=
PyObject_NEW
(
ThreadLockObject
,
&
ThreadLockType
))
return
NULL
;
self
->
count
=-
1
;
#ifdef WITH_THREAD
self
->
lock
=
allocate_lock
();
if
(
self
->
lock
==
NULL
)
{
PyMem_DEL
(
self
);
self
=
NULL
;
PyErr_SetString
(
ErrorObject
,
"can't allocate lock"
);
}
#endif
return
(
PyObject
*
)
self
;
}
static
PyObject
*
ident
(
PyObject
*
self
,
PyObject
*
args
)
{
#ifdef WITH_THREAD
return
PyInt_FromLong
(
get_thread_ident
());
#else
return
PyInt_FromLong
(
0
);
#endif
}
static
struct
PyMethodDef
Module_methods
[]
=
{
{
"allocate_lock"
,
(
PyCFunction
)
newThreadLockObject
,
1
,
"allocate_lock() -- Return a new lock object"
},
{
"get_ident"
,
(
PyCFunction
)
ident
,
1
,
"get_ident() -- Get the id of the current thread"
},
{
NULL
,
(
PyCFunction
)
NULL
,
0
,
NULL
}
/* sentinel */
};
void
initThreadLock
()
{
PyObject
*
m
,
*
d
;
char
*
rev
=
"$Revision: 1.7 $"
;
m
=
Py_InitModule4
(
"ThreadLock"
,
Module_methods
,
ThreadLock_module_documentation
,
(
PyObject
*
)
NULL
,
PYTHON_API_VERSION
);
d
=
PyModule_GetDict
(
m
);
ThreadLockType
.
ob_type
=&
PyType_Type
;
PyDict_SetItemString
(
d
,
"ThreadLockType"
,
(
PyObject
*
)
&
ThreadLockType
);
ErrorObject
=
PyString_FromString
(
"ThreadLock.error"
);
PyDict_SetItemString
(
d
,
"error"
,
ErrorObject
);
PyDict_SetItemString
(
d
,
"__version__"
,
PyString_FromStringAndSize
(
rev
+
11
,
strlen
(
rev
+
11
)
-
2
));
#ifdef WITH_THREAD
PyDict_SetItemString
(
d
,
"WITH_THREAD"
,
PyInt_FromLong
(
1
));
#else
PyDict_SetItemString
(
d
,
"WITH_THREAD"
,
Py_None
);
#endif
/* Check for errors */
if
(
PyErr_Occurred
())
Py_FatalError
(
"can't initialize module ThreadLock"
);
}
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