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

« back to all changes in this revision

Viewing changes to Import/pycxx-5.4.2/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
 
    return "ok";
80
 
}
81
 
 
82
 
static std::string
83
 
test_boolean()
84
 
{
85
 
    bool passed = true;
86
 
 
87
 
    Py::Object o;
88
 
    Py::Boolean pb1;
89
 
    Py::Boolean pb2;
90
 
    bool b1;
91
 
 
92
 
    o = Py::True();
93
 
    if( o.isTrue() )
94
 
        { std::cout << "OK: T1: True" << std::endl; }
95
 
    else
96
 
        { std::cout << "Bad: T1: False" << std::endl; passed = false; }
97
 
 
98
 
    pb1 = o;
99
 
    if( pb1 )
100
 
        { std::cout << "OK: T2: True" << std::endl; }
101
 
    else
102
 
        { std::cout << "Bad: T2: False" << std::endl; passed = false; }
103
 
 
104
 
    b1 = pb1;
105
 
    if( b1 )
106
 
        { std::cout << "OK: T3: True" << std::endl; }
107
 
    else
108
 
        { std::cout << "Bad: T3: False" << std::endl; passed = false; }
109
 
 
110
 
    pb2 = pb1;
111
 
    if( pb2 )
112
 
        { std::cout << "OK: T4: True" << std::endl; }
113
 
    else
114
 
        { std::cout << "Bad: T4: False" << std::endl; passed = false; }
115
 
 
116
 
    pb2 = true;
117
 
    if( pb2 )
118
 
        { std::cout << "OK: T5: True" << std::endl; }
119
 
    else
120
 
        { std::cout << "Bad: T5: False" << std::endl; passed = false; }
121
 
 
122
 
 
123
 
    o = Py::False();
124
 
    if( o.isTrue() )
125
 
        { std::cout << "Bad: F1: True" << std::endl; passed = false; }
126
 
    else
127
 
        { std::cout << "OK: F1: False" << std::endl; }
128
 
 
129
 
    pb1 = o;
130
 
    if( pb1 )
131
 
        { std::cout << "Bad: F2: True" << std::endl; passed = false; }
132
 
    else
133
 
        { std::cout << "OK: F2: False" << std::endl; }
134
 
 
135
 
    b1 = pb1;
136
 
    if( b1 )
137
 
        { std::cout << "Bad: F3: True" << std::endl; passed = false; }
138
 
    else
139
 
        { std::cout << "OK: F3: False" << std::endl; }
140
 
 
141
 
    pb2 = pb1;
142
 
    if( pb2 )
143
 
        { std::cout << "Bad: F4: True" << std::endl; passed = false; }
144
 
    else
145
 
        { std::cout << "OK: F4: False" << std::endl; }
146
 
 
147
 
    pb2 = false;
148
 
    if( pb2 )
149
 
        { std::cout << "Bad: F5: True" << std::endl; passed = false; }
150
 
    else
151
 
        { std::cout << "OK: F5: False" << std::endl; }
152
 
 
153
 
    if( passed )
154
 
        return "ok";
155
 
    else
156
 
        return "failed";
157
 
}
158
 
 
159
 
static std::string
160
 
test_numbers()
161
 
{
162
 
    // test the basic numerical classes
163
 
    Py::Int i;
164
 
    Py::Int j(2);
165
 
    Py::Int k = Py::Int(3);
166
 
 
167
 
    if (! (j < k)) return "failed (1)";
168
 
    if (! (j == j)) return "failed (2)" ;
169
 
    if (! (j != k)) return "failed (3)";
170
 
    if (! (j <= k)) return "failed (4)";
171
 
    if (! (k >= j)) return "failed (5)";
172
 
    if (! (k > j)) return "failed (6)";
173
 
    if (! (j <= j)) return "failed (7)";
174
 
    if (! (j >= Py::Int(2))) return "failed (8)";
175
 
 
176
 
    i = 2;
177
 
    Py::Float a;
178
 
    a = 3 + i; //5.0
179
 
    Py::Float b(4.0);
180
 
    a = (1.0 + 2*a + (b*3.0)/2.0 + k)/Py::Float(5); // 4.0
181
 
    i = a - 1.0; // 3
182
 
    if(i != k)
183
 
    {
184
 
        return "failed 9";
185
 
    }
186
 
 
187
 
    return "ok";
188
 
}
189
 
 
190
 
static std::string 
191
 
