aboutsummaryrefslogtreecommitdiffstats
path: root/cppgenerator.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fixing includesLauro Neto2010-01-261-1/+1
| | | | Reviewed by Hugo Parent <hugo.lima@openbossa.org>
* Do not remove the "const" from "const char*" types when convertingHugo Lima2010-01-221-1/+2
| | | | | | | | python arguments to C++. This fixes bug #133 Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Adds support for Duck Punching (aka Monkey Patching).Marcelo Lira2010-01-211-0/+13
| | | | | | | | | | | | | | | | 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>
* Generator now supports overloads with both static and non-static methods.Marcelo Lira2010-01-191-14/+78
| | | | | | | | | | | | | | | | | When a class contains one or more overloads with static and non-static signatures Python must accept both usages, but for this to work some steps must be taken: * The overload method is defined with its own PyMethodDef structure, instead of being parte of an array of definitions. * The overload method is marked as static in the PyMethodDef. * This method definition is inserted in the PyMethodDef array for the class. * A tp_getattro function is generated and registered for the Python wrapper. It is used to intercept instance calls to methods with static versions to add the 'self' to the PyMethod. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Common variable names are stored as #defines instead of C++ static methods.Marcelo Lira2010-01-181-29/+29
| | | | Reviewed by Hugo Parente Lima <hugo.lima@openbossa.org>
* Generator now makes use of the GilState and ThreadStateSaver classes.Marcelo Lira2010-01-181-15/+12
| | | | | Generated code now makes use of the new convenience classes instead of directly using the Python provided PyGILState_STATE and PyThreadState.
* Adds CppGenerator::writeCppSelfDefinition method.Marcelo Lira2010-01-151-32/+26
| | | | | | | | | | The code to write the definition of cppSelf was in two places and contained an #ifdef clause, now it is a writer method. Also added the ShibokenGenerator::cppSelfVariableName() method to be used instead of directly writing the "cppSelf" string. Updated custom code on test binding to remove warning. Reviewed by Hugo Parente Lima <hugo.lima@openbossa.org>
* Wrapped virtual methods now locking the GIL in the right places.Marcelo Lira2010-01-151-12/+25
| | | | | | A code injection on the tests was updated. Reviewed by Hugo Parente Lima <hugo.lima@openbossa.org>
* Adds support for "allow-thread" type system tag on Python method wrappers.Marcelo Lira2010-01-151-17/+24
|
* Values returned from C++ are now stored in a C++ variable.Marcelo Lira2010-01-151-26/+19
| | | | | | | | | | | The previous behaviour was to pass the result, if any, straight to the to-Python-converter method. Separating the C++ from the Python part allows us to release the thread lock when calling C++ and taking it back before calling the converter filled with Python calls. Also renamed "retvalVariableName()" to the more meaninful name "pythonReturnVariableName()" and added "cppReturnVariableName()". Also updated the type system variable replacement to recognize "%0" as "cppReturnVariableName()".
* Inc. the reference of the return value when returning self on inplace ↵Hugo Lima2010-01-141-5/+6
| | | | | | operator overloads. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Changed prefix of local generated C functions to avoid name clash with ↵Hugo Lima2010-01-141-1/+1
| | | | | | bindinded method names. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Added a convenience overload for cpythonBaseName, with AbstractMetaClass as ↵Hugo Lima2010-01-141-5/+5
| | | | parameter.
* Implemented type discovery feature.Hugo Lima2010-01-141-6/+26
| | | | | | | | | | | | | | | 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.
* Fix transfer ownership on return values.Hugo Lima2010-01-131-7/+12
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Fix object initialization.Hugo Lima2010-01-131-46/+42
| | | | | | | 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>
* Try to decref py_result if an error happenned.Hugo Lima2009-12-301-2/+4
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Always use global method indexes in qt_metacalls instead of local indexes.Hugo Lima2009-12-301-2/+2
|
* Implemented support for classname on MetaObject.renato2009-12-301-4/+9
| | | | Reviewer: Hugo Lima <hugo.lima@openbossa.org>
* Modifies ShibokenGenerator::writeCodeSnips semantics.Marcelo Lira2009-12-281-7/+12
| | | | | | | A NULL pointer in the "lastArg" parameter of writeCodeSnips means that the function being processed will be called without arguments. The behavior prior to this change was that a NULL lastArg indicates that all arguments are to be used.
* Wrapper classes of QObjects store a pointer to their own meta object, a ↵Hugo Lima2009-12-281-7/+19
| | | | | | dynamic one. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Replaces SbkCopyCppObject template function with the CppObjectCopier ↵Marcelo Lira2009-12-221-4/+2
| | | | | | | | | | | | | | | 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>
* Improves TypeResolver code generation for the PySide extension.Marcelo Lira2009-12-211-8/+4
| | | | Reviewed by Hugo Parente <hugo.lima@openbossa.org>
* Adds support for added functions that receives varargs arguments.Marcelo Lira2009-12-181-11/+29
|
* Register object-types with * at end into TypeResolver.Hugo Lima2009-12-171-2/+6
|
* Add metaObject() method to every class derived from QObject whenHugo Lima2009-12-161-1/+22
| | | | the flag enable-pyside-extensions is on.
* Added the option --enable-pyside-extensions to enable PySide extensions.Hugo Lima2009-12-161-0/+9
| | | | | | | | | | You need to enable these extensions if you are generating a binding for a Qt-based library and need to pass some types through the signal slots mechanism. If you turn this flag on, you also need to link the generated bindings with the libpyside, besides add libpyside include path to your project. Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Updates generator to use improvements in API Extractor regarding function ↵Marcelo Lira2009-12-151-8/+10
| | | | modifications.
* All wrapped classes now inherit from the SbkBaseWrapper of the metatype ↵Marcelo Lira2009-12-141-28/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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-111-3/+3
| | | | with SbkBaseWrapper.
* Converter<T>::copyCppObject method was replaced by a template function.Marcelo Lira2009-12-101-17/+20
| | | | | | | | | | | | | | | | | 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>
* Added convenience method to get the file name for a module's global header.Marcelo Lira2009-12-081-2/+2
| | | | Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Implement support to slice operator.Luciano Wolf2009-12-081-2/+4
| | | | Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
* Improved rich comparison writer to use cpythonBaseName method.Marcelo Lira2009-12-081-3/+4
|
* Renamed a lot of Shiboken things with "Py" prefix to use "Sbk" prefix.Marcelo Lira2009-12-081-20/+20
| | | | | | | | | | | | | | 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.
* Added Shiboken_TypeCheck macro that makes use of PyType<T>().Marcelo Lira2009-12-071-16/+23
| | | | | | | | | | | 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-21/+0
| | | | | | | 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>
* Constructor initializes multiple inheritance information for Python derived ↵Marcelo Lira2009-12-051-7/+28
| | | | | | | | classes. The Python wrapper constructor for classes that have multiple inheritance now copies the needed information (mi_offsets, mi_init and mi_specialcast) from the nearest wrapped class parent in the inheritance hierarchy.
* Multiple inheritance works as desired for 99.9% of all known use cases!Hugo Lima2009-12-051-2/+24
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Fixed argument conversion writer and type translator to handle references to ↵Marcelo Lira2009-12-021-5/+7
| | | | object-types.
* Modified the BindingManager::getOverride method to use Python __mro__.Marcelo Lira2009-12-021-2/+2
| | | | | | | | | 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>
* Try to guess the check function for custom types.Hugo Lima2009-12-011-1/+1
|
* Do not try to write the C++ version of an argument when the argument type is aHugo Lima2009-12-011-0/+3
| | | | custom type.
* Fixed inverted parentship semantics.Marcelo Lira2009-12-011-12/+14
| | | | | | | The parentship was expressed inverted in the type system and was working because the generator implementation was also screwed. Reviewed by Hugo Lima <hugo.lima@openbossa.org>
* Type check writer now adds isConvertible check to object-types and ↵Marcelo Lira2009-12-011-3/+6
| | | | value-type pointers.
* Fix issues with parent tag.Hugo Lima2009-11-301-4/+6
| | | | Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
* Support parent rules for return values.Hugo Lima2009-11-301-2/+4
|
* Add the generator flag "enable-parent-ctor-heuristic".Hugo Lima2009-11-301-3/+18
| | | | | When enabled, this heuristic will check every constructor for an argument named "parent", if the argument is a pointer, then it'll be the parent of this object.
* Added method to take care of the details of ownership transfer to C++.Marcelo Lira2009-11-301-16/+7
| | | | | | | | | | | | | | | | | | | 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>
* Fix identation of generated code for C++ wrapper destructor.Marcelo Lira2009-11-271-0/+1
| | | | Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>