Opened 14 years ago

Closed 14 years ago

#2794 closed Patches (invalid)

boost::python::handle constructor problem

Reported by: Rick Yang <rick68@…> Owned by: Dave Abrahams
Milestone: Boost 1.39.0 Component: python USE GITHUB
Version: Boost 1.38.0 Severity: Problem
Keywords: Cc:

Description

Hi,

I tried my test code:

#include <iostream>                                                                               
                                                                                                  
#include <boost/cstdlib.hpp>                                                                      
                                                                                                  
#include <boost/python/refcount.hpp>                                                              
#include <boost/python/handle.hpp>                                                                
                                                                                                  
int main(void)                                                                                    
{                                                                                                 
    using boost::python::allow_null;                                                              
    using boost::python::handle;                                                                  
                                                                                                  
    Py_Initialize();                                                                              
                                                                                                  
    PyObject* py_int = PyInt_FromLong(68);                                                        
                                                                                                  
    std::cout << "py_int->ob_refcnt = ["                                                          
        << py_int->ob_refcnt << ']' << std::endl;                                                 
                                                                                                  
                                                                                                  
    {                                                                                             
        handle<PyObject> h1(allow_null(py_int));                                                  
        handle<PyObject> h2(py_int);                                                              
    }                                                                                             
    std::cout << "py_int->ob_refcnt = ["                                                          
        << py_int->ob_refcnt << ']' << std::endl;                                                 
                                                                                                  
    boost::python::decref(py_int);                                                                
    Py_Finalize();                                                                                
                                                                                                  
                                                                                                  
    return boost::exit_success;                                                                   
}

and this is my result:

py_int->ob_refcnt = [9]
py_int->ob_refcnt = [7]

the reference counter not keep to1 9.

Change History (1)

comment:1 by Rick Yang <rick68@…>, 14 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.