Commit 0bd6a9c6 authored by Jeremy Hylton's avatar Jeremy Hylton

Remove unused Sync module.

Remove unnecessary Py_FatalError() calls on failed module import.
parent 22ac2d3a
*shared*
ExtensionClass ExtensionClass.c
Acquisition Acquisition.c
MethodObject MethodObject.c
MultiMapping MultiMapping.c
ThreadLock ThreadLock.c
Missing Missing.c
Sync Sync.c
Record Record.c
ComputedAttribute ComputedAttribute.c
......@@ -74,8 +74,6 @@ MultiMapping = Extension(name = 'MultiMapping',
Record = Extension(name = 'Record', sources = ['src/Record.c'])
Sync = Extension(name = 'Sync', sources = ['src/Sync.c'])
ThreadLock = Extension(name = 'ThreadLock',
sources = ['src/ThreadLock.c'])
......@@ -87,7 +85,7 @@ setup(name = "ExtensionClass",
url = "http://www.zope.com",
ext_modules = [ExtensionClass, Acquisition, ComputedAttribute,
MethodObject, Missing, MultiMapping, Sync,
MethodObject, Missing, MultiMapping,
ThreadLock, Record],
headers = ["src/ExtensionClass.h"],
......
......@@ -1515,7 +1515,7 @@ initAcquisition(void)
/* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.59 2002/06/10 22:48:46 jeremy Exp $\n",
"$Id: Acquisition.c,v 1.60 2002/11/13 17:45:53 jeremy Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m);
......@@ -1542,6 +1542,4 @@ initAcquisition(void)
api = PyCObject_FromVoidPtr(&AcquisitionCAPI, NULL);
PyDict_SetItemString(d, "AcquisitionCAPI", api);
Py_DECREF(api);
CHECK_FOR_ERRORS("can't initialize module Acquisition");
}
......@@ -112,10 +112,9 @@ initComputedAttribute(void)
/* Create the module and add the functions */
m = Py_InitModule4("ComputedAttribute", methods,
"Provide Computed Attributes\n\n"
"$Id: ComputedAttribute.c,v 1.7 2002/06/10 22:48:46 jeremy Exp $\n",
"$Id: ComputedAttribute.c,v 1.8 2002/11/13 17:45:53 jeremy Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m);
PyExtensionClass_Export(d,"ComputedAttribute",ComputedAttributeType);
CHECK_FOR_ERRORS("can't initialize module Acquisition");
}
......@@ -49,13 +49,10 @@ initMethodObject(void)
/* 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.8 2002/06/10 22:48:46 jeremy Exp $\n",
"$Id: MethodObject.c,v 1.9 2002/11/13 17:45:53 jeremy Exp $\n",
(PyObject*)NULL,PYTHON_API_VERSION);
d = PyModule_GetDict(m);
PyExtensionClass_Export(d,"Method",MethodType);
/* Check for errors */
CHECK_FOR_ERRORS("can't initialize module MethodObject");
}
......@@ -14,7 +14,7 @@
static char Missing_module_documentation[] =
""
"\n$Id: Missing.c,v 1.14 2002/11/12 20:06:00 jeremy Exp $"
"\n$Id: Missing.c,v 1.15 2002/11/13 17:45:53 jeremy Exp $"
;
#include "ExtensionClass.h"
......@@ -292,16 +292,16 @@ initMissing(void)
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.15 2002/11/13 17:45:53 jeremy
Remove unused Sync module.
Remove unnecessary Py_FatalError() calls on failed module import.
Revision 1.14 2002/11/12 20:06:00 jeremy
Remove bogus include.
......
......@@ -14,7 +14,7 @@
static char Record_module_documentation[] =
""
"\n$Id: Record.c,v 1.17 2002/06/10 22:48:46 jeremy Exp $"
"\n$Id: Record.c,v 1.18 2002/11/13 17:45:53 jeremy Exp $"
;
#ifdef PERSISTENCE
......@@ -548,7 +548,4 @@ initRecord(void)
d = PyModule_GetDict(m);
PyExtensionClass_Export(d,"Record",RecordType);
/* Check for errors */
if (PyErr_Occurred()) Py_FatalError("can't initialize module Record");
}
/*****************************************************************************
Copyright (c) 1996-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
****************************************************************************/
static char Sync_module_documentation[] =
""
"\n$Id: Sync.c,v 1.5 2002/06/10 22:48:46 jeremy Exp $"
;
#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))
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(void)
{
PyObject *m, *d;
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);
CHECK_FOR_ERRORS("can't initialize module MethodObject");
}
##############################################################################
#
# Copyright (c) 1996-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
#
##############################################################################
from Sync import Synchronized
import thread
from random import random
from time import sleep
class P(Synchronized):
def __init__(self,*args,**kw):
self.count=0
def inc(self):
c = self.count
if random() > 0.7:
sleep(1)
self.count = self.count + 1
return c, self.count
def incn(self,n):
c = self.count
for i in range(n):
self.inc()
return c, self.count
p = P(1, 2, spam=3)
def test():
for i in range(8):
n = 3
old, new = p.incn(n)
if old + n != new:
print 'oops'
sleep(2)
thread_finished()
def thread_finished(lock=thread.allocate_lock()):
global num_threads
lock.acquire()
num_threads = num_threads - 1
lock.release()
num_threads = 8
for i in range(num_threads):
thread.start_new_thread(test, ())
while num_threads > 0:
sleep(1)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment