- Previous segmentation fault was due to a faulty call (wrong parameters

to ScriptAdapter.__wrap_sort_queue()). Now prints an error and check
for retval before Py_DECREF'ing it.
- Fix(?) qsort implementation in Policy
- SWIG doesn't understand "uint". Change into more verbose (but surely
standard) unsigned int


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@394 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-23 10:12:27 +00:00
parent 075e12d14d
commit a2a492b5d5
5 changed files with 28 additions and 26 deletions

View File

@ -1,4 +1,4 @@
from Abstract import *
from Abstract import *
## @brief This is the abstract class a user-defined policy
# should inherit from
@ -28,8 +28,8 @@ class Policy:
# @param queue The SchedulableQueue to be sorted in place
# @param cmpf The binary function to use to compare elements
# @returns None
def sort(queue, cmpf):
__recursive_qsort_(queue, 0, queue.size()-1, cmpf)
def sort(self, queue, cmpf):
self.__recursive_qsort(queue, 0, queue.size()-1, cmpf)
## @brief Recursive (private) call to perform quicksort on a
# queue
@ -39,12 +39,12 @@ class Policy:
# @param b The final element position of the slice
# @param cmpf The user-defined compare function to employ
# @returns None
def __recursive_qsort_(queue, a, b, cmpf):
def __recursive_qsort(self, queue, a, b, cmpf):
if(b>a):
pivot = __partition_(queue, a, b, cmpf)
__recursive_qsort_(queue, a, pivot-1, cmpf)
__recursive_qsort_(queue, pivot+1, b, cmpf)
pivot = self.__partition(queue, a, b, cmpf)
self.__recursive_qsort(queue, a, pivot-1, cmpf)
self.__recursive_qsort(queue, pivot+1, b, cmpf)
## @brief Recursive (private) call to partition a slice of the queue
#
# This private function (the name mangling should work)
@ -58,11 +58,11 @@ class Policy:
# @param b The partition ending element position in the queue
# @param cmpf The binary function to use for comparing two elements
# @return The new pivot index
def __partition_(queue, a, b, cmpf):
def __partition_(self, queue, a, b, cmpf):
# takes pivot element:
right = queue.get_item_at(b)
i = a
for j in range(a,b-1):
for j in range(a,b): # goes from a to b-1
if cmpf(queue.get_item_at(j), right):
# the C++ code should do nothing if i == j:
queue.swap(i,j)

View File

@ -21,15 +21,14 @@ _ret_val = None
# @endcode
class ScriptAdapter :
_policy = None
_event = None
def __init__(self, policy):
self._policy = policy()
print 'ScriptAdapter for policy ', policy, ' loaded'
def async_configure(self):
print 'Calling ', self._policy, ' configure() method.'
_g_mutex.lock(ScriptAdapter._wrap_configure, self )
print 'Returning from configure() method'
def _wrap_configure(self):
thread.start_new_thread(ScriptAdapter._wrap_configure_callback, (self,))
@ -40,10 +39,12 @@ class ScriptAdapter :
_g_mutex.unlock()
def async_sort_queue(self, event):
_g_mutex.lock(ScriptAdapter._wrap_sort_queue, (self, event))
self._event = event
_g_mutex.lock(ScriptAdapter._wrap_sort_queue, self)
def _wrap_sort_queue(self, event):
thread.start_new_thread(ScriptAdapter._wrap_sort_queue_callback, (self, event))
def _wrap_sort_queue(self):
thread.start_new_thread(ScriptAdapter._wrap_sort_queue_callback,
(self,self._event))
def _wrap_sort_queue_callback(self, event):
# here we retrieve and pass the ready queue

View File

@ -19,6 +19,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "python_policy.hh"
#include <iostream>
#include <unistd.h>
using namespace sgpem;
using namespace std;
@ -103,8 +104,8 @@ PythonPolicy::sort_queue(Scheduler::event event) const
PyObject* pEvent = PyInt_FromLong(event);
PyObject* pMethodName = PyString_FromString("async_sort_queue");
PyObject* retval = PyObject_CallMethodObjArgs(_adapter, pMethodName, pEvent, NULL);
// Why we haven't to decref this?
// Py_DECREF(retval);
if(!retval) PyErr_Print();
else Py_DECREF(retval);
Py_DECREF(pMethodName);
Py_DECREF(pEvent);

View File

@ -40,13 +40,13 @@ namespace sgpem
bool operator==(const SchedulableList&) const;
bool has_same_objects(const SchedulableList& dx) const;
sgpem::SchedulableStatus* top();
sgpem::SchedulableStatus* bottom();
void add_at_bottom(const sgpem::SchedulableStatus&);
void add_at_top(const sgpem::SchedulableStatus&);
memory::smart_ptr<sgpem::SchedulableStatus> remove(const uint& position);
bool insert_at(const uint&, const uint&);
uint size() const;
SchedulableStatus* top();
SchedulableStatus* bottom();
void add_at_bottom(const SchedulableStatus&);
void add_at_top(const SchedulableStatus&);
memory::smart_ptr<sgpem::SchedulableStatus> remove(const unsigned int& position);
bool insert_at(const unsigned int&, const unsigned int&);
unsigned int size() const;
SchedulableStatus* get_item_at(const uint&);
const SchedulableStatus* get_item_at(const uint&) const;
void clear();

View File

@ -126,8 +126,8 @@ namespace sgpem {
class SchedulableList
{
public:
uint size() const;
const SchedulableStatus* get_item_at(const uint&) const;
unsigned int size() const;
const SchedulableStatus* get_item_at(const unsigned int&) const;
void swap(unsigned int positionA, unsigned int positionB) throw();
private: