Remove Python swigrun example
By default it doesn't work as it does not call the CEO's __del__ method as indicated in the comments. __del__ is called with -builtin but then the base class's __del__ is not available and so it errors out. Python 3 and -builtin goes into an endless loop. So removing as hopelessly broken.
This commit is contained in:
parent
a9c6196f71
commit
da394fae80
6 changed files with 0 additions and 145 deletions
|
|
@ -24,7 +24,6 @@ simple
|
||||||
smartptr
|
smartptr
|
||||||
std_vector
|
std_vector
|
||||||
std_map
|
std_map
|
||||||
swigrun
|
|
||||||
template
|
template
|
||||||
varargs
|
varargs
|
||||||
variables
|
variables
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
TOP = ../..
|
|
||||||
SWIG = $(TOP)/../preinst-swig
|
|
||||||
CXXSRCS = example.cxx
|
|
||||||
TARGET = example
|
|
||||||
INTERFACE = example.i
|
|
||||||
LIBS = -lm
|
|
||||||
SWIGOPT =
|
|
||||||
|
|
||||||
check: build
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
|
|
||||||
|
|
||||||
build:
|
|
||||||
$(SWIG) -python -external-runtime
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
|
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean
|
|
||||||
rm -f swigpyrun.h
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
/* File : example.cxx */
|
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include "swigpyrun.h"
|
|
||||||
#include "example.h"
|
|
||||||
|
|
||||||
|
|
||||||
Manager* convert_to_Manager(PyObject *py_obj)
|
|
||||||
{
|
|
||||||
Manager* c_ptr;
|
|
||||||
swig_type_info *ty = SWIG_TypeQuery("Manager *");
|
|
||||||
printf("manager ty %p \n", (void *)ty);
|
|
||||||
if (SWIG_ConvertPtr(py_obj, (void **) &c_ptr, ty, 0) == -1) {
|
|
||||||
c_ptr = 0;
|
|
||||||
} else {
|
|
||||||
Py_XINCREF(py_obj);
|
|
||||||
}
|
|
||||||
return c_ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,58 +0,0 @@
|
||||||
/* File : example.h */
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
class Employee {
|
|
||||||
private:
|
|
||||||
std::string name;
|
|
||||||
public:
|
|
||||||
Employee(const char* n): name(n) {}
|
|
||||||
virtual std::string getTitle() { return getPosition() + " " + getName(); }
|
|
||||||
virtual std::string getName() { return name; }
|
|
||||||
virtual std::string getPosition() const { return "Employee"; }
|
|
||||||
virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class Manager: public Employee {
|
|
||||||
public:
|
|
||||||
Manager(const char* n): Employee(n) {}
|
|
||||||
virtual std::string getPosition() const { return "Manager"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class EmployeeList {
|
|
||||||
std::vector<Employee*> list;
|
|
||||||
public:
|
|
||||||
EmployeeList() {
|
|
||||||
list.push_back(new Employee("Bob"));
|
|
||||||
list.push_back(new Employee("Jane"));
|
|
||||||
list.push_back(new Manager("Ted"));
|
|
||||||
}
|
|
||||||
void addEmployee(Employee *p) {
|
|
||||||
list.push_back(p);
|
|
||||||
std::cout << "New employee added. Current employees are:" << std::endl;
|
|
||||||
std::vector<Employee*>::iterator i;
|
|
||||||
for (i=list.begin(); i!=list.end(); i++) {
|
|
||||||
std::cout << " " << (*i)->getTitle() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const Employee *get_item(int i) {
|
|
||||||
return list[i];
|
|
||||||
}
|
|
||||||
~EmployeeList() {
|
|
||||||
std::vector<Employee*>::iterator i;
|
|
||||||
std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
|
|
||||||
for (i=list.begin(); i!=list.end(); i++) {
|
|
||||||
delete *i;
|
|
||||||
}
|
|
||||||
std::cout << "~EmployeeList empty." << std::endl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Manager* convert_to_Manager(PyObject *obj);
|
|
||||||
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
/* File : example.i */
|
|
||||||
%module(directors="1") example
|
|
||||||
%{
|
|
||||||
#include "example.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
%include "std_vector.i"
|
|
||||||
%include "std_string.i"
|
|
||||||
|
|
||||||
/* turn on director wrapping for Manager */
|
|
||||||
%feature("director") Employee;
|
|
||||||
%feature("director") Manager;
|
|
||||||
|
|
||||||
%include "example.h"
|
|
||||||
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
# file: runme.py
|
|
||||||
|
|
||||||
# This file illustrates the cross language polymorphism using directors.
|
|
||||||
|
|
||||||
import example
|
|
||||||
|
|
||||||
|
|
||||||
# CEO class, which overrides Employee::getPosition().
|
|
||||||
|
|
||||||
class CEO(example.Manager):
|
|
||||||
def __init__(self, name):
|
|
||||||
example.Manager.__init__(self, name)
|
|
||||||
def getPosition(self):
|
|
||||||
return "CEO"
|
|
||||||
def __del__(self):
|
|
||||||
print "CEO.__del__(),", self.getName()
|
|
||||||
# for proxy class extensions that are not "disowned" and
|
|
||||||
# define a __del__ method, it is very important to call the
|
|
||||||
# base class __del__. otherwise the c++ objects will never
|
|
||||||
# be deleted.
|
|
||||||
example.Manager.__del__(self)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
e = CEO("Alice")
|
|
||||||
m = example.convert_to_Manager(e)
|
|
||||||
print m
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue