[pygccxml-commit] SF.net SVN: pygccxml:[1792] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
|
From: <rom...@us...> - 2009-12-28 21:23:16
|
Revision: 1792
http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1792&view=rev
Author: roman_yakovenko
Date: 2009-12-28 21:23:02 +0000 (Mon, 28 Dec 2009)
Log Message:
-----------
add ability to generate the user code in a module head/tail
Modified Paths:
--------------
pyplusplus_dev/pyplusplus/module_builder/boost_python_builder.py
pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py
pyplusplus_dev/unittests/ctypes_tester.py
pyplusplus_dev/unittests/sconstruct
Added Paths:
-----------
pyplusplus_dev/unittests/data/ctypes/user_code/
pyplusplus_dev/unittests/data/ctypes/user_code/sconscript
pyplusplus_dev/unittests/data/ctypes/user_code/user_code.cpp
pyplusplus_dev/unittests/data/ctypes/user_code/user_code.h
Modified: pyplusplus_dev/pyplusplus/module_builder/boost_python_builder.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_builder/boost_python_builder.py 2009-12-28 21:17:07 UTC (rev 1791)
+++ pyplusplus_dev/pyplusplus/module_builder/boost_python_builder.py 2009-12-28 21:23:02 UTC (rev 1792)
@@ -190,22 +190,22 @@
@property
def declarations_code_head( self ):
- "List of user code, that will be added to the head of the declarations section."
+ "A list of the user code, which will be added to the head of the declarations section."
return self.__declarations_code_head
@property
def declarations_code_tail( self ):
- "List of user code, that will be added to the tail of the declarations section."
+ "A list of the user code, which will be added to the tail of the declarations section."
return self.__declarations_code_tail
@property
def registrations_code_head( self ):
- "List of user code, that will be added to the head of the registrations section."
+ "A list of the user code, which will be added to the head of the registrations section."
return self.__registrations_code_head
@property
def registrations_code_tail( self ):
- "List of user code, that will be added to the tail of the registrations section."
+ "A list of the user code, which will be added to the tail of the registrations section."
return self.__registrations_code_tail
def build_code_creator( self
@@ -259,12 +259,14 @@
return not ( None is self.__code_creator )
def add_declaration_code( self, code, tail=True ):
+ """adds the user code to the generated one"""
if tail:
self.__declarations_code_tail.append( code )
else:
self.__declarations_code_head.append( code )
def add_registration_code( self, code, tail=True ):
+ """adds the user code to the generated one"""
if tail:
self.__registrations_code_tail.append( code )
else:
Modified: pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py
===================================================================
--- pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2009-12-28 21:17:07 UTC (rev 1791)
+++ pyplusplus_dev/pyplusplus/module_builder/ctypes_builder.py 2009-12-28 21:23:02 UTC (rev 1792)
@@ -49,6 +49,9 @@
self.__treat_char_ptr_as_binary_data = None
+ self.__module_code_head = []
+ self.__module_code_tail = []
+
def __parse_declarations( self, files, gccxml_config, compilation_mode=None, cache=None ):
if None is gccxml_config:
gccxml_config = parser.config_t()
@@ -94,6 +97,23 @@
treat_char_ptr_as_binary_data = property( __get_treat_char_ptr_as_binary_data, __set_treat_char_ptr_as_binary_data,
doc="""If True, Py++ will generate "POINTER( char )", instead of "c_char_p" for "char*" type. By default it is False""" )
+ @property
+ def module_code_head( self ):
+ "A list of the user code, which will be added to the top of the module"
+ return self.__module_code_head
+
+ @property
+ def module_code_tail( self ):
+ "A list of the user code, which will be added to the bottom of the module"
+ return self.__module_code_tail
+
+ def add_module_code( self, code, tail=True ):
+ """adds the user code to the generated one"""
+ if tail:
+ self.__module_code_tail.append( code )
+ else:
+ self.__module_code_head.append( code )
+
def build_code_creator( self, library_path, doc_extractor=None ):
creator = creators_factory.ctypes_creator_t( self.global_ns
, library_path
@@ -117,6 +137,13 @@
"""
return not ( None is self.__code_creator )
+ def __merge_user_code( self ):
+ for code in self.module_code_tail:
+ self.code_creator.adopt_creator( code_creators.custom_text_t( code ) )
+
+ for code in self.module_code_head:
+ self.code_creator.adopt_creator( code_creators.custom_text_t( code ), 0 )
+
def write_module( self, file_name ):
"""
Writes module to single file
@@ -125,6 +152,7 @@
:type file_name: string
"""
+ self.__merge_user_code()
file_writers.write_file( self.code_creator, file_name, encoding=self.encoding )
Modified: pyplusplus_dev/unittests/ctypes_tester.py
===================================================================
--- pyplusplus_dev/unittests/ctypes_tester.py 2009-12-28 21:17:07 UTC (rev 1791)
+++ pyplusplus_dev/unittests/ctypes_tester.py 2009-12-28 21:23:02 UTC (rev 1792)
@@ -229,6 +229,28 @@
self.failUnless( data.contents.size == len( "hello world" ) )
self.failUnless( data.contents.bytes[0:data.contents.size + 1] == "hello\0world\0" )
+class user_code_tester_t( ctypes_base_tester_t ):
+ def __init__( self, *args, **keywd ):
+ ctypes_base_tester_t.__init__( self, 'user_code', *args, **keywd )
+ self.module_top_code = "top = 'top'"
+ self.module_bottom_code = "bottom = 'bottom'"
+
+ def customize(self, mb ):
+ mb.add_module_code( self.module_top_code, tail=False )
+ mb.add_module_code( self.module_bottom_code, tail=True )
+
+ def test(self):
+ self.failUnless( self.module_ref.top == "top" )
+ self.failUnless( self.module_ref.bottom == "bottom" )
+ content = []
+ for line in file( self.module_ref.__file__ ):
+ if line.lstrip().startswith( '#' ) or not line.strip():
+ continue
+ else:
+ content.append( line.rstrip() )
+ self.failUnless( content[0] == self.module_top_code )
+ self.failUnless( content[-1] == self.module_bottom_code )
+
def create_suite():
#part of this functionality is going to be deprecated
suite = unittest.TestSuite()
@@ -241,6 +263,7 @@
suite.addTest( unittest.makeSuite(circular_references_tester_t))
suite.addTest( unittest.makeSuite(function_ptr_as_variable_tester_t))
suite.addTest( unittest.makeSuite(char_ptr_as_binary_data_tester_t))
+ suite.addTest( unittest.makeSuite(user_code_tester_t))
return suite
def run_suite():
Added: pyplusplus_dev/unittests/data/ctypes/user_code/sconscript
===================================================================
--- pyplusplus_dev/unittests/data/ctypes/user_code/sconscript (rev 0)
+++ pyplusplus_dev/unittests/data/ctypes/user_code/sconscript 2009-12-28 21:23:02 UTC (rev 1792)
@@ -0,0 +1,7 @@
+Import('*')
+
+target_name = 'user_code'
+shlib = env.SharedLibrary( target=target_name
+ , source=[ target_name + '.cpp' ]
+ , CPPPATH=['#data'] )
+env.Alias( target_name, shlib )
Added: pyplusplus_dev/unittests/data/ctypes/user_code/user_code.cpp
===================================================================
--- pyplusplus_dev/unittests/data/ctypes/user_code/user_code.cpp (rev 0)
+++ pyplusplus_dev/unittests/data/ctypes/user_code/user_code.cpp 2009-12-28 21:23:02 UTC (rev 1792)
@@ -0,0 +1,5 @@
+#include "user_code.h"
+
+EXPORT_SYMBOL void init(){
+}
+
Added: pyplusplus_dev/unittests/data/ctypes/user_code/user_code.h
===================================================================
--- pyplusplus_dev/unittests/data/ctypes/user_code/user_code.h (rev 0)
+++ pyplusplus_dev/unittests/data/ctypes/user_code/user_code.h 2009-12-28 21:23:02 UTC (rev 1792)
@@ -0,0 +1,11 @@
+#include "libconfig.h"
+
+struct EXPORT_SYMBOL data_t{
+ int i;
+ unsigned int j : 3;
+};
+
+EXPORT_SYMBOL int j;
+
+EXPORT_SYMBOL void init();
+
Modified: pyplusplus_dev/unittests/sconstruct
===================================================================
--- pyplusplus_dev/unittests/sconstruct 2009-12-28 21:17:07 UTC (rev 1791)
+++ pyplusplus_dev/unittests/sconstruct 2009-12-28 21:23:02 UTC (rev 1792)
@@ -33,7 +33,8 @@
, 'varargs'
, 'templates'
, 'circular_references'
- , 'function_ptr_as_variable'
+ , 'function_ptr_as_variable'
+ , 'user_code'
, 'char_ptr_as_binary_data' ]
for s in scripts:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|