From phil at geog.ubc.ca Mon Apr 24 22:35:05 2000 From: phil at geog.ubc.ca (Phil Austin) Date: Mon, 24 Apr 2000 13:35:05 -0700 (PDT) Subject: [C++-SIG] help with CXX-4.2 and add_keyword_method Message-ID: <14596.45049.483478.431140@brant.geog.ubc.ca> I'm trying to use add_keyword_method in the appended code and am getting the following errors from KCC-3.4f under Solaris 5.6. Am I guessing wrong as to the correct synax? Thanks Phil "/home/phil/include/CXX-4.2/CXX_Extensions.h", line 164: error: no instance of constructor "Py::MethodDefExt::MethodDefExt [with T=testkey_module]" matches the argument list argument types are: (const char *, Py::ExtensionModule::method_keyword_funct ion_t, PyObject *(PyObject *, PyObject *, PyObject *), const char *) name, ^ detected during instantiation of "void Py::ExtensionModule::add_keyword_method(const char *, Py::ExtensionModule::method_keyword_function_t, const char *) [with T=testkey_module]" at line 20 of "testkey.cc" #include "Python.h" #include "CXX_Objects.h" #include "CXX_Extensions.h" #include USING(namespace Py) USING(namespace std) extern "C" void inittestkey(); class testkey_module : public ExtensionModule { public: testkey_module() : ExtensionModule( "testkey" ) { add_varargs_method("sum", &testkey_module::ex_sum, "testing"); add_keyword_method("sum2", &testkey_module::ex_sum2, "testing2"); initialize( "documentation for the testkey module" ); Dict d( moduleDictionary() ); d["a_constant"] = Int(12); } virtual ~testkey_module() {} private: Object ex_sum (const Tuple &a) { cout << a[0] << endl; return a[0]; } Object ex_sum2 (const Tuple &a, const Dict &b) { cout << a[1] << endl; return a[1]; } }; void inittestkey() { static testkey_module *testkey = new testkey_module; } From barry at scottb.demon.co.uk Fri Apr 28 21:43:48 2000 From: barry at scottb.demon.co.uk (Barry Scott) Date: Fri, 28 Apr 2000 20:43:48 +0100 Subject: [C++-SIG] help with CXX-4.2 and add_keyword_method In-Reply-To: <14596.45049.483478.431140@brant.geog.ubc.ca> Message-ID: <000001bfb14a$12a7db30$060210ac@private> There is a bug in the keyword template. I got the types of the call back handlers wrong and the C++ compiler is rightly very upset. I have fixed the problem and added a test to the demo software. This works well under Windows with Visual C++ 6.0. I have seen this compile clean under G++ 2.95.2 on FreeBSD. But it does not run because of undefined symbol "cout" (which should not be used as we use std::cout everywhere). Attached are two files: Demo\example.cxx adds a test function "kw" to the Demo. Include\CXX_Extensions.h contains the fix to correctly support keyword functions. Example output: Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import example >>> example.kw >>> example.kw.__doc__ 'kw()' >>> example.kw('fred',12,name='barry',size='big',test=1) Called with 2 normal arguments. and with 3 keyword arguments: size name test 0 >>> BArry -------------- next part -------------- A non-text attachment was scrubbed... Name: example.cxx Type: application/octet-stream Size: 8935 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: CXX_Extensions.h Type: application/octet-stream Size: 19216 bytes Desc: not available URL: