assert(condition[, message]) patch

Joseph Lisee jlisee at umd.edu
Tue Aug 1 13:21:36 PDT 2006


In article <eao805$2svv$1 at digitaldaemon.com>,
 Kirk McDonald <kirklin.mcdonald at gmail.com> wrote:


> Are you aware of my Pyd library? It's a wrapper around the Python API, 
> analogous to Boost::Python, but for D. It's probably not quite ready for 
> serious use (for one thing, I haven't really documented it yet; for 
> another, I haven't added Linux support yet, though it's going in Real 
> Soon Now (tm)), but it might be worth taking a look at.
> 
> So yeah, this is yet another unfinished, undocumented open-source 
> project, but it is still capable of the following and more:
> 
> [testdll.d]
> import pyd.pyd;
> import std.stdio;
> 
> class Foo {
>      int m_i;
>      this() { m_i = 0; }
>      this(int i) { m_i = i; }
> 
>      void foo() { writefln("i = ", m_i); }
>      int i() { return m_i; }
>      void i(int j) { m_i = j; }
> }
> 
> void bar(int i) {
>      writefln("You entered: ", i);
> }
> 
> extern(C)
> export void inittestdll() {
>      // Function wrapping
>      def!(bar, "bar");
> 
>      module_init("testdll");
> 
>      // Class wrapping
>      wrapped_class!(Foo, "Foo") f;
>      // Constructor wrapping
>      f.init!(tuple!(int));
>      // Member function wrapping
>      f.def!(Foo.foo, "foo");
>      // Property wrapping
>      f.prop!(Foo.i, "i");
>      finalize_class(f);
> }
> // EOF
> 
> And in Python:
> 
>  >>> import testdll
>  >>> testdll.bar(20)
> You entered: 20
>  >>> f = testdll.Foo(30)
>  >>> f.i
> 30
>  >>> f.i = 50
>  >>> f.foo()
> i = 50
> 
> It also comes with an extension to Python's distutils (David Rushby's 
> CeleriD), to make building these extensions so much easier.
> 
> Even if you don't use Pyd, the project has what I believe is the most 
> complete version of the Python API header, which would probably be 
> useful to you:
> http://dsource.org/projects/pyd/browser/trunk/infrastructure/python/headers/py
> thon.d

I have seen your library and I think it will be a great addition to D, 
what parts of linux support are missing?

I don't think PyD will apply to my project.  Let me get incredibly off 
topic and explain a little more. I am trying to make a program that 
generates wrappers for C++ programs so you can use them in D.  My 
current plan is to process the XML output from Doxygen with Python and 
the ElementTree library.  I will then generate a C++ file with a C 
interface to the class and D wrapper file for each class.  Something 
similar to below:

// C++ Code
class MyClass {
   int m_num;
public:
    MyClass(int num) {
        m_num = num;
    }

    int getNum() {
        return m_num;
    }
};

// C Wrapper Code
extern "C"
{
    void* MyClass_new(int num) {
        return (void*)(new myClass(num));
    }

    int MyClass_getNum(void* obj) {
        return ((myClass*)obj)->getNum();
    }

    void MyClass_delete(void* obj) {
        delete (myClass*)obj;
    }
}

// D wrapper class
extern (C)
{
    void* MyClass_new(int num);
    int MyClass_getNum(void* obj);
    void MyClass_delete(void* obj);
}

class MyClass {
    private void* cppObj;

    this(int num) {
        cppObj = MyClass_new(num);
    }

    ~this() {
        MyClass_delete(cppObj);
    }

    int getNum() {
        return MyClass_getNum(cppObj);
    }
}

That is a very basic example and doesn't handle exception being thrown 
from the C++ code.  I haven't start work on the generator yet.  I am 
currently testing my ideas on the following issues:

  -properly handling the passing of D wrapped C++ classes to and from 
the C++ code.
  -using directors at the bottom of the inheritance tree to properly 
pass virtual function calls of to inherited D class
  -Throwing C++ and D exceptions through the interface that has C 
linkage.
  -Mapping of types from C++ to C to D.

If this ever gets off the ground I am thinking of calling it WrapeD, the 
lack of two p's is intentional.  I hope to have simpler interface file 
system than swig.  Something looks more like SCons build files.

-Joseph



More information about the Digitalmars-d mailing list