diff --git a/Doc/Manual/C.html b/Doc/Manual/C.html
index 6ad664664..42e283714 100644
--- a/Doc/Manual/C.html
+++ b/Doc/Manual/C.html
@@ -367,8 +367,8 @@ The generated functions make calls to class' constructors and destructors, respe
-Circle * new_Circle(double r);
-void delete_Circle(Circle * self);
+Circle * Circle_new(double r);
+void Circle_delete(Circle * self);
@@ -397,9 +397,9 @@ Our application code could look like this:
- Circle *c = new_Circle(1.5);
+ Circle *c = Circle_new(1.5);
printf("radius: %f\narea: %f\n", Circle_radius_get(c), Circle_area(c));
- delete_Circle(c);
+ Circle_delete(c);
@@ -482,18 +482,18 @@ What we would like to generate as a C interface of this function would be someth
// wrapper header file
typedef struct SwigObj_SomeClass SomeClass;
-SomeClass * new_SomeClass();
+SomeClass * SomeClass_new();
-void delete_SomeClass(SomeClass * carg1);
+void SomeClass_delete(SomeClass * carg1);
SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
-SomeIntTemplateClass * new_SomeIntTemplateClass();
+SomeIntTemplateClass * SomeIntTemplateClass_new();
-void delete_SomeIntTemplateClass(SomeIntTemplateClass * carg1);
+void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
The Wrapper
@@ -616,18 +616,18 @@ above.
// wrapper header file
typedef struct SwigObj_SomeClass SomeClass;
-SomeClass * new_SomeClass();
+SomeClass * SomeClass_new();
-void delete_SomeClass(SomeClass * carg1);
+void SomeClass_delete(SomeClass * carg1);
SomeClass* someFunction(SomeIntTemplateClass* carg1, int carg2);
typedef struct SwigObj_SomeIntTemplateClass SomeIntTemplateClass;
-SomeIntTemplateClass * new_SomeIntTemplateClass();
+SomeIntTemplateClass * SomeIntTemplateClass_new();
-void delete_SomeIntTemplateClass(SomeIntTemplateClass * carg1);
+void SomeIntTemplateClass_delete(SomeIntTemplateClass * carg1);
36.5 Exception handling
diff --git a/Examples/c/class/runme.c b/Examples/c/class/runme.c
index 4c1f33ca0..4aa613968 100644
--- a/Examples/c/class/runme.c
+++ b/Examples/c/class/runme.c
@@ -4,9 +4,9 @@
int main(int argc, char **argv) {
printf("Creating some objects:\n");
- Circle* c = new_Circle(10);
+ Circle* c = Circle_new(10);
printf(" Created circle\n");
- Square* s = new_Square(10);
+ Square* s = Square_new(10);
printf(" Created square\n");
printf("\nA total of %d shapes were created\n", Shape_nshapes_get());
@@ -33,8 +33,8 @@ int main(int argc, char **argv) {
printf("\nGuess I'll clean up now\n");
- delete_Square(s);
- delete_Circle(c);
+ Square_delete(s);
+ Circle_delete(c);
printf("%d shapes remain\n", Shape_nshapes_get());
printf("Goodbye\n");
diff --git a/Examples/c/exception/runme.c b/Examples/c/exception/runme.c
index 6480f3d50..4094a9859 100644
--- a/Examples/c/exception/runme.c
+++ b/Examples/c/exception/runme.c
@@ -7,7 +7,7 @@
#include "example_wrap.h"
int main() {
- Test *t = new_Test();
+ Test *t = Test_new();
SWIG_try {
Test_unknown(t);
diff --git a/Examples/c/std_vector/runme.c b/Examples/c/std_vector/runme.c
index ef12180f9..b29ffa14a 100644
--- a/Examples/c/std_vector/runme.c
+++ b/Examples/c/std_vector/runme.c
@@ -3,7 +3,7 @@
#include "example_wrap.h"
int main() {
- Klass *klass = new_Klass();
+ Klass *klass = Klass_new();
Vint *vint = Klass_vi_get(klass);
VA *va = Klass_va_get(klass);
@@ -26,7 +26,7 @@ int main() {
printf("\nVector of objects:\n");
for (i = 0; i < 10; i++) {
- A *a = new_A_std_string_i("hello", i);
+ A *a = A_new_std_string_i("hello", i);
VA_push_back(va, a);
}
@@ -35,7 +35,7 @@ int main() {
printf("%s %d\n", A_name_get(a), A_value_get(a));
}
- delete_Klass(klass);
+ Klass_delete(klass);
SWIG_exit(0);
}
diff --git a/Examples/test-suite/c/abstract_access_runme.c b/Examples/test-suite/c/abstract_access_runme.c
index e27c9b363..5e282394c 100644
--- a/Examples/test-suite/c/abstract_access_runme.c
+++ b/Examples/test-suite/c/abstract_access_runme.c
@@ -2,11 +2,11 @@
#include
int main(int argc, const char *argv[]) {
- D *d = new_D();
+ D *d = D_new();
assert(D_do_x(d) == 1);
- delete_D(d);
+ D_delete(d);
return 0;
-}
\ No newline at end of file
+}
diff --git a/Examples/test-suite/c/abstract_change_runme.c b/Examples/test-suite/c/abstract_change_runme.c
index 125fad7e9..3696bc493 100644
--- a/Examples/test-suite/c/abstract_change_runme.c
+++ b/Examples/test-suite/c/abstract_change_runme.c
@@ -2,9 +2,9 @@
#include
int main(int argc, const char *argv[]) {
- Base *ba = new_Base();
- Derived *d = new_Derived();
- Bottom *bo = new_Bottom();
+ Base *ba = Base_new();
+ Derived *d = Derived_new();
+ Bottom *bo = Bottom_new();
assert(Base_PublicProtectedPublic1(ba) == 0);
assert(Base_PublicProtectedPublic2(ba) == 0);
@@ -26,9 +26,9 @@ int main(int argc, const char *argv[]) {
assert(Bottom_WasProtected3(ba) == 0);
assert(Bottom_WasProtected4(ba) == 0);
- delete_Base(ba);
- delete_Derived(d);
- delete_Bottom(bo);
+ Base_delete(ba);
+ Derived_delete(d);
+ Bottom_delete(bo);
return 0;
-}
\ No newline at end of file
+}
diff --git a/Examples/test-suite/c/abstract_typedef_runme.c b/Examples/test-suite/c/abstract_typedef_runme.c
index 0019b1cc9..62c4c65d5 100644
--- a/Examples/test-suite/c/abstract_typedef_runme.c
+++ b/Examples/test-suite/c/abstract_typedef_runme.c
@@ -3,13 +3,13 @@
#include
int main(int argc, const char *argv[]) {
- Engine *e = new_Engine();
- A *a = new_A();
+ Engine *e = Engine_new();
+ A *a = A_new();
assert(AbstractBaseClass_write(a, e) == true);
- delete_A(a);
- delete_Engine(e);
+ A_delete(a);
+ Engine_delete(e);
return 0;
}
diff --git a/Examples/test-suite/c/abstract_virtual_runme.c b/Examples/test-suite/c/abstract_virtual_runme.c
index 77dca7f88..91f1b9652 100644
--- a/Examples/test-suite/c/abstract_virtual_runme.c
+++ b/Examples/test-suite/c/abstract_virtual_runme.c
@@ -2,17 +2,17 @@
#include
int main(int argc, const char *argv[]) {
- B *b = new_B();
- D *d = new_D();
- E *e = new_E();
+ B *b = B_new();
+ D *d = D_new();
+ E *e = E_new();
assert(B_foo(b) == 0);
assert(D_foo(d) == 0);
assert(E_foo(e) == 0);
- delete_B(b);
- delete_D(d);
- delete_E(e);
+ B_delete(b);
+ D_delete(d);
+ E_delete(e);
return 0;
}
diff --git a/Examples/test-suite/c/add_link_runme.c b/Examples/test-suite/c/add_link_runme.c
index c9080dbf9..809e55e75 100644
--- a/Examples/test-suite/c/add_link_runme.c
+++ b/Examples/test-suite/c/add_link_runme.c
@@ -2,13 +2,13 @@
#include
int main(int argc, const char *argv[]) {
- Foo *f = new_Foo();
+ Foo *f = Foo_new();
Foo *f2 = Foo_blah(f);
assert(f2 != 0);
- delete_Foo(f);
- delete_Foo(f2);
+ Foo_delete(f);
+ Foo_delete(f2);
return 0;
}
diff --git a/Examples/test-suite/c/anonymous_bitfield_runme.c b/Examples/test-suite/c/anonymous_bitfield_runme.c
index 3370341ec..a3d93149f 100644
--- a/Examples/test-suite/c/anonymous_bitfield_runme.c
+++ b/Examples/test-suite/c/anonymous_bitfield_runme.c
@@ -2,7 +2,7 @@
#include
int main(int argc, const char *argv[]) {
- Foo *f = new_Foo();
+ Foo *f = Foo_new();
assert(f != 0);
@@ -23,7 +23,7 @@ int main(int argc, const char *argv[]) {
Foo_seq_set(f, 1);
assert(Foo_seq_get(f) == 1);
- delete_Foo(f);
+ Foo_delete(f);
return 0;
}
diff --git a/Examples/test-suite/c/cast_operator_runme.c b/Examples/test-suite/c/cast_operator_runme.c
index 66ccf984a..1b90bbcb4 100644
--- a/Examples/test-suite/c/cast_operator_runme.c
+++ b/Examples/test-suite/c/cast_operator_runme.c
@@ -3,10 +3,10 @@
#include "cast_operator/cast_operator_wrap.h"
int main() {
- A *a = new_A();
+ A *a = A_new();
if (strcmp(A_tochar(a), "hi"))
fprintf(stderr, "cast failed\n");
- delete_A(a);
+ A_delete(a);
SWIG_exit(0);
}
diff --git a/Examples/test-suite/c/cpp_basic_class_method_runme.c b/Examples/test-suite/c/cpp_basic_class_method_runme.c
index 93fb4e190..9061c40fb 100644
--- a/Examples/test-suite/c/cpp_basic_class_method_runme.c
+++ b/Examples/test-suite/c/cpp_basic_class_method_runme.c
@@ -3,11 +3,11 @@
int main(int argc, const char *argv[])
{
- MyClass *mc = new_MyClass();
+ MyClass *mc = MyClass_new();
assert(MyClass_someMethod(mc) == 42);
- delete_MyClass(mc);
+ MyClass_delete(mc);
return 0;
}
diff --git a/Examples/test-suite/c/cpp_basic_class_runme.c b/Examples/test-suite/c/cpp_basic_class_runme.c
index 0b835ee21..13b4bc641 100644
--- a/Examples/test-suite/c/cpp_basic_class_runme.c
+++ b/Examples/test-suite/c/cpp_basic_class_runme.c
@@ -3,9 +3,9 @@
int main(int argc, const char *argv[])
{
MyClass *mc;
- mc = new_MyClass();
+ mc = MyClass_new();
- delete_MyClass(mc);
+ MyClass_delete(mc);
return 0;
}
diff --git a/Examples/test-suite/c/cpp_basic_class_var_pub_member_built_in_runme.c b/Examples/test-suite/c/cpp_basic_class_var_pub_member_built_in_runme.c
index d3dbf9fdf..6d2898933 100644
--- a/Examples/test-suite/c/cpp_basic_class_var_pub_member_built_in_runme.c
+++ b/Examples/test-suite/c/cpp_basic_class_var_pub_member_built_in_runme.c
@@ -3,13 +3,13 @@
int main(int argc, const char *argv[])
{
- MyClass *mc = new_MyClass();
+ MyClass *mc = MyClass_new();
assert(MyClass_myPubInt_get(mc) == 42);
MyClass_myPubInt_set(mc, 4711);
assert(MyClass_myPubInt_get(mc) == 4711);
- delete_MyClass(mc);
+ MyClass_delete(mc);
return 0;
}
diff --git a/Examples/test-suite/c/cpp_basic_class_var_pub_member_class_runme.c b/Examples/test-suite/c/cpp_basic_class_var_pub_member_class_runme.c
index cc4127d9e..de700e46b 100644
--- a/Examples/test-suite/c/cpp_basic_class_var_pub_member_class_runme.c
+++ b/Examples/test-suite/c/cpp_basic_class_var_pub_member_class_runme.c
@@ -6,15 +6,15 @@ int main(int argc, const char *argv[])
MyClass *mc;
MySecondClass *mc2;
- mc2 = new_MySecondClass();
- mc = new_MyClass();
+ mc2 = MySecondClass_new();
+ mc = MyClass_new();
assert(MySecondClass_myPubClassInstance_get(mc2));
MySecondClass_myPubClassInstance_set(mc2, mc);
assert(MySecondClass_myPubClassInstance_get(mc2));
- delete_MyClass(mc);
- delete_MySecondClass(mc2);
+ MyClass_delete(mc);
+ MySecondClass_delete(mc2);
return 0;
}
diff --git a/Examples/test-suite/c/cpp_basic_class_virtual_method_runme.c b/Examples/test-suite/c/cpp_basic_class_virtual_method_runme.c
index a5cabe8a7..034104a6f 100644
--- a/Examples/test-suite/c/cpp_basic_class_virtual_method_runme.c
+++ b/Examples/test-suite/c/cpp_basic_class_virtual_method_runme.c
@@ -3,10 +3,10 @@
int main()
{
- BaseClass *bc = new_BaseClass();
- NonMethodOverwritingClass *noc = new_NonMethodOverwritingClass();
- MethodOverwritingClass *oc = new_MethodOverwritingClass();
- BaseClass *inherited_bc = (BaseClass*)new_MethodOverwritingClass();
+ BaseClass *bc = BaseClass_new();
+ NonMethodOverwritingClass *noc = NonMethodOverwritingClass_new();
+ MethodOverwritingClass *oc = MethodOverwritingClass_new();
+ BaseClass *inherited_bc = (BaseClass*)MethodOverwritingClass_new();
assert(BaseClass_myInt(bc) == 0xba53);
assert(NonMethodOverwritingClass_myInt(noc) == 0xba53);
@@ -15,10 +15,10 @@ int main()
assert(BaseClass_myInt((BaseClass*)oc) == 0xa173123d);
assert(BaseClass_myInt(inherited_bc) == 0xa173123d);
- delete_BaseClass(bc);
- delete_NonMethodOverwritingClass(noc);
- delete_MethodOverwritingClass(oc);
- delete_BaseClass(inherited_bc);
+ BaseClass_delete(bc);
+ NonMethodOverwritingClass_delete(noc);
+ MethodOverwritingClass_delete(oc);
+ BaseClass_delete(inherited_bc);
return 0;
}
diff --git a/Examples/test-suite/c/cpp_basic_namespaced_class_runme.c b/Examples/test-suite/c/cpp_basic_namespaced_class_runme.c
index 95a1ce5c3..27527ceeb 100644
--- a/Examples/test-suite/c/cpp_basic_namespaced_class_runme.c
+++ b/Examples/test-suite/c/cpp_basic_namespaced_class_runme.c
@@ -3,9 +3,9 @@
int main(int argc, const char *argv[])
{
myNamespace_MyClass *mc;
- mc = new_myNamespace_MyClass();
+ mc = myNamespace_MyClass_new();
- delete_myNamespace_MyClass(mc);
+ myNamespace_MyClass_delete(mc);
return 0;
}
diff --git a/Examples/test-suite/c/cpp_basic_runme.c b/Examples/test-suite/c/cpp_basic_runme.c
index 4de994340..e8397480c 100644
--- a/Examples/test-suite/c/cpp_basic_runme.c
+++ b/Examples/test-suite/c/cpp_basic_runme.c
@@ -3,7 +3,7 @@
#include
int main(int argc, const char *argv[]) {
- Foo *f = new_Foo(5);
+ Foo *f = Foo_new(5);
// test global static variables
// TODO: Implement or document as not available
@@ -36,7 +36,7 @@ int main(int argc, const char *argv[]) {
// because of unclear implementation details
//assert(c_init_ref != 0);
- Bar *b = new_Bar();
+ Bar *b = Bar_new();
// check default value set by constructor
assert(Bar_cint_get(b) == 3);
@@ -55,9 +55,9 @@ int main(int argc, const char *argv[]) {
Foo_num_set(Bar_fref_get(b), 1);
assert(Foo_num_get(Bar_fref_get(b)) == 1);
// create new Bar instance and check static member value
- Bar *b2 = new_Bar();
+ Bar *b2 = Bar_new();
assert(Foo_num_get(Bar_fref_get(b2)) == 1);
- delete_Bar(b2);
+ Bar_delete(b2);
b2 = 0;
// Try to set a pointer
@@ -68,7 +68,7 @@ int main(int argc, const char *argv[]) {
Foo *f2 = Bar_testFoo(b, 2, f);
assert(Foo_num_get(f2) == 11);
- delete_Foo(f2);
+ Foo_delete(f2);
f2 = 0;
// test static variables
@@ -93,16 +93,16 @@ int main(int argc, const char *argv[]) {
assert(test_func_ptr(f, 2) == -14);
#endif
- delete_Bar(b);
- delete_Foo(f);
+ Bar_delete(b);
+ Foo_delete(f);
- Fl_Window *w = new_Fl_Window();
+ Fl_Window *w = Fl_Window_new();
// Test whether macro worked for code extension
// and test optional function parameters
Fl_Window_show(w);
Fl_Window_show_pv(w, 0);
Fl_Window_show_pv_pv(w, 0, 0);
- delete_Fl_Window(w);
+ Fl_Window_delete(w);
w = 0;
return 0;
diff --git a/Examples/test-suite/c/cpp_basic_template_class_runme.c b/Examples/test-suite/c/cpp_basic_template_class_runme.c
index f2aac8cd5..b4da41e64 100644
--- a/Examples/test-suite/c/cpp_basic_template_class_runme.c
+++ b/Examples/test-suite/c/cpp_basic_template_class_runme.c
@@ -2,12 +2,12 @@
#include "cpp_basic_template_class/cpp_basic_template_class_wrap.h"
int main() {
- MyTemplateClass_Int *ci = new_MyTemplateClass_Int();
+ MyTemplateClass_Int *ci = MyTemplateClass_Int_new();
MyTemplateClass_Int_someMemberVariable_set(ci, 42);
assert(MyTemplateClass_Int_someMemberVariable_get(ci) == 42);
- delete_MyTemplateClass_Int(ci);
+ MyTemplateClass_Int_delete(ci);
return 0;
}
diff --git a/Examples/test-suite/c/cpp_enum_runme.c b/Examples/test-suite/c/cpp_enum_runme.c
index e72a2fdee..82148bc7b 100644
--- a/Examples/test-suite/c/cpp_enum_runme.c
+++ b/Examples/test-suite/c/cpp_enum_runme.c
@@ -8,7 +8,7 @@ int main(int argc, const char *argv[]) {
int e = ENUM_ONE, *p;
// check the constructor's default value
- StructWithEnums *s = new_StructWithEnums();
+ StructWithEnums *s = StructWithEnums_new();
assert(StructWithEnums_some_enum_get(s) == ENUM_ONE);
// check setter
@@ -43,9 +43,9 @@ int main(int argc, const char *argv[]) {
p = StructWithEnums_enum_test8(s);
assert(*p == ENUM_TWO);
- delete_StructWithEnums(s);
+ StructWithEnums_delete(s);
- Foo *f = new_Foo();
+ Foo *f = Foo_new();
// check the constructor's default value
assert(Foo_hola_get(f) == Foo_Hello);
@@ -53,7 +53,7 @@ int main(int argc, const char *argv[]) {
Foo_hola_set(f, Foo_Hi);
assert(Foo_hola_get(f) == Foo_Hi);
- delete_Foo(f);
+ Foo_delete(f);
//check C enum
hi = Hi;
diff --git a/Examples/test-suite/c/exception_order_runme.c b/Examples/test-suite/c/exception_order_runme.c
index 1d9e58e49..9233c2716 100644
--- a/Examples/test-suite/c/exception_order_runme.c
+++ b/Examples/test-suite/c/exception_order_runme.c
@@ -3,7 +3,7 @@
#include "exception_order/exception_order_wrap.h"
int main() {
- A* a = new_A();
+ A* a = A_new();
SWIG_try {
A_foo(a);
diff --git a/Examples/test-suite/c/operator_overload_runme.c b/Examples/test-suite/c/operator_overload_runme.c
index 7bb483f90..00e525a9c 100644
--- a/Examples/test-suite/c/operator_overload_runme.c
+++ b/Examples/test-suite/c/operator_overload_runme.c
@@ -7,7 +7,7 @@
int main() {
Op_sanity_check();
- Op *op1 = new_Op_i(1), *op2 = new_Op_i(2), *op3 = copy_Op(op1);
+ Op *op1 = Op_new_i(1), *op2 = Op_new_i(2), *op3 = Op_copy(op1);
assert(Op_NotEqual(op1, op2), "neq failed");
Op_PlusPlusPrefix(op3);
@@ -18,8 +18,8 @@ int main() {
assert(3 == *Op_IndexInto(op3, Op_IndexIntoConst(op2, Op_Functor(op1))), "[] or () failed");
assert(5 == Op_Functor_i(op3, 2), "f(x) failed");
- delete_Op(op1);
- delete_Op(op2);
- delete_Op(op3);
+ Op_delete(op1);
+ Op_delete(op2);
+ Op_delete(op3);
SWIG_exit(0);
}
diff --git a/Source/Modules/c.cxx b/Source/Modules/c.cxx
index 0a1d549db..0027ac724 100644
--- a/Source/Modules/c.cxx
+++ b/Source/Modules/c.cxx
@@ -379,6 +379,14 @@ public:
SWIG_typemap_lang("c");
SWIG_config_file("c.swg");
+ // The default naming convention is to use new_Foo(), copy_Foo() and delete_Foo() for the default/copy ctor and dtor of the class Foo, but we prefer to
+ // start all Foo methods with the same prefix, so change this. Notice that new/delete are chosen to ensure that we avoid conflicts with the existing class
+ // methods, more natural create/destroy, for example, could result in errors if the class already had a method with the same name, but this is impossible
+ // for the chosen names as they're keywords in C++ ("copy" is still a problem but we'll just have to live with it).
+ Swig_name_register("construct", "%n%c_new");
+ Swig_name_register("copy", "%n%c_copy");
+ Swig_name_register("destroy", "%n%c_delete");
+
allow_overloading();
}