fix private new operator
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6658 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
44009421a8
commit
f81cf97c35
3 changed files with 52 additions and 3 deletions
|
|
@ -20,6 +20,27 @@
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
class TROOT {
|
||||||
|
protected:
|
||||||
|
void *operator new(size_t l) { return malloc(sizeof(TROOT)); }
|
||||||
|
|
||||||
|
public:
|
||||||
|
TROOT()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
TROOT(const char *name, const char *title, void *initfunc = 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class A : public TROOT
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
#ifdef SWIGPYTHON
|
#ifdef SWIGPYTHON
|
||||||
|
|
||||||
// This case only works in python
|
// This case only works in python
|
||||||
|
|
@ -32,4 +53,5 @@
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -514,6 +514,22 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Getattr(n,"allocate:has_new")) {
|
||||||
|
/* No destructor was defined. We need to check a few things here too */
|
||||||
|
List *bases = Getattr(n,"bases");
|
||||||
|
int allows_new = 1;
|
||||||
|
|
||||||
|
for (int i = 0; i < Len(bases); i++) {
|
||||||
|
Node *n = Getitem(bases,i);
|
||||||
|
/* If base class does not allow default destructor, we don't allow it either */
|
||||||
|
if (Getattr(n,"allocate:has_new")) {
|
||||||
|
allows_new = !Getattr(n,"allocate:nonew");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!allows_new) {
|
||||||
|
Setattr(n,"allocate:nonew","1");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if base classes allow smart pointers, but might be hidden */
|
/* Check if base classes allow smart pointers, but might be hidden */
|
||||||
if (!Getattr(n,"allocate:smartpointer")) {
|
if (!Getattr(n,"allocate:smartpointer")) {
|
||||||
|
|
@ -569,14 +585,20 @@ public:
|
||||||
|
|
||||||
String *name = Getattr(n,"name");
|
String *name = Getattr(n,"name");
|
||||||
if (cplus_mode != PUBLIC) {
|
if (cplus_mode != PUBLIC) {
|
||||||
/* Look for a private assignment operator */
|
|
||||||
if (Strcmp(name,"operator =") == 0) {
|
if (Strcmp(name,"operator =") == 0) {
|
||||||
|
/* Look for a private assignment operator */
|
||||||
Setattr(inclass,"allocate:has_assign","1");
|
Setattr(inclass,"allocate:has_assign","1");
|
||||||
Setattr(inclass,"allocate:noassign","1");
|
Setattr(inclass,"allocate:noassign","1");
|
||||||
|
} else if (Strcmp(name,"operator new") == 0) {
|
||||||
|
/* Look for a private new operator */
|
||||||
|
Setattr(inclass,"allocate:has_new","1");
|
||||||
|
Setattr(inclass,"allocate:nonew","1");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (Strcmp(name,"operator =") == 0) {
|
if (Strcmp(name,"operator =") == 0) {
|
||||||
Setattr(inclass,"allocate:has_assign","1");
|
Setattr(inclass,"allocate:has_assign","1");
|
||||||
|
} else if (Strcmp(name,"operator new") == 0) {
|
||||||
|
Setattr(inclass,"allocate:has_new","1");
|
||||||
}
|
}
|
||||||
/* Look for smart pointer operator */
|
/* Look for smart pointer operator */
|
||||||
if ((Strcmp(name,"operator ->") == 0) && (!Getattr(n,"feature:ignore"))) {
|
if ((Strcmp(name,"operator ->") == 0) && (!Getattr(n,"feature:ignore"))) {
|
||||||
|
|
|
||||||
|
|
@ -1544,8 +1544,9 @@ int Language::unrollVirtualMethods(Node *n,
|
||||||
if ((Cmp(nodeType, "cdecl") == 0)|| is_destructor) {
|
if ((Cmp(nodeType, "cdecl") == 0)|| is_destructor) {
|
||||||
decl = Getattr(ni, "decl");
|
decl = Getattr(ni, "decl");
|
||||||
/* extra check for function type and proper access */
|
/* extra check for function type and proper access */
|
||||||
if (SwigType_isfunction(decl) &&
|
if (SwigType_isfunction(decl)
|
||||||
(is_public(ni) || need_nonpublic_member(ni))) {
|
&& (is_public(n) || need_nonpublic_member(n))
|
||||||
|
&& (is_public(ni) || need_nonpublic_member(ni))) {
|
||||||
String *name = Getattr(ni, "name");
|
String *name = Getattr(ni, "name");
|
||||||
String *local_decl = SwigType_typedef_resolve_all(decl);
|
String *local_decl = SwigType_typedef_resolve_all(decl);
|
||||||
Node *method_id = is_destructor ? NewStringf("~destructor") : NewStringf("%s|%s", name, local_decl);
|
Node *method_id = is_destructor ? NewStringf("~destructor") : NewStringf("%s|%s", name, local_decl);
|
||||||
|
|
@ -1690,6 +1691,7 @@ int Language::classDirectorConstructors(Node *n) {
|
||||||
int default_ctor = Getattr(parent,"allocate:default_constructor") ? 1 : 0;
|
int default_ctor = Getattr(parent,"allocate:default_constructor") ? 1 : 0;
|
||||||
int protected_ctor = 0;
|
int protected_ctor = 0;
|
||||||
int constructor = 0;
|
int constructor = 0;
|
||||||
|
|
||||||
/* emit constructors */
|
/* emit constructors */
|
||||||
for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
|
for (ni = Getattr(n, "firstChild"); ni; ni = nextSibling(ni)) {
|
||||||
nodeType = Getattr(ni, "nodeType");
|
nodeType = Getattr(ni, "nodeType");
|
||||||
|
|
@ -2731,6 +2733,9 @@ String * Language::getClassType() const {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int Language::abstractClassTest(Node *n) {
|
int Language::abstractClassTest(Node *n) {
|
||||||
|
/* check for non public operator new */
|
||||||
|
if (Getattr(n,"allocate:nonew")) return 1;
|
||||||
|
/* now check for the rest */
|
||||||
List *abstract = Getattr(n,"abstract");
|
List *abstract = Getattr(n,"abstract");
|
||||||
if (!abstract) return 0;
|
if (!abstract) return 0;
|
||||||
if (abstract && !directorsEnabled()) return 1;
|
if (abstract && !directorsEnabled()) return 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue