assert(condition[, message]) patch

Kirk McDonald kirklin.mcdonald at gmail.com
Tue Aug 1 11:54:00 PDT 2006


Joseph Lisee wrote:
> In article <ealh03$htp$1 at digitaldaemon.com>, Sean Kelly <sean at f4.ca> 
> wrote:
> 
> 
>>Joseph Lisee wrote:
>>
>>>In article <e5l5v8$1g7j$1 at digitaldaemon.com>,
>>> Tom S <h3r3tic at remove.mat.uni.torun.pl> wrote:
>>>
>>>
>>>>Lars Ivar Igesund wrote:
>>>>
>>>>>Because not all the users will have access to the source, or be inclined 
>>>>>to
>>>>>see it. Unless the user get's a readable/understandable assert message
>>>>>he/she might not get enough information to actually reproduce a test case
>>>>>for the developer to peruse.
>>>>>
>>>>>Walter, this is a no-brainer, please put it in.
>>>>
>>>>++votes;
>>>>
>>>>/+
>>>>when you release your app to some testing team, you might want to leave 
>>>>asserts in. While an error message containing the line number and 
>>>>filename could be helpful, an additional message could be priceless. 
>>>>E.g. assert(fileNameContainsNoSpaces(foo)); won't tell you that the 
>>>>'foo' really was something like '^&^34 5+23 3(43D678[SAFer6_[]' which 
>>>>might mean some mem corruption or forgetting a .dup somewhere in your 
>>>>code. You'd instead go searching for some logic problems that wouldn't 
>>>>solve the problem.
>>>>+/
>>>
>>>I vote for the assert(condition, "msg"), construct as well.
>>
>>This feature was added a number of builds ago.
>>
>>
>>Sean
> 
> 
> That is what happens when I don't read the documentation close enough 
> and not pay attention to message dates.
> 
> It should also be noted that the in the Contract Programming page of the 
> documentation it only mentions "assert(expression)".  While It does link 
> to the full documentation on the assert expression should that page also 
> mention the option for a message?
> 
> Sorry to clutter the mailing list.  I will just go back to my attempt at 
> wrapping C++ with doxygen + python. Yes I am aware of the D module for 
> Swig, but I am going for something more elegant and this effort is a 
> good C++, Python, and D programming exercise.

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/python.d

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://dsource.org/projects/pyd/wiki



More information about the Digitalmars-d mailing list