~ubuntu-branches/ubuntu/natty/pysvn/natty

« back to all changes in this revision

Viewing changes to Import/pycxx-5.5.0/Demo/example.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-23 20:08:08 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223200808-t946skprxzf6vjqx
Tags: 1.6.3-0ubuntu1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//-----------------------------------------------------------------------------
 
2
//
 
3
// Copyright (c) 1998 - 2007, The Regents of the University of California
 
4
// Produced at the Lawrence Livermore National Laboratory
 
5
// All rights reserved.
 
6
//
 
7
// This file is part of PyCXX. For details, see http://cxx.sourceforge.net. The
 
8
// full copyright notice is contained in the file COPYRIGHT located at the root
 
9
// of the PyCXX distribution.
 
10
//
 
11
// Redistribution  and  use  in  source  and  binary  forms,  with  or  without
 
12
// modification, are permitted provided that the following conditions are met:
 
13
//
 
14
//  - Redistributions of  source code must  retain the above  copyright notice,
 
15
//    this list of conditions and the disclaimer below.
 
16
//  - Redistributions in binary form must reproduce the above copyright notice,
 
17
//    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
 
18
//    documentation and/or materials provided with the distribution.
 
19
//  - Neither the name of the UC/LLNL nor  the names of its contributors may be
 
20
//    used to  endorse or  promote products derived from  this software without
 
21
//    specific prior written permission.
 
22
//
 
23
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
 
24
// AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
 
25
// IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
 
26
// ARE  DISCLAIMED.  IN  NO  EVENT  SHALL  THE  REGENTS  OF  THE  UNIVERSITY OF
 
27
// CALIFORNIA, THE U.S.  DEPARTMENT  OF  ENERGY OR CONTRIBUTORS BE  LIABLE  FOR
 
28
// ANY  DIRECT,  INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL
 
29
// DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
 
30
// SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
 
31
// CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
 
32
// LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
 
33
// OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 
34
// DAMAGE.
 
35
//
 
36
//-----------------------------------------------------------------------------
 
37
 
 
38
#ifdef _MSC_VER
 
39
// disable warning C4786: symbol greater than 255 character,
 
40
// nessesary to ignore as <map> causes lots of warning
 
41
#pragma warning(disable: 4786)
 
42
#endif
 
43
 
 
44
#include "CXX/Objects.hxx"
 
45
#include "CXX/Extensions.hxx"
 
46
 
 
47
#include <assert.h>
 
48
 
 
49
#include "range.hxx"  // Extension object
 
50
extern std::string test_extension_object();
 
51
 
 
52
#include <algorithm>
 
53
 
 
54
static std::string test_String()
 
55
{
 
56
    Py::String s("hello");
 
57
    Py::Char blank = ' ';
 
58
    Py::String r1("world in brief", 5);
 
59
    s = s + blank + r1;
 
60
    s = s * 2;
 
61
    if(std::string(s) != "hello worldhello world")
 
62
    {
 
63
        return "failed (1) '" + std::string(s) + "'";
 
64
    }
 
65
    // test conversion
 
66
    std::string w = static_cast<std::string>(s);
 
67
    std::string w2 = (std::string) s;
 
68
    if(w != w2)
 
69
    {
 
70
        return "failed (2)";
 
71
    }
 
72
    Py::String r2("12345 789");
 
73
    Py::Char c6 = r2[5];
 
74
    if(c6 != blank)
 
75
    {
 
76
        std::cout << "|" << c6 << "|" << std::endl;
 
77
        return "failed (3)";
 
78
    }
 
79
 
 
80
    Py::Char c7 = r2.front();
 
81
    Py::Char c8 = r2.back();
 
82
 
 
83
    return "ok";
 
84
}
 
85
 
 
86
static std::string
 
87
test_boolean()
 
