aboutsummaryrefslogtreecommitdiffstats
path: root/libshiboken
Commit message (Collapse)AuthorAgeFilesLines
* Add overflow check to unsigned int, because we need it on 64bit platforms.Hugo Lima2010-01-221-21/+10
|
* Fix bug on overflow check routines under 32 bits platforms.Hugo Lima2010-01-221-33/+50
|
* Adds support for Duck Punching (aka Monkey Patching).Marcelo Lira2010-01-213-6/+40
| | | | | | | | | | | | | | | | The simplest definition of duck punching for our purposes is the ability to change the definition of a method in an instance of a class. To allow this behaviour the SbkBaseWrapper structure had to be extended with a 'ob_dict' which is a PyObject pointer to the instance dictionary. It is originally set to NULL until the user tries to access it. This dictionary could be accessed through the '__dict__' instance property. For now it is read-only. The generator was updated to handle the instance dictionary, and an extensive duck punching test was also added. Reviewed by Hugo Parente Lima <hugo.lima@openbossa.org>
* Add special conversion rules to the char type.Hugo Lima2010-01-201-3/+28
| | | | | | A type is convertible to char if it is a number or a 1-sized char. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Converter<PyInt> now follows the Converter interface.Hugo Lima2010-01-201-2/+2
| | | | | - Converter<PyInt>::isConvertible should return bool instead of int and - Converter<PyInt>::toPython must receive "const PyInt&" instead of just "PyInt".
* Adds convenience ThreadStateSaver class to libshiboken.Marcelo Lira2010-01-182-0/+64
| | | | | | | ThreadStateSaver class just wraps the Python Thread save and restore operations. Its destructor also ensures the restoration of saved thread state if the method ends abruptly, e.g. when the wrapped C++ library throws an exception.
* Adds convenience GilState class to libshiboken.Marcelo Lira2010-01-182-0/+56
| | | | | | GilState class puts some sugar over the Python GIL usage and also adds the safety of a final GIL release when the GilState destructor is called when get out of scope.
* libshiboken initialises Python threads if available.Marcelo Lira2010-01-151-0/+4
|
* Added SbkDbg stream class, used to print debug messages.Hugo Lima2010-01-143-5/+107
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Added template specialization SbkType<signed char>(), needed by someone.Hugo Lima2010-01-141-0/+1
|
* Implemented type discovery feature.Hugo Lima2010-01-146-7/+264
| | | | | | | | | | | | | | | The problem: - There are two class, A and B, B inherits from A. - You are inside a virtual method reimplemented in python with just one parameter of type A*. - But the object referenced by a variable of type A* is an instance of B and it was created by C++, not Python! - Shiboken needs to create a PyObject of type B, not A! This does not makes sense for C++, but does for Python, because python variables does not store type information, just values. To achieve this we use RTTI to get the real type name of a variable, then we create the PyObject using the TypeResolver infrastructure initially developed to help with signal slot problems. In other words, the TypeResolver class has been moved from libpyside to libshiboken.
* Removed warninig: missing braces around initializer for 'PyTypeObject' from ↵Hugo Lima2010-01-141-1/+5
| | | | basewrapper.cpp
* Fix transfer ownership on return values.Hugo Lima2010-01-131-0/+1
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Fix object initialization.Hugo Lima2010-01-134-30/+45
| | | | | | | The C++ object instanciation was made in tp_init function instead of tp_new function. Now tp_new just create a useless python object which will be filled in the tp_init function. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Added Shiboken::makeTuple inline method to help with constructions of Python ↵Hugo Lima2010-01-081-0/+20
| | | | | | | | tuples from C++ objects. Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
* Add -> operator to AutoDecRef class.Hugo Lima2009-12-301-0/+1
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Replaces SbkCopyCppObject template function with the CppObjectCopier ↵Marcelo Lira2009-12-221-113/+46
| | | | | | | | | | | | | | | template struct In addition to the mere use of SbkCopyCppObject to copy C++ objects, it is needed to know if a C++ type has a C++ wrapped produced by the generator. To solve this SbkCopyCppObject was transformed in the template struct CppObjectCopier with the methods copy and the constant member isCppWrapper. The Converter[Base]<>::createWrapper methods were replaced by template function SbkCreateWrapper. Also some refactoring was made on the Converters code to improve legibility. Reviewed by Hugo Parente <hugo.lima@openbossa.org>
* Changed SbkBaseWrapper_New signature to use "bool" instead of "unsigned int" ↵Marcelo Lira2009-12-222-5/+5
| | | | in some parameters.
* Improvements and refactor on libshiboken's converters.Marcelo Lira2009-12-211-41/+87
| | | | | | | Short methods in Converter and ConverterBase variations received the "inline" keyword. A convenience "toPython" signature receiving "void*" as parameter was also added to the converter classes.
* Refactored SbkType specializations and replaced "long long" by "PY_LONG_LONG".Marcelo Lira2009-12-211-78/+13
|
* Disabled AutoDecRef obj. copy. and added some useful cast operators.Hugo Lima2009-12-211-1/+6
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Adds AutoDecRef class that holds a PyObject pointer and decrefs it when get ↵Marcelo Lira2009-12-182-2/+72
| | | | out of scope.
* Added template specializations for SbkType<T> when T is a primitive type.Hugo Lima2009-12-161-5/+81
|
* Tests for numerical implicit conversions and fixesLauro Neto2009-12-161-9/+36
| | | | | | | | | | | | Added a test for simple implicit numerical conversions involving doubles, signed and unsigned ints and longs. Some fixes to the converters were also made, mostly related to adding manual checks for boundaries with doubles for negative values Also put the overflow check in a single template Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
* All wrapped classes now inherit from the SbkBaseWrapper of the metatype ↵Marcelo Lira2009-12-143-22/+156
| | | | | | | | | | | | | | | | | | | | | | | | | | | SbkBaseWrapperType. The wrapped classes are described with a SbkBaseWrapperType structure which extends the PyTypeObject with information about multiple inheritance and parenting ownership. This works well for the classes produced by the generator but inheriting classes written in Python continues using the PyTypeObject to describe themselves. To fix this the SbkBaseWrapperType is now a metatype for all the wrapped classes and anyone inheriting from them. In addition all the wrapped classes now inherit from SbkBaseWrapper, since Python's PyType_Ready method need that multiple inheriting classes have a common base class with the same size of the classes involved in the multiple inheritance, which disqualifies Python's base "object" class. The metatype and the base wrapper type are initialized by calling the new Shiboken::init_shiboken() function. This is done by all the imported binding modules, but it is really run only in the first call. Another noteworthy change is the replacement of PyTypeObject as a basis for SbkBaseWrapperType by the PyHeapTypeObject, since the latter is the proper choice for types created on the heap, e.g. user defined classes extending the generated wrapper classes. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Renamed ShiboTypeObject to SbkBaseWrapperType to clearify its relationship ↵Marcelo Lira2009-12-114-8/+8
| | | | with SbkBaseWrapper.
* Converter<T>::copyCppObject method was replaced by a template function.Marcelo Lira2009-12-101-8/+25
| | | | | | | | | | | | | | | | | Added the template function T* SbkCopyCppObject(const T& cppobj); whose task is simply to copy a C++ object. If the binding has a C++ class wrapper for it, the function is specialized to use the copy constructor of the C++ wrapper class. This replaces the Converter<T>::copyCppObject method. Also moved implementation of Converter<T>::toPython from the generator to ConverterBase<T> in the conversions header, for it makes use of the SbkCopyCppObject. Reviewed by Lauro Neto <lauro.neto@openbossa.org>
* Renamed a lot of Shiboken things with "Py" prefix to use "Sbk" prefix.Marcelo Lira2009-12-087-83/+85
| | | | | | | | | | | | | | To avoid confusion of Python stuff with Shiboken generated stuff. For example: a C++ class called "String" would have the PyString_Type wrapper generated for it, mixing with the proper Python PyString_Type; now the generate code will have things like SbkString_Type, SbkString_New, SbkString_someMethod, and so on. PyBaseWrapper and its variants were renamed to SbkBaseWrapper. PyType<T>() is now SbkType<T>() PyEnumObject was renamed to SbkEnumObject.
* Moved container converters from test library to libshiboken's converter header.Marcelo Lira2009-12-071-0/+117
| | | | | | | The implementation of converters for pair, list and map containers was moved from libsample test binding to libshiboken/conversions.h. The implementation must be used with types similar to the C++ STL containers of the same name.
* Added Shiboken_TypeCheck macro that makes use of PyType<T>().Marcelo Lira2009-12-072-3/+9
| | | | | | | | | | | The Shiboken_TypeCheck calls Python's PyObject_TypeCheck using the type pointer stored in PyType<T> for the type being checked. Conversion<T*>::toCpp(pyobj) converter tries first to convert pyobj to the Python wrapper for type T and only second to any of the convertible types. If pyobj is neither of those, 0 is returned as the C++ object. This works fine for Py_None and invalid values are not expected to be passed because the generated code checked the types first.
* Do not generate the method Converter<T>::createWrapper, it'll beHugo Lima2009-12-071-17/+22
| | | | | | | auto generated by the compiler using the function PyType<T> to get PyTypeObject of a type T. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Adds Overflow check to integer types conversions.Marcelo Lira2009-12-071-3/+9
| | | | | | Unit tests were added also. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Correct install location for FindShiboken.cmakeChris Hills2009-12-071-1/+1
| | | | Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Multiple inheritance works as desired for 99.9% of all known use cases!Hugo Lima2009-12-052-0/+24
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Modified the BindingManager::getOverride method to use Python __mro__.Marcelo Lira2009-12-023-19/+21
| | | | | | | | | Using the CLASS->tp_mro, which contains the list of method resolution for a Python class, to find an override for a wrapped C++ virtual method is more correct than relying in the ShiboTypeObject's baseWrapperType value. Also baseWrapperType was removed from ShiboTypeObject structure. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Converter's basic isConvertible and toCpp methods consider None as C++ NULL ↵Marcelo Lira2009-12-011-2/+6
| | | | pointer.
* Shiboken::cppObjectIsInvalid now accepts None values as valid.Marcelo Lira2009-12-011-1/+1
|
* Added method to take care of the details of ownership transfer to C++.Marcelo Lira2009-11-302-0/+19
| | | | | | | | | | | | | | | | | | | Simple ownership transference, i.e. without parenting, is now performed by the new BindingManager::transferOwnershipToCpp method. It remove the parent of the transfered object and proceeds transfer or invalidation if needed. The generated code for simple ownership transfer from Python to C++ now reflects this change. Fixed the method BlackBox::keepObjectType that steals an ObjectType ownership to C++ to remove it from its parent also. The BlackBox class does not take care of the stolen object as a proper parent would, but its destructor deletes the object, so the "unparenting" is needed to avoid freeing the same memory twice. Created an unit test that adds children to a parent ObjectType and then steal the children to C++ with BlackBox.keepObjectType. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Wrapper invalidation method recursively updates children objects status.Marcelo Lira2009-11-303-8/+27
| | | | | | | | | | | BindingManager::invalidateWrapper checks if the object to be invalidated carries any children objects and recursively invalidates them. Shiboken::destroyParentInfo function was refactored to call the new recursive wrapper invalidator and then call a helper function that only destroy the parent information. The invalidate parent test was updated.
* Implemented primitives to solve the parent/children problem.Hugo Lima2009-11-272-30/+135
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Added convenience method BindingManager::invalidateWrapper(const void*).Marcelo Lira2009-11-262-0/+9
| | | | | | | | This new invalidateWrapper finds the Python wrapper for a C++ pointer and then invalidates it. Virtual destructors for C++ wrappers call the invalidateWrapper on the "this" pointer.
* Added the "containsCppWrapper" flag to the PyBaseWrapper.Marcelo Lira2009-11-262-4/+22
| | | | | | | | | | | | | | The containsCppWrapper flag says if the C++ pointer held by the Python wrapper has a binding generated C++ wrapper and was created by Python. This means that the C++ object has a virtual destructor that will invalidate the Python wrapper if it is destroyed when its ownership is with C++. PyBaseWrapper_New function was expanded with the "containsCppWrapper" parameter, and CppGenerator::writeConstructorWrapper was updated to use it. The PyBaseWrapper structure was documented with comments.
* BindingManager::invalidateWrapper also removes ownership of the object from ↵Marcelo Lira2009-11-261-0/+1
| | | | Python.
* Renamed Shiboken's function cppObjectIsValid to cppObjectIsInvalid.Marcelo Lira2009-11-262-8/+13
| | | | | | CppGenerator::writeInvalidCppObjectCheck receives the name of the PyObject to be checked and do not set the exception message anymore, since it is done by Shiboken::cppObjectIsInvalid.
* Added the invalidateWrapper method to BindingManager.Marcelo Lira2009-11-253-13/+23
| | | | | | | | | | | | It sets the wrapper as invalid and removes the relation of C++ objects to the Python wrapper from the mappings. Moved BindingManager::releaseWrapper(void*) to BindingManagerPrivate, since it should only be used by releaseWrapper(PyObject*). Modified includes on conversions.h to use quotes instead of < and >. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Merged with multipleinheritance branchMarcelo Lira2009-11-253-12/+41
|\
| * Binding manager releaseWrapper(PyObject*) method fixed to releaseMarcelo Lira2009-11-181-1/+10
| | | | | | | | | | the multiple inheritance pointers registered for a class with this trait.
| * In multiple inheritance cases the binding manager only assigns aMarcelo Lira2009-11-181-1/+2
| | | | | | | | | | wrapper to a base pointer plus offset if the latter is greater than 0 to avoid duplicated associations with the base pointer.
| * Shiboken retrieves a Python wrapper object from its correspondingMarcelo Lira2009-11-183-11/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | C++ object using the memory address of the former to retrieve the latter. When multiple inheritance is involved, a C++ object passed to C++ could be caught back downcasted to one of its parents with a different memory address, following the memory layout for multiple inheritance used by the compiler. This poses a problem to keep the Python identity of a C++ object. The solution was to extend the traditional PyTypeObject with a number array with all the possible displacements to be added to an object pointer to produce the memory addresses for the valid pointers that could appear from all the possible type casts involving the object parents. All the possible pointers are registered (and unregistered) by the binding wrapper manager. To store the multiple inheritance information the ShiboTypeObject structure was created, expanding the original PyTypeObject with two fields: mi_offsets an integer array containing the possible displacements from the object base pointer. The array has the value -1 at its end. mi_init the function that will initialize the mi_offsets array it is called at the first instaciation of a multiple inheriting object.
* | Added an PyObject* specialization to the Conversion template toMarcelo Lira2009-11-241-0/+8
| | | | | | | | | | | | | | avoid problems when converting PyObjects to C++. Tests where also added for this. Reviewed by Lauro Neto <lauro.neto@openbossa.org>