From: Thomas H. <tho...@io...> - 2001-09-27 11:14:03
|
No comments? ----- Original Message ----- From: "Thomas Heller" <tho...@io...> To: "Ken Simpson" <ksi...@tt...>; <pyi...@li...> Sent: Friday, September 07, 2001 8:57 AM Subject: Re: [Pyinline-discuss] PyInline direction > > > 1. It wold be cool if the generated C-code would contain > > > #line directives pointing into the correct location > > > into the python source file, but I doubt that it is > > > possible to do it automatically. > > > > Great idea. It will take some work to implement, though, so let's write it > > down for implementation during the next month or so. > > The idea I have so far is to insert the C code in a function in this > way: > > C(""" > int foo(void) > { > return do_something(); > } > """) > > and the C function could be something like > > def C(code): > import sys > lineno = sys._getframe(1).f_lineno > return "#line %d\n" % lineno + code > > This way is not bullet-proof: > > print C("spam") > > works correctly, > > print C( > "spam") > > does not. > > > > > 2. Currently you automatically wrap C-functions > > > by parsing their header. This is (nearly) trivial > > > for simple argument and return types, but impossible > > > for structured types. How will this be handled? > > > > I'm planning to implement a Python equivalent of Neil Watkiss' > > Inline::Struct module for Perl. Inline::Struct lets you define C structs > > which are automagically turned into Perl dictionaries when they pass into > > Perl land (and vice versa). > Another great way would be to use Jack Jansen's bgen. > This is a module for generating the complete source code for > Python extension modules. Seems to be used quite extensively > for MacPython, although it is not Mac specific. > > You write manual functions in the following way: > > bgen.ManualGenerator("function_name", """ > if (!PyArg_ParseTuple(.....) > return NULL; > .... > return _res; > """) > > The function header is created automatically. > Or, better yet, create a Python interface function wrapping a C function like > int fib(int i) > in this way: > > c_int = bgen.Type("int", "i") > bgen.FunctionGenerator(c_int, "fib", (c_int, "n", InMode)) > > which will automatically create the following source: > > PyObject *spam_fib(PyObject *self, PyObject *args) > { > int n; > if (!PyArg_ParseTuple(args, "i", &n)) > return NULL; > return Py_BuildValue("i", fib(n)); > } > > Best is, bgen allows to easily create new Python types > in the extension module! > Looks much easier than SWIG! > The only problem so far is that there are no docs... > > ---- > > All in all, I have a lot of ideas, but different from you > I know nothing about Perls inline module. > > Big question is: Should we cooperate (open source development), > or do we split our efforts? > > Thomas > > > _______________________________________________ > Pyinline-discuss mailing list > Pyi...@li... > https://lists.sourceforge.net/lists/listinfo/pyinline-discuss |