88
{
 
89
    bool passed = true;
 
90
 
 
91
    Py::Object o;
 
92
    Py::Boolean pb1;
 
93
    Py::Boolean pb2;
 
94
    bool b1;
 
95
 
 
96
    o = Py::True();
 
97
    if( o.isTrue() )
 
98
        { std::cout << "OK: T1: True" << std::endl; }
 
99
    else
 
100
        { std::cout << "Bad: T1: False" << std::endl; passed = false; }
 
101
 
 
102
    pb1 = o;
 
103
    if( pb1 )
 
104
        { std::cout << "OK: T2: True" << std::endl; }
 
105
    else
 
106
        { std::cout << "Bad: T2: False" << std::endl; passed = false; }
 
107
 
 
108
    b1 = pb1;
 
109
    if( b1 )
 
110
        { std::cout << "OK: T3: True" << std::endl; }
 
111
    else
 
112
        { std::cout << "Bad: T3: False" << std::endl; passed = false; }
 
113
 
 
114
    pb2 = pb1;
 
115
    if( pb2 )
 
116
        { std::cout << "OK: T4: True" << std::endl; }
 
117
    else
 
118
        { std::cout << "Bad: T4: False" << std::endl; passed = false; }
 
119
 
 
120
    pb2 = true;
 
121
    if( pb2 )
 
122
        { std::cout << "OK: T5: True" << std::endl; }
 
123
    else
 
124
        { std::cout << "Bad: T5: False" << std::endl; passed = false; }
 
125
 
 
126
 
 
127
    o = Py::False();
 
128
    if( o.isTrue() )
 
129
        { std::cout << "Bad: F1: True" << std::endl; passed = false; }
 
130
    else
 
131
        { std::cout << "OK: F1: False" << std::endl; }
 
132
 
 
133
    pb1 = o;
 
134
    if( pb1 )
 
135
        { std::cout << "Bad: F2: True" << std::endl; passed = false; }
 
136
    else
 
137
        { std::cout << "OK: F2: False" << std::endl; }
 
138
 
 
139
    b1 = pb1;
 
140
    if( b1 )
 
141
        { std::cout << "Bad: F3: True" << std::endl; passed = false; }
 
142
    else
 
143
        { std::cout << "OK: F3: False" << std::endl; }
 
144
 
 
145
    pb2 = pb1;
 
146
    if( pb2 )
 
147
        { std::cout << "Bad: F4: True" << std::endl; passed = false; }
 
148
    else
 
149
        { std::cout << "OK: F4: False" << std::endl; }
 
150
 
 
151
    pb2 = false;
 
152
    if( pb2 )
 
153
        { std::cout << "Bad: F5: True" << std::endl; passed = false; }
 
154
    else
 
155
        { std::cout << "OK: F5: False" << std::endl; }
 
156
 
 
157
    if( passed )
 
158
        return "ok";
 
159
    else
 
160
        return "failed";
 
161
}
 
162
 
 
163
static std::string
 
164
test_numbers()
 
165
{
 
166
    // test the basic numerical classes
 
167
    Py::Int i;
 
168
    Py::Int j(2);
 
169
    Py::Int k = Py::Int(3);
 
170
 
 
171
    if (! (j < k)) return "failed (1)";
 
172
    if (! (j == j)) return "failed (2)" ;
 
173
    if (! (j != k)) return "failed (3)";
 
174
    if (! (j <= k)) return "failed (4)";
 
175
    if (! (k >= j)) return "failed (5)";
 
176
    if (! (k > j)) return "failed (6)";
 
177
    if (! (j <= j)) return "failed (7)";
 
178
    if (! (j >= Py::Int(2))) return "failed (8)";
 
179
 
 
180
    i = 2;
 
181
    Py::Float a;
 
182
    a = 3 + i; //5.0
 
183
    Py::Float b(4.0);
 
184
    a = (1.0 + 2*a + (b*3.0)/2.0 + k)/Py::Float(5); // 4.0
 
185
    i = a - 1.0; // 3
 
186
    if(i != k)
 
187
    {
 
188
        return "failed 9";
 
189
    }
 
190
 
 
191
    return "ok";
 
192
}
 
193
 
 
194
static std::string 
 
195
test_List_iterators (const Py::List& x, Py::List& y)
 