test_List_iterators (const Py::List& x, Py::List& y)
192
 
{
193
 
    std::vector<Py::Object> v;
194
 
    Py::Sequence::iterator j;
195
 
    int k = 0;
196
 
    for(Py::Sequence::const_iterator i = x.begin(); i != x.end(); ++i)
197
 
    {
198
 
        if ((*i).isList())
199
 
        {
200
 
            ++k;
201
 
        }
202
 
    }
203
 
    if(k!=1)
204
 
        return "failed List iterators (1)";
205
 
 
206
 
    k = 0;
207
 
    for(j = y.begin(); j != y.end(); ++j)
208
 
    {
209
 
        *j = Py::Int(k++);
210
 
        v.push_back (*j);
211
 
    }
212
 
 
213
 
    k = 0;
214
 
    for(j = y.begin(); j != y.end(); j++)
215
 
    {
216
 
        if(*j != Py::Int(k))
217
 
            return "failed List iterators (2)";
218
 
        if(v[k] != Py::Int(k))
219
 
            return "failed List iterators (3)";
220
 
        ++k;
221
 
    }
222
 
    Py::String o1("Howdy");
223
 
    Py::Int o2(1);
224
 
    int caught_it = 0;
225
 
    try
226
 
    {
227
 
        o2 = o1;
228
 
    } 
229
 
    catch (Py::Exception& e)
230
 
    {
231
 
        caught_it = 1;
232
 
        e.clear();
233
 
    }
234
 
    if(!caught_it)
235
 
        return "failed exception catch (4).";
236
 
    return "ok";
237
 
}
238
 
 
239
 
static Py::List
240
 
test_List_references (Py::List& x)
241
 
{
242
 
    Py::List y;
243
 
    for(Py::List::size_type i=0; i < x.length(); ++i)
244
 
    {
245
 
        if (x[i].isList())
246
 
        {
247
 
            y = x[i];
248
 
        }
249
 
    }
250
 
    return y;
251
 
}
252
 
 
253
 
static std::string
254
 
test_List()
255
 
{
256
 
    // test the Py::List class
257
 
    Py::List a;
258
 
    Py::List ans, aux;
259
 
    aux.append(Py::Int(3));
260
 
    aux.append(Py::Float(6.0));
261
 
 
262
 
    Py::Object b;
263
 
    Py::Int i(3);
264
 
    Py::Float x(6.0);
265
 
    Py::Float c(10.0), d(20.0);
266
 
    a.append(i);
267
 
    a.append(x);
268
 
    a.append(Py::Float(0.0));
269
 
    b = a[0]; 
270
 
    a[2] = b;
271
 
    a.append(c+d);
272
 
    a.append(aux);
273
 
    // a is now [3, 6.0, 3, 30.0, aux]
274
 
 
275
 
    ans.append(Py::Int(3));
276
 
    ans.append(Py::Float(6.0));
277
 
    ans.append(Py::Int(3));
278
 
    ans.append(Py::Float(30.0));
279
 
    ans.append(aux);
280
 
 
281
 
    Py::List::iterator l1, l2;
282
 
    for(l1= a.begin(), l2 = ans.begin();
283
 
        l1 != a.end() && l2 != ans.end();
284
 
        ++l1, ++l2) 
285
 
    {
286
 
        if(*l1 != *l2) return "failed 1" + a.as_string();
287
 
    }
288
 
 
289
 
    if (test_List_references (a)!= aux)
290
 
    {
291
 
        return "failed 2" + test_List_references(a).as_string();
292
 
    }
293
 
    return test_List_iterators(ans, a);
294
 
}
295
 
 
296
 
static std::string
297
 
test_Dict()
298
 
{
299
 
    // test the Dict class
300
 
    Py::Dict a,b;
301
 
    Py::List v;
302
 
    Py::String s("two");
303
 
    a["one"] = Py::Int(1);
304
 
    a[s] = Py::Int(2);
305
 
    a["three"] = Py::Int(3);
306
 
    if(Py::Int(a["one"]) != Py::Int(1))
307
 
        return "failed 1a " + a.as_string();
308
 
    if(Py::Int(a[s]) != Py::Int(2))
309
 
        return "failed 1b " + a.as_string();
310
 
 
311
 
    v = a.values();
312
 
 
313
 
#if 0
314
 
    std::sort(v.begin(), v.end());
315
 
 
316
 
    for(int k = 1; k < 4; ++k)
317
 
    {
318
 
        if(v[k-1] != Py::Int(k))
319
 
            return "failed 2 " + v.as_string();
320
 
    }
321
 
#endif
322
 
 
323
 
    b = a;
324
 
    b.clear();
325
 
    if(b.keys().length() != 0)
326
 
    {
327
 
        return "failed 3 " + b.as_string();
328
 
    }
329
 
    return "ok";
330
 
}
331
 
 
332
 
