Ticket #3716: boost_python_function.patch

File boost_python_function.patch, 2.0 KB (added by Emmanuel Giasson <zirconia_@…>, 13 years ago)

Potential way to fix that issue

  • .\libs\python\src\

    diff -dur .\libs\python\src\object_bak/function.cpp .\libs\python\src\object/function.cpp
    old new  
    5151    return this->min_arity();
    5252}
    5353
    54 extern PyTypeObject function_type;
     54extern PyTypeObject function_type_skel;
     55extern PyTypeObject * function_type_ptr;
    5556
    5657function::function(
    5758    py_function const& implementation
     
    105106    }
    106107   
    107108    PyObject* p = this;
    108     if (Py_TYPE(&function_type) == 0)
     109    if ( function_type_ptr == NULL )
    109110    {
    110         Py_TYPE(&function_type) = &PyType_Type;
    111         ::PyType_Ready(&function_type);
     111        function_type_ptr = PyObject_New( PyTypeObject, &PyType_Type );
     112        *function_type_ptr = function_type_skel;
     113        ::PyType_Ready(function_type_ptr);
    112114    }
    113115   
    114116    (void)(     // warning suppression for GCC
    115         PyObject_INIT(p, &function_type)
     117        PyObject_INIT(p, function_type_ptr)
    116118    );
    117119}
    118120
     
    430432    str const name(name_);
    431433    PyObject* const ns = name_space.ptr();
    432434   
    433     if (attribute.ptr()->ob_type == &function_type)
     435    if (attribute.ptr()->ob_type == function_type_ptr)
    434436    {
    435437        function* new_func = downcast<function>(attribute.ptr());
    436438        PyObject* dict = 0;
     
    453455       
    454456        if (existing)
    455457        {
    456             if (existing->ob_type == &function_type)
     458            if (existing->ob_type == function_type_ptr)
    457459            {
    458460                new_func->add_overload(
    459461                    handle<function>(
     
    681683    {NULL, 0, 0, 0, 0} /* Sentinel */
    682684};
    683685
    684 PyTypeObject function_type = {
    685     PyVarObject_HEAD_INIT(NULL, 0)
     686PyTypeObject * function_type_ptr = NULL;
     687PyTypeObject function_type_skel = {
     688    PyVarObject_HEAD_INIT(&PyType_Type, 0)
    686689    const_cast<char*>("Boost.Python.function"),
    687690    sizeof(function),
    688691    0,