196
{
 
197
    std::vector<Py::Object> v;
 
198
    Py::Sequence::iterator j;
 
199
    int k = 0;
 
200
    for(Py::Sequence::const_iterator i = x.begin(); i != x.end(); ++i)
 
201
    {
 
202
        if ((*i).isList())
 
203
        {
 
204
            ++k;
 
205
        }
 
206
    }
 
207
    if(k!=1)
 
208
        return "failed List iterators (1)";
 
209
 
 
210
    k = 0;
 
211
    for(j = y.begin(); j != y.end(); ++j)
 
212
    {
 
213
        *j = Py::Int(k++);
 
214
        v.push_back (*j);
 
215
    }
 
216
 
 
217
    k = 0;
 
218
    for(j = y.begin(); j != y.end(); j++)
 
219
    {
 
220
        if(*j != Py::Int(k))
 
221
            return "failed List iterators (2)";
 
222
        if(v[k] != Py::Int(k))
 
223
            return "failed List iterators (3)";
 
224
        ++k;
 
225
    }
 
226
    Py::String o1("Howdy");
 
227
    Py::Int o2(1);
 
228
    int caught_it = 0;
 
229
    try
 
230
    {
 
231
        o2 = o1;
 
232
    } 
 
233
    catch (Py::Exception& e)
 
234
    {
 
235
        caught_it = 1;
 
236
        e.clear();
 
237
    }
 
238
    if(!caught_it)
 
239
        return "failed exception catch (4).";
 
240
    return "ok";
 
241
}
 
242
 
 
243
static Py::List
 
244
test_List_references (Py::List& x)
 
245
{
 
246
    Py::List y;
 
247
    for(Py::List::size_type i=0; i < x.length(); ++i)
 
248
    {
 
249
        if (x[i].isList())
 
250
        {
 
251
            y = x[i];
 
252
        }
 
253
    }
 
254
    return y;
 
255
}
 
256
 
 
257
static std::string
 
258
test_List()
 
259
{
 
260
    // test the Py::List class
 
261
    Py::List a;
 
262
    Py::List ans, aux;
 
263
    aux.append(Py::Int(3));
 
264
    aux.append(Py::Float(6.0));
 
265
 
 
266
    Py::Object b;
 
267
    Py::Int i(3);
 
268
    Py::Float x(6.0);
 
269
    Py::Float c(10.0), d(20.0);
 
270
    a.append(i);
 
271
    a.append(x);
 
272
    a.append(Py::Float(0.0));
 
273
    b = a[0]; 
 
274
    a[2] = b;
 
275
    a.append(c+d);
 
276
    a.append(aux);
 
277
    // a is now [3, 6.0, 3, 30.0, aux]
 
278
 
 
279
    ans.append(Py::Int(3));
 
280
    ans.append(Py::Float(6.0));
 
281
    ans.append(Py::Int(3));
 
282
    ans.append(Py::Float(30.0));
 
283
    ans.append(aux);
 
284
 
 
285
    Py::List::iterator l1, l2;
 
286
    for(l1= a.begin(), l2 = ans.begin();
 
287
        l1 != a.end() && l2 != ans.end();
 
288
        ++l1, ++l2) 
 
289
    {
 
290
        if(*l1 != *l2) return "failed 1" + a.as_string();
 
291
    }
 
292
 
 
293
    if (test_List_references (a)!= aux)
 
294
    {
 
295
        return "failed 2" + test_List_references(a).as_string();
 
296
    }
 
297
    return test_List_iterators(ans, a);
 
298
}
 
299
 
 
300
static std::string
 
301
test_Dict()
 
302
{
 
303
    // test the Dict class
 
304
    Py::Dict a,b;
 
305
    Py::List v;
 
306
    Py::String s("two");
 
307
    a["one"] = Py::Int(1);
 
308
    a[s] = Py::Int(2);
 
309
    a["three"] = Py::Int(3);
 
310
    if(Py::Int(a["one"]) != Py::Int(1))
 
311
        return "failed 1a " + a.as_string();
 
312
    if(Py::Int(a[s]) != Py::Int(2))
 
313
        return "failed 1b " + a.as_string();
 
314
 
 
315
    v = a.values();
 
316
 
 
317
#if 0
 
318
    std::sort(v.begin(), v.end());
 
319
 
 
320
    for(int k = 1; k < 4; ++k)
 
321
    {
 
322
        if(v[k-1] != Py::Int(k))
 
323
            return "failed 2 " + v.as_string();
 
324
    }
 
325
#endif
 
326
 
 
327
    b = a;
 
328
    b.clear();
 
329
    if(b.keys().length() != 0)
 
330
    {
 
331
        return "failed 3 " + b.as_string();
 
332
    }
 
333
 
 
334
    const Py::Dict c;
 
335
    for (Py::Dict::const_iterator it = c.begin(); it != c.end(); ++it)
 
336
    {
 
337
    }
 
338
 
 
339
    return "ok";
 
340
}
 