static std::string
333
 
test_Tuple()
334
 
{
335
 
    // test the Tuple class
336
 
    Py::Tuple a(3);
337
 
    Py::Tuple t1;
338
 
    Py::Float f1(1.0), f2(2.0), f3(3.0);
339
 
    a[0] = f1; // should be ok since no other reference owned
340
 
    a[1] = f2;
341
 
    a[2] = f3;
342
 
    Py::Tuple b(a);
343
 
    int k = 0;
344
 
    for(Py::Tuple::iterator i = b.begin(); i != b.end(); ++i)
345
 
    {
346
 
        if(*i != Py::Float(++k)) return "failed 1 " + b.as_string();
347
 
    }
348
 
 
349
 
    t1 = a;
350
 
    try
351
 
    {
352
 
        t1[0] = Py::Int(1); // should fail, tuple has multiple references
353
 
        return "failed 2";
354
 
    }
355
 
    catch (Py::Exception& e)
356
 
    {
357
 
        e.clear();
358
 
    }
359
 
    return "ok";
360
 
}
361
 
 
362
 
static std::string 
363
 
test_STL()
364
 
{
365
 
    int ans1;
366
 
    Py::List w;
367
 
    Py::List wans;
368
 
    wans.append(Py::Int(1));
369
 
    wans.append(Py::Int(1));
370
 
    wans.append(Py::Int(2));
371
 
    wans.append(Py::Int(3));
372
 
    wans.append(Py::Int(4));
373
 
    wans.append(Py::Int(5));
374
 
    w.append(Py::Int(5));
375
 
    w.append(Py::Int(1));
376
 
    w.append(Py::Int(4));
377
 
    w.append(Py::Int(2));
378
 
    w.append(Py::Int(3));
379
 
    w.append(Py::Int(1));
380
 
    ans1 = std::count(w.begin(), w.end(), Py::Float(1.0));
381
 
    if (ans1 != 2)
382
 
    {
383
 
        return "failed count test";
384
 
    }
385
 
 
386
 
 
387
 
#if 0
388
 
    std::sort(w.begin(), w.end());
389
 
    if (w != wans)
390
 
    {
391
 
        return "failed sort test";
392
 
    }
393
 
#endif
394
 
 
395
 
    Py::Dict    d;
396
 
    Py::String    s1("blah");
397
 
    Py::String    s2("gorf");
398
 
    d[ "one" ] = s1;
399
 
    d[ "two" ] = s1;
400
 
    d[ "three" ] = s2;
401
 
    d[ "four" ] = s2;
402
 
 
403
 
    Py::Dict::iterator    it = d.begin();
404
 
    for( ; it != d.end(); ++it )
405
 
    {
406
 
        Py::Dict::value_type vt( *it );
407
 
        Py::String rs = vt.second.repr();
408
 
        std::string ls = rs.operator std::string();
409
 
        std::cout << "dict value " << ls.c_str() << std::endl;
410
 
    }
411
 
 
412
 
    return "ok";
413
 
}
414
 
 
415
 
void debug_check_ref_queue()
416
 
{
417
 
#ifdef Py_TRACE_REFS
418
 
 
419
 
    // create an element to find the queue
420
 
    Py::Int list_element;
421
 
 
422
 
    PyObject *p_slow = list_element.ptr();
423
 
    PyObject *p_fast = p_slow;
424
 
 
425
 
    do
426
 
    {
427
 
        assert( p_slow->_ob_next->_ob_prev == p_slow );
428
 
        assert( p_slow->_ob_prev->_ob_next == p_slow );
429
 
 
430
 
 
431
 
        p_slow = p_slow->_ob_next;
432
 
        p_fast = p_slow->_ob_next->_ob_next;
433
 
 
434
 
        assert( p_slow != p_fast );    
435
 
    }
436
 
    while( p_slow != list_element.ptr() );
437
 
 
438
 
#endif
439
 
}
440
 
 
441
 
 
442
 
class example_module : public Py::ExtensionModule<example_module>
443
 
