2008-01-13 16:44:42 +01:00
/*
Unix SMB / CIFS implementation .
Python / Talloc glue
Copyright ( C ) Jelmer Vernooij < jelmer @ samba . org > 2008
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
2008-10-24 02:52:51 +02:00
# include <talloc.h>
# include "../lib/talloc/pytalloc.h"
2008-01-13 16:44:42 +01:00
void py_talloc_dealloc ( PyObject * self )
{
py_talloc_Object * obj = ( py_talloc_Object * ) self ;
2008-01-13 20:41:34 +01:00
talloc_free ( obj - > talloc_ctx ) ;
2008-05-23 15:09:51 +02:00
obj - > talloc_ctx = NULL ;
2008-01-13 16:44:42 +01:00
PyObject_Del ( self ) ;
}
2008-01-14 02:48:50 +01:00
PyObject * py_talloc_import_ex ( PyTypeObject * py_type , TALLOC_CTX * mem_ctx ,
2008-01-13 20:41:34 +01:00
void * ptr )
2008-01-13 16:44:42 +01:00
{
2008-01-14 02:48:50 +01:00
py_talloc_Object * ret = PyObject_New ( py_talloc_Object , py_type ) ;
2008-05-23 15:09:51 +02:00
ret - > talloc_ctx = talloc_new ( NULL ) ;
if ( ret - > talloc_ctx = = NULL ) {
return NULL ;
}
if ( talloc_reference ( ret - > talloc_ctx , mem_ctx ) = = NULL ) {
return NULL ;
}
2008-01-13 20:41:34 +01:00
ret - > ptr = ptr ;
2008-01-14 02:48:50 +01:00
return ( PyObject * ) ret ;
2008-01-13 16:44:42 +01:00
}
2008-01-13 18:38:12 +01:00
PyObject * py_talloc_default_repr ( PyObject * py_obj )
{
py_talloc_Object * obj = ( py_talloc_Object * ) py_obj ;
2008-04-15 12:51:31 +02:00
PyTypeObject * type = ( PyTypeObject * ) PyObject_Type ( ( PyObject * ) obj ) ;
2008-01-13 18:38:12 +01:00
2008-05-23 13:13:36 +02:00
return PyString_FromFormat ( " <%s talloc object at 0x%x> " , type - > tp_name , ( intptr_t ) py_obj ) ;
2008-01-13 18:38:12 +01:00
}