341
 
 
342
static std::string
 
343
test_Tuple()
 
344
{
 
345
    // test the Tuple class
 
346
    Py::Tuple a(3);
 
347
    Py::Tuple t1;
 
348
    Py::Float f1(1.0), f2(2.0), f3(3.0);
 
349
    a[0] = f1; // should be ok since no other reference owned
 
350
    a[1] = f2;
 
351
    a[2] = f3;
 
352
    Py::Tuple b(a);
 
353
    int k = 0;
 
354
    for(Py::Tuple::iterator i = b.begin(); i != b.end(); ++i)
 
355
    {
 
356
        if(*i != Py::Float(++k)) return "failed 1 " + b.as_string();
 
357
    }
 
358
 
 
359
    t1 = a;
 
360
    try
 
361
    {
 
362
        t1[0] = Py::Int(1); // should fail, tuple has multiple references
 
363
        return "failed 2";
 
364
    }
 
365
    catch (Py::Exception& e)
 
366
    {
 
367
        e.clear();
 
368
    }
 
369
    return "ok";
 
370
}
 
371
 
 
372
static std::string 
 
373
test_STL()
 
374
{
 
375
    int ans1;
 
376
    Py::List w;
 
377
    Py::List wans;
 
378
    wans.append(Py::Int(1));
 
379
    wans.append(Py::Int(1));
 
380
    wans.append(Py::Int(2));
 
381
    wans.append(Py::Int(3));
 
382
    wans.append(Py::Int(4));
 
383
    wans.append(Py::Int(5));
 
384
    w.append(Py::Int(5));
 
385
    w.append(Py::Int(1));
 
386
    w.append(Py::Int(4));
 
387
    w.append(Py::Int(2));
 
388
    w.append(Py::Int(3));
 
389
    w.append(Py::Int(1));
 
390
    ans1 = std::count(w.begin(), w.end(), Py::Float(1.0));
 
391
    if (ans1 != 2)
 
392
    {
 
393
        return "failed count test";
 
394
    }
 
395
 
 
396
 
 
397
#if 0
 
398
    std::sort(w.begin(), w.end());
 
399
    if (w != wans)
 
400
    {
 
401
        return "failed sort test";
 
402
    }
 
403
#endif
 
404
 
 
405
    Py::Dict    d;
 
406
    Py::String    s1("blah");
 
407
    Py::String    s2("gorf");
 
408
    d[ "one" ] = s1;
 
409
    d[ "two" ] = s1;
 
410
    d[ "three" ] = s2;
 
411
    d[ "four" ] = s2;
 
412
 
 
413
    Py::Dict::iterator    it = d.begin();
 
414
    for( ; it != d.end(); ++it )
 
415
    {
 
416
        Py::Dict::value_type vt( *it );
 
417
        Py::String rs = vt.second.repr();
 
418
        std::string ls = rs.operator std::string();
 
419
        std::cout << "dict value " << ls.c_str() << std::endl;
 
420
    }
 
421
 
 
422
    return "ok";
 
423
}
 
424
 
 
425
void debug_check_ref_queue()
 
426
{
 
427
#ifdef Py_TRACE_REFS
 
428
 
 
429
    // create an element to find the queue
 
430
    Py::Int list_element;
 
431
 
 
432
    PyObject *p_slow = list_element.ptr();
 
433
    PyObject *p_fast = p_slow;
 
434
 
 
435
    do
 
436
    {
 
437
        assert( p_slow->_ob_next->_ob_prev == p_slow );
 
438
        assert( p_slow->_ob_prev->_ob_next == p_slow );
 
439
 
 
440
 
 
441
        p_slow = p_slow->_ob_next;
 
442
        p_fast = p_slow->_ob_next->_ob_next;
 
443
 
 
444
        assert( p_slow != p_fast );    
 
445
    }
 
446
    while( p_slow != list_element.ptr() );
 
447
 
 
448
#endif
 
449
}
 
450
 
 
451
 
 
452
class example_module : public Py::ExtensionModule<example_module>
 