{
444
 
public:
445
 
    example_module()
446
 
        : Py::ExtensionModule<example_module>( "example" )
447
 
    {
448
 
        range::init_type();
449
 
 
450
 
        add_varargs_method("string", &example_module::ex_string, "string( s ) = return string");
451
 
        add_varargs_method("sum", &example_module::ex_sum, "sum(arglist) = sum of arguments");
452
 
        add_varargs_method("test", &example_module::ex_test, "test(arglist) runs a test suite");
453
 
        add_varargs_method("range", &example_module::new_r, "range(start,stop,stride)");
454
 
        add_keyword_method("kw", &example_module::ex_keyword, "kw()");
455
 
 
456
 
        initialize( "documentation for the example module" );
457
 
 
458
 
        Py::Dict d( moduleDictionary() );
459
 
 
460
 
        Py::Object b(Py::asObject(new range(1,10,2)));
461
 
 
462
 
        d["a_constant"] = b.getAttr("c");
463
 
    }
464
 
 
465
 
    virtual ~example_module()
466
 
    {}
467
 
 
468
 
private:
469
 
    Py::Object ex_keyword( const Py::Tuple &args, const Py::Dict &kws )
470
 
    {
471
 
        std::cout << "Called with " << args.length() << " normal arguments." << std::endl;
472
 
        Py::List names( kws.keys() );
473
 
        std::cout << "and with " << names.length() << " keyword arguments:" << std::endl;
474
 
        for( Py::List::size_type i=0; i< names.length(); i++ )
475
 
        {
476
 
            Py::String name( names[i] );
477
 
            std::cout << "    " << name << std::endl;
478
 
        }
479
 
 
480
 
        return Py::Int(0);
481
 
    }
482
 
 
483
 
    Py::Object new_r (const Py::Tuple &rargs)
484
 
    {
485
 
        if (rargs.length() < 2 || rargs.length() > 3)
486
 
        {
487
 
            throw Py::RuntimeError("Incorrect # of args to range(start,stop [,step]).");
488
 
        }
489
 
 
490
 
        Py::Int start(rargs[0]);
491
 
        Py::Int stop(rargs[1]);
492
 
        Py::Int step(1);
493
 
        if (rargs.length() == 3)
494
 
        {
495
 
            step = rargs[2];
496
 
        }
497
 
        if (long(start) > long(stop) + 1 || long(step) == 0)
498
 
        {
499
 
            throw Py::RuntimeError("Bad arguments to range(start,stop [,step]).");
500
 
        }
501
 
        return Py::asObject(new range(start, stop, step));
502
 
    }
503
 
 
504
 
    Py::Object ex_string (const Py::Tuple &a)
505
 
    {
506
 
        std::cout << "ex_std::string: s1 is first arg" << std::endl;
507
 
        Py::String s1( a[0] );
508
 
        std::cout << "ex_string: s1.isString() " << s1.isString() << std::endl;
509
 
        std::cout << "ex_string: s1.isUnicode() " << s1.isUnicode() << std::endl;
510
 
        std::cout << "ex_string: s1.size() " << s1.size() << std::endl;
511
 
 
512
 
        if( s1.isUnicode() )
513
 
        {
514
 
            std::cout << "ex_string: s2 is s1.encode( utf-8 )" << std::endl;
515
 
            Py::String s2( s1.encode( "utf-8" ) );
516
 
            std::cout << "ex_string: s2.isString() " << s2.isString() << std::endl;
517
 
            std::cout << "ex_string: s2.isUnicode() " << s2.isUnicode() << std::endl;
518
 
            std::cout << "ex_string: s2.size() " << s2.size() << std::endl;
519
 
            return s2;
520
 
        }
521
 
        else
522
 
        {
523
 
            std::cout << "ex_string: s2 is s1.decode( utf-8 )" << std::endl;
524
 
            Py::String s2( s1.decode( "utf-8" ) );
525
 
            std::cout << "ex_string: s2.isString() " << s2.isString() << std::endl;
526
 
            std::cout << "ex_string: s2.isUnicode() " << s2.isUnicode() << std::endl;
527
 
            std::cout << "ex_string: s2.size() " << s2.size() << std::endl;
528
 
            return s2;
529
 
        }
530
 
    }
531
 
 
532
 
    Py::Object ex_sum (const Py::Tuple &a)
533
 
    {
534
 
        // this is just to test the function verify_length:
535
 
        try
536
 
        {
537
 
            a.verify_length(0);
538
 
            std::cout << "I see that you refuse to give me any work to do." << std::endl;
539
 
        }
540
 
        catch (Py::Exception& e)
541
 
        {
542
 
            e.clear();
543
 
            std::cout << "I will now add up your elements, oh great one." << std::endl;
544
 
        }
545
 
 
546
 
 
547
 
        Py::Float f(0.0);
548
 
        for( Py::Sequence::size_type i = 0; i < a.length(); i++ )
549
 
        {    
550
 
            Py::Float g (a[i]);
551
 
            f = f + g;
552
 
        }
553
 
 
554
 
        return f;
555
 
    }
556
 
 
557
 
    Py::Object ex_test( const Py::Tuple &a) 
558
 
    {
559
 
        debug_check_ref_queue();
560
 
 
561
 
        std::cout << "Example Test starting" << std::endl;
562
 
        try
563
 
        {
564
 
            PyObject *p = NULL;
565
 
            std::cout << "Trying to convert a NULL to an Py::Int" << std::endl;
566
 
            Py::Int k( p );
567
 
            std::cout << "Failed to raise error" << std::endl;
568
 
        }
569
 
        catch (Py::TypeError& e)
570
 
        {
571
 
            std::cout << "Correctly caught " << Py::type(e) << std::endl;
572
 
            std::cout << "  Py::Exception value: " << Py::value(e) << std::endl;
573
 
            std::cout << "  Py::Exception traceback: " << Py::trace(e) << std::endl;
574
 
            e.clear();
575
 
        }
576
 
 
577
 
        try
578
 
        {
579
 
            Py::String s("this should fail");
580
 
            PyObject *p = s.ptr();
581
 
            std::cout << "Trying to convert a Py::String to an Py::Int" << std::endl;
582
 
            Py::Int k( p );
583
 
            std::cout << "Failed to raise error" << std::endl;
584
 
        }
585
 
        catch (Py::TypeError& e)
586
 
        {
587
 
            std::cout << "Correctly caught " << Py::type(e) << std::endl;
588
 
            std::cout << "  Py::Exception value: " << Py::value(e) << std::endl;
589
 
            std::cout << "  Py::Exception traceback: " << Py::trace(e) << std::endl;
590
 
            e.clear();
591
 
        }
592
 
 
593
 
        debug_check_ref_queue();
594
 
 
595
 
        std::string result = test_boolean();
596
 
        std::cout << "Py::Boolean: " << result << std::endl;
597
 
        debug_check_ref_queue();
598
 
        std::cout << "Numbers: " << test_numbers() << std::endl;
599
 
        debug_check_ref_queue();
600
 
        std::cout << "Py::String: " << test_String() << std::endl;
601
 
        debug_check_ref_queue();
602
 
        std::cout << "Py::List: " << test_List() << std::endl;
603
 
        debug_check_ref_queue();
604
 
        std::cout << "Py::Dict: " << test_Dict() << std::endl;
605
 
        debug_check_ref_queue();
606
 
        std::cout << "Py::Tuple: " << test_Tuple() << std::endl;
607
 
        debug_check_ref_queue();
608
 
        std::cout << "STL test: " << test_STL() << std::endl;
609
 
        debug_check_ref_queue();
610
 
        std::cout << "Extension object test: " << test_extension_object() << std::endl;
611
 
        debug_check_ref_queue();
612
 
 
613
 
        Py::List b(a);
614
 
        Py::Tuple c(b);
615
 
        if( c != a)
616
 
        {
617
 
            std::cout << "Py::Tuple/list conversion failed.\n";
618
 
        }
619
 
 
620
 
        Py::Module m("sys");
621
 
        Py::Object s = m.getAttr("stdout");
622
 
        Py::Object nun;
623
 
        nun = PyObject_CallMethod(s.ptr(), "write", "s", "Module test ok.\n");
624
 
        return Py::None();
625
 
    }
626
 
};
627
 
 
628
 
extern "C" void initexample()
629
 
{
630
 
#if defined(PY_WIN32_DELAYLOAD_PYTHON_DLL)
631
 
    Py::InitialisePythonIndirectPy::Interface();
632
 
#endif
633
 
 
634
 
    static example_module* example = new example_module;
635
 
}
636
 
 
637
 
// symbol required for the debug version
638
 
extern "C" void initexample_d()
639
 
{ initexample(); }