453
{
 
454
public:
 
455
    example_module()
 
456
        : Py::ExtensionModule<example_module>( "example" )
 
457
    {
 
458
        range::init_type();
 
459
 
 
460
        add_varargs_method("string", &example_module::ex_string, "string( s ) = return string");
 
461
        add_varargs_method("sum", &example_module::ex_sum, "sum(arglist) = sum of arguments");
 
462
        add_varargs_method("test", &example_module::ex_test, "test(arglist) runs a test suite");
 
463
        add_varargs_method("range", &example_module::new_r, "range(start,stop,stride)");
 
464
        add_keyword_method("kw", &example_module::ex_keyword, "kw()");
 
465
 
 
466
        initialize( "documentation for the example module" );
 
467
 
 
468
        Py::Dict d( moduleDictionary() );
 
469
 
 
470
        Py::Object b(Py::asObject(new range(1,10,2)));
 
471
 
 
472
        d["a_constant"] = b.getAttr("c");
 
473
    }
 
474
 
 
475
    virtual ~example_module()
 
476
    {}
 
477
 
 
478
private:
 
479
    Py::Object ex_keyword( const Py::Tuple &args, const Py::Dict &kws )
 
480
    {
 
481
        std::cout << "Called with " << args.length() << " normal arguments." << std::endl;
 
482
        Py::List names( kws.keys() );
 
483
        std::cout << "and with " << names.length() << " keyword arguments:" << std::endl;
 
484
        for( Py::List::size_type i=0; i< names.length(); i++ )
 
485
        {
 
486
            Py::String name( names[i] );
 
487
            std::cout << "    " << name << std::endl;
 
488
        }
 
489
 
 
490
        return Py::Int(0);
 
491
    }
 
492
 
 
493
    Py::Object new_r (const Py::Tuple &rargs)
 
494
    {
 
495
        if (rargs.length() < 2 || rargs.length() > 3)
 
496
        {
 
497
            throw Py::RuntimeError("Incorrect # of args to range(start,stop [,step]).");
 
498
        }
 
499
 
 
500
        Py::Int start(rargs[0]);
 
501
        Py::Int stop(rargs[1]);
 
502
        Py::Int step(1);
 
503
        if (rargs.length() == 3)
 
504
        {
 
505
            step = rargs[2];
 
506
        }
 
507
        if (long(start) > long(stop) + 1 || long(step) == 0)
 
508
        {
 
509
            throw Py::RuntimeError("Bad arguments to range(start,stop [,step]).");
 
510
        }
 
511
        return Py::asObject(new range(start, stop, step));
 
512
    }
 
513
 
 
514
    Py::Object ex_string (const Py::Tuple &a)
 
515
    {
 
516
        std::cout << "ex_std::string: s1 is first arg" << std::endl;
 
517
        Py::String s1( a[0] );
 
518
        std::cout << "ex_string: s1.isString() " << s1.isString() << std::endl;
 
519
        std::cout << "ex_string: s1.isUnicode() " << s1.isUnicode() << std::endl;
 
520
        std::cout << "ex_string: s1.size() " << s1.size() << std::endl;
 
521
 
 
522
        if( s1.isUnicode() )
 
523
        {
 
524
            std::cout << "ex_string: s2 is s1.encode( utf-8 )" << std::endl;
 
525
            Py::String s2( s1.encode( "utf-8" ) );
 
526
            std::cout << "ex_string: s2.isString() " << s2.isString() << std::endl;
 
527
            std::cout << "ex_string: s2.isUnicode() " << s2.isUnicode() << std::endl;
 
528
            std::cout << "ex_string: s2.size() " << s2.size() << std::endl;
 
529
            return s2;
 
530
        }
 
531
        else
 
532
        {
 
533
            std::cout << "ex_string: s2 is s1.decode( utf-8 )" << std::endl;
 
534
            Py::String s2( s1.decode( "utf-8" ) );
 
535
            std::cout << "ex_string: s2.isString() " << s2.isString() << std::endl;
 
536
            std::cout << "ex_string: s2.isUnicode() " << s2.isUnicode() << std::endl;
 
537
            std::cout << "ex_string: s2.size() " << s2.size() << std::endl;
 
538
            return s2;
 
539
        }
 
540
    }
 
541
 
 
542
    Py::Object ex_sum (const Py::Tuple &a)
 
543
    {
 
544
        // this is just to test the function verify_length:
 
545
        try
 
546
        {
 
547
            a.verify_length(0);
 
548
            std::cout << "I see that you refuse to give me any work to do." << std::endl;
 
549
        }
 
550
        catch (Py::Exception& e)
 
551
        {
 
552
            e.clear();
 
553
            std::cout << "I will now add up your elements, oh great one." << std::endl;
 
554
        }
 
555
 
 
556
 
 
557
        Py::Float f(0.0);
 
558
        for( Py::Sequence::size_type i = 0; i < a.length(); i++ )
 
559
        {    
 
560
            Py::Float g (a[i]);
 
561
            f = f + g;
 
562
        }
 
563
 
 
564
        return f;
 
565
    }
 
566
 
 
567
    Py::Object ex_test( const Py::Tuple &a) 
 
568
    {
 
569
        debug_check_ref_queue();
 
570
 
 
571
        std::cout << "Example Test starting" << std::endl;
 
572
        try
 
573
        {
 
574
            PyObject *p = NULL;
 
575
            std::cout << "Trying to convert a NULL to an Py::Int" << std::endl;
 
576
            Py::Int k( p );
 
577
            std::cout << "Failed to raise error" << std::endl;
 
578
        }
 
579
        catch (Py::TypeError& e)
 
580
        {
 
581
            std::cout << "Correctly caught " << Py::type(e) << std::endl;
 
582
            std::cout << "  Py::Exception value: " << Py::value(e) << std::endl;
 
583
            std::cout << "  Py::Exception traceback: " << Py::trace(e) << std::endl;
 
584
            e.clear();
 
585
        }
 
586
 
 
587
        try
 
588
        {
 
589
            Py::String s("this should fail");
 
590
            PyObject *p = s.ptr();
 
591
            std::cout << "Trying to convert a Py::String to an Py::Int" << std::endl;
 
592
            Py::Int k( p );
 
593
            std::cout << "Failed to raise error" << std::endl;
 
594
        }
 
595
        catch (Py::TypeError& e)
 
596
        {
 
597
            std::cout << "Correctly caught " << Py::type(e) << std::endl;
 
598
            std::cout << "  Py::Exception value: " << Py::value(e) << std::endl;
 
599
            std::cout << "  Py::Exception traceback: " << Py::trace(e) << std::endl;
 
600
            e.clear();
 
601
        }
 
602
 
 
603
        debug_check_ref_queue();
 
604
 
 
605
        std::string result = test_boolean();
 
606
        std::cout << "Py::Boolean: " << result << std::endl;
 
607
        debug_check_ref_queue();
 
608
        std::cout << "Numbers: " << test_numbers() << std::endl;
 
609
        debug_check_ref_queue();
 
610
        std::cout << "Py::String: " << test_String() << std::endl;
 
611
        debug_check_ref_queue();
 
612
        std::cout << "Py::List: " << test_List() << std::endl;
 
613
        debug_check_ref_queue();
 
614
        std::cout << "Py::Dict: " << test_Dict() << std::endl;
 
615
        debug_check_ref_queue();
 
616
        std::cout << "Py::Tuple: " << test_Tuple() << std::endl;
 
617
        debug_check_ref_queue();
 
618
        std::cout << "STL test: " << test_STL() << std::endl;
 
619
        debug_check_ref_queue();
 
620
        std::cout << "Extension object test: " << test_extension_object() << std::endl;
 
621
        debug_check_ref_queue();
 
622
 
 
623
        Py::List b(a);
 
624
        Py::Tuple c(b);
 
625
        if( c != a)
 
626
        {
 
627
            std::cout << "Py::Tuple/list conversion failed.\n";
 
628
        }
 
629
 
 
630
        Py::Module m("sys");
 
631
        Py::Object s = m.getAttr("stdout");
 
632
        Py::Object nun;
 
633
        nun = PyObject_CallMethod(s.ptr(), "write", "s", "Module test ok.\n");
 
634
        return Py::None();
 
635
    }
 
636
};
 
637
 
 
638
extern "C" void initexample()
 
639
{
 
640
#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL)
 
641
    Py::InitialisePythonIndirectPy::Interface();
 
642
#endif
 
643
 
 
644
    static example_module* example = new example_module;
 
645
}
 
646
 
 
647
// symbol required for the debug version
 
648
extern "C" void initexample_d()
 
649
{ initexample(); }