Changeset 64

Show
Ignore:
Timestamp:
12/18/06 06:00:22 (2 years ago)
Author:
KirkMcDonald
Message:

PydMain?; build improvements (no more colliding object files); examples and docs updated to use PydMain?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dcompiler.py

    r63 r64  
    142142 
    143143        includePathOpts = [] 
    144          
     144 
     145        # All object files will be placed in one of three directories: 
     146        # infra   - All of the infrastructure's object files. 
     147        # project - The project's own object files. 
     148        # outside - Any source files specified by the project which are not 
     149        #           contained in the project's own directory. 
     150        orig_sources = sources 
     151        sources = [] 
     152        for source in orig_sources: 
     153            if os.path.abspath(source).startswith(os.getcwd()): 
     154                sources.append((source, 'project')) 
     155            else: 
     156                sources.append((source, 'outside')) 
     157 
    145158        # To sources, add the appropriate D header file python.d, as well as 
    146159        # any platform-specific boilerplate. 
     
    153166                ' header files "%s" is missing.' % pythonHeaderPath 
    154167            ) 
    155         sources.append(pythonHeaderPath
    156  
    157         # flags = (with_pyd, with_st, with_meta
    158         flags = [f for f, category in macros if category == 'aux'][0] 
     168        sources.append((pythonHeaderPath, 'infra')
     169 
     170        # flags = (with_pyd, with_st, with_meta, with_main
     171        with_pyd, with_st, with_meta, with_main = [f for f, category in macros if category == 'aux'][0] 
    159172        # And Pyd! 
    160         if flags[0]
     173        if with_pyd
    161174            # If we're not using StackThreads, don't use iteration.d in Pyd 
    162             if not flags[1] or not self._st_support: 
     175            if not with_st or not self._st_support: 
    163176                _pydFiles.remove('iteration.d'); 
    164177            for file in _pydFiles: 
     
    168181                        " missing." % filePath 
    169182                    ) 
    170                 sources.append(filePath) 
     183                sources.append((filePath, 'infra')) 
     184        # If using PydMain, parse the template file 
     185        if with_main: 
     186            name = [n for n, category in macros if category == 'name'][0] 
     187            mainTemplatePath = os.path.join(_infraDir, 'd', 'pydmain_template.d') 
     188            if not os.path.isfile(mainTemplatePath): 
     189                raise DistutilsPlatformError( 
     190                    "Required supporting code file %s is missing." % mainTemplatePath 
     191                ) 
     192            mainTemplate = open(mainTemplatePath).read() 
     193            mainFileContent = mainTemplate % {'modulename' : name} 
     194            # Store the finished pydmain.d file alongside the object files 
     195            infra_output_dir = os.path.join(output_dir, 'infra') 
     196            if not os.path.exists(infra_output_dir): 
     197                os.path.makedirs(infra_output_dir) 
     198            mainFilename = os.path.join(infra_output_dir, 'pydmain.d') 
     199            mainFile = open(mainFilename, 'w') 
     200            mainFile.write(mainFileContent) 
     201            mainFile.close() 
     202            sources.append((mainFilename, 'infra')) 
    171203        # And StackThreads 
    172         if self._st_support and flags[1]
     204        if self._st_support and with_st
    173205            for file in _stFiles: 
    174206                filePath = os.path.join(_infraDir, 'st', file) 
     
    177209                        " file '%s' is missing." % filePath 
    178210                    ) 
    179                 sources.append(filePath
     211                sources.append((filePath, 'infra')
    180212            # Add the version conditional for st 
    181213            macros.append(('Pyd_with_StackThreads', 'version')) 
    182214        # And meta 
    183         if flags[2]
     215        if with_meta
    184216            for file in _metaFiles: 
    185217                filePath = os.path.join(_infraDir, 'meta', file) 
     
    188220                        " '%s' is missing." % filePath 
    189221                    ) 
    190                 sources.append(filePath
     222                sources.append((filePath, 'infra')
    191223        # Add the infraDir to the include path for pyd, st, and meta. 
    192         if True in flags
     224        if True in (with_pyd, with_st, with_meta)
    193225            includePathOpts += self._includeOpts 
    194226            includePathOpts[-1] = includePathOpts[-1] % os.path.join(_infraDir) 
     
    207239                ' is missing.' % boilerplatePath 
    208240            ) 
    209         sources.append(boilerplatePath
     241        sources.append((boilerplatePath, 'infra')
    210242 
    211243        # Extension subclass DExtension will have packed any user-supplied 
     
    239271            optimizationOpts = self._defaultOptimizeOpts 
    240272 
    241         print 'sources: ', [os.path.basename(s) for s in sources] 
    242         # Compiling one-by-one exhibits a strange bug in the D front-end, while 
    243         # compiling all at once works. This flags allows me to test each form 
    244         # easily. Supporting the one-by-one form is synonymous with GDC support. 
    245         ONE_BY_ONE = True 
    246         if ONE_BY_ONE: 
    247             for source in sources: 
    248                 outOpts = outputOpts[:] 
    249                 objName = self.object_filenames([os.path.split(source)[1]], 0, output_dir)[0] 
    250                 outOpts[-1] = outOpts[-1] % _qp(objName) 
    251                 cmdElements = ( 
    252                     [binpath] + extra_preargs + compileOpts + 
    253                     [pythonVersionOpt, self._unicodeOpt] + optimizationOpts + 
    254                     includePathOpts + outOpts + userVersionAndDebugOpts + 
    255                     [_qp(source)] + extra_postargs 
    256                 ) 
    257                 cmdElements = [el for el in cmdElements if el] 
    258                 try: 
    259                     self.spawn(cmdElements) 
    260                 except DistutilsExecError, msg: 
    261                     raise CompileError(msg) 
    262         else: 
    263             # gdc/gcc doesn't support the idea of an output directory, so we 
    264             # compile from the destination 
    265             sources = [_qp(os.path.abspath(s)) for s in sources] 
    266             cwd = os.getcwd() 
    267             os.chdir(output_dir) 
     273        print 'sources: ', [os.path.basename(s) for s, t in sources] 
     274 
     275        objFiles = [] 
     276        for source, source_type in sources: 
     277            outOpts = outputOpts[:] 
     278            objFilename = os.path.splitext(source)[0] + self.obj_extension 
     279            if source_type == 'project': 
     280                objName = os.path.join(output_dir, 'project', objFilename) 
     281            elif source_type == 'outside': 
     282                objName = os.path.join(output_dir, 'outside', os.path.basename(objFilename)) 
     283            else: # infra 
     284                objName = os.path.join(output_dir, 'infra', os.path.basename(objFilename)) 
     285            if not os.path.exists(os.path.dirname(objName)): 
     286                os.makedirs(os.path.dirname(objName)) 
     287            objFiles.append(objName) 
     288            outOpts[-1] = outOpts[-1] % _qp(objName) 
    268289            cmdElements = ( 
    269290                [binpath] + extra_preargs + compileOpts + 
    270291                [pythonVersionOpt, self._unicodeOpt] + optimizationOpts + 
    271                 includePathOpts + userVersionAndDebugOpts + 
    272                 sources + extra_postargs 
     292                includePathOpts + outOpts + userVersionAndDebugOpts + 
     293                [_qp(source)] + extra_postargs 
    273294            ) 
    274295            cmdElements = [el for el in cmdElements if el] 
    275      
    276296            try: 
    277297                self.spawn(cmdElements) 
    278298            except DistutilsExecError, msg: 
    279                 #os.chdir(cwd) 
    280299                raise CompileError(msg) 
    281             os.chdir(cwd) 
    282  
    283         return [os.path.join(output_dir, fn) for fn in os.listdir(output_dir) if fn.endswith(self.obj_extension)] 
     300        return objFiles 
    284301 
    285302    def link (self, 
     
    432449 
    433450            defFileContents = defTemplate % os.path.basename(output_filename) 
    434             defFilePath = os.path.join(output_dir, 'python_dll_def.def') 
     451            defFilePath = os.path.join(output_dir, 'infra', 'python_dll_def.def') 
    435452            f = file(defFilePath, 'wb') 
    436453            try: 
  • trunk/examples/hello/hello.d

    r46 r64  
    99} 
    1010 
    11 extern(C) 
    12 export void inithello() { 
     11extern(C) void PydMain() { 
    1312    def!(hello); 
    14     module_init("hello"); 
     13    module_init(); 
    1514} 
  • trunk/examples/inherit/inherit.d

    r57 r64  
    3131} 
    3232 
    33 extern(C) 
    34 export void initinherit() { 
     33extern(C) void PydMain() { 
    3534    def!(call_poly); 
    3635 
    37     module_init("inherit"); 
     36    module_init(); 
    3837 
    3938    wrapped_class!(Base) b; 
  • trunk/examples/testdll/testdll.d

    r57 r64  
    128128} 
    129129 
    130 extern (C) 
    131 export void inittestdll() { 
     130//extern (C) 
     131//export void inittestdll() { 
     132extern(C) void PydMain() { 
    132133    def!(foo); 
    133134    // Python does not support function overloading. This allows us to wrap 
     
    145146    def!(throws); 
    146147 
    147     module_init("testdll"); 
     148    module_init(); 
    148149 
    149150    wrapped_class!(Foo) f; 
  • trunk/html_doc/basics.html

    r59 r64  
    3434<pre class="code"><span class="keyword">import</span> pyd.pyd; 
    3535 
    36 <span class="keyword">extern</span> (C) 
    37 <span class="keyword">export void</span> inittestmodule() { 
    38     module_init(<span class="string">"testmodule"</span>); 
     36<span class="keyword">extern</span> (C) <span class="keyword">void</span> PydMain() { 
     37    module_init(); 
    3938}</pre> 
    4039 
     
    4544<p>The <code>pyd</code> module in the <code>pyd</code> package publicly imports all of the other components of Pyd.</p> 
    4645 
    47 <p>The "init" function is a requirement of the Python/C API. It is a global function with the footprint <code>extern(C) export void function()</code>. Its name <em>must</em> be <code>init</code> plus the name of your module. This function must then contain a call to <code>module_init</code>, with the same module name as an argument. (Users of Boost.Python will be familiar with the <code>BOOST_PYTHON_MODULE</code> macro used in that library. Unfortunately for this purpose, D has no preprocessor, and cannot define the name of a function like the C preprocessor can. Therefore, users of Pyd must define their init functions manually.)</p> 
     46<p>The <code>PydMain</code> function is called when the module is imported by Python. You will call most of Pyd's API from here. At the very least, <code>PydMain</code> <em>must</em> contain a call to <code>module_init</code>. The <code>module_init</code> function has the following form:</p> 
    4847 
    49 <p>The <code>module_init</code> function has the following form:</p> 
    50  
    51 <p><code>PyObject* module_init(char[] <span class="arg">name</span>, char[] <span class="arg">docstring</span>="");</code></p> 
     48<p><code>PyObject* module_init(char[] <span class="arg">docstring</span>="");</code></p> 
    5249 
    5350<p>It does little more than call <a href="http://docs.python.org/api/allocating-objects.html">Py_InitModule</a> and return the new module object. This object is also available via the <code>Pyd_Module_p</code> property once you've called <code>module_init</code>.</p> 
    5451 
    55 <p>Due to the way in which Pyd implements function and class wrapping, any calls to <code>def</code> must occur <em>before</em> the call to <code>module_init</code>, and any calls to <code>finalize_class</code> must occur <em>after</em> the call. I know this seems like a rather arbitrary rule, but it is important. Calls to <code>def</code> in the wrong place will simply be ignored, and calls to <code>finalize_class</code> in the wrong place will throw an assert. (And this assert will cause the Python interpreter to crash. So be warned.)</p> 
     52<p>Due to the way in which Pyd implements function and class wrapping, any calls to <code>def</code> must occur <em>before</em> the call to <code>module_init</code>, and any calls to <code>finalize_class</code> must occur <em>after</em> the call. I know this seems like a rather arbitrary rule, but it is important. Calls to <code>def</code> in the wrong place will simply be ignored, and calls to <code>finalize_class</code> in the wrong place will throw an assert.</p> 
    5653 
    57 <p>It is important that no D exceptions escape from the init function. If you put any of your own code in the init function, be sure to guard it aginst exceptions. The <a href="except_wrapping.html">exception wrapping</a> facilities of Pyd provide some useful functions for this purpose.</p> 
     54<p><code>PydMain</code> will catch any D exception that is thrown from inside it, and <a href="except_wrapping.html">safely pass that exception to Python</a>.</p> 
    5855</div> 
    5956 
  • trunk/html_doc/celerid.html

    r63 r64  
    5555    <dt><code>version_flags</code></dt> <dd>This should be a list of strings, which will be passed to the D compiler as version flags.</dd> 
    5656    <dt><code>debug_flags</code></dt> <dd>Similar to <code>version_flags</code>, the strings in this list will be passed to D as debug flags.</dd> 
    57     <dt><code>raw_only</code></dt> <dd>This flag defaults to <code>False</code>. When <code>True</code>, it supresses the compilation and linkage of Pyd, StackThreads, and meta. This is useful if you only want to write a raw Python/C extension without the overhead of Pyd and its auxiliary packages. This is equivalent to specifying <code>False</code> to the next three flags.</dd> 
     57    <dt><code>raw_only</code></dt> <dd>This flag defaults to <code>False</code>. When <code>True</code>, it supresses the compilation and linkage of Pyd, StackThreads, and meta. This is useful if you only want to write a raw Python/C extension without the overhead of Pyd and its auxiliary packages. This is equivalent to specifying <code>False</code> to the next four flags.</dd> 
    5858    <dt><code>with_pyd</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the compilation and linkage of Pyd. This is useful if you want to write a raw Python/C extension and don't want the overhead of compiling Pyd.</dd> 
    5959    <dt><code>with_st</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the compilation and linkage of StackThreads. Pyd uses StackThreads for its iteration wrapping support. By setting this to <code>False</code>, opApply wrapping, <code>wrapped_class.iter</code>, and <code>wrapped_class.alt_iter</code> will be unavailable. If <code>with_pyd</code> and this are <code>True</code>, then the <code>Pyd_with_StackThreads</code> version flag will be defined (which is used internally by Pyd). <b>Important note:</b> StackThreads does not currently work with GDC! CeleriD will always set this flag to <code>False</code> when using GDC! This means that opApply wrapping is not available on Linux at this time.</dd> 
    6060    <dt><code>with_meta</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the compilation and linkage of <code>meta</code> (Pyd's metaprogramming package). Because Pyd depends on meta, an exception will be raised if <code>with_pyd</code> is <code>True</code> and this is not.</dd> 
     61    <dt><code>with_main</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the use of the "magic" <code>PydMain</code> function. (Instead, users must manually declare a C-style <code>init</code> function.) Do not use this unless you know what you are doing. If <code>with_pyd</code> is <code>False</code>, this will silently be set to <code>False</code> as well. <code>PydMain</code> can only be used if Pyd itself is in use.</dd> 
    6162    </dl> 
    6263</dd> 
  • trunk/html_doc/class_wrapping.html

    r63 r64  
    121121}</pre> 
    122122 
    123 <p>These would be exposed to Python by putting this code in out init function after the call to <code>module_init</code>:</p> 
     123<p>These would be exposed to Python by putting this code in <code>PydMain</code> after the call to <code>module_init</code>:</p> 
    124124 
    125125<pre class="code">wrapped_class!(Base) b; 
     
    226226}</pre> 
    227227 
    228 <p>We would expose this class to Python by putting this code in our init function after the call to <code>module_init</code>:</p> 
     228<p>We would expose this class to Python by putting this code in <code>PydMain</code> after the call to <code>module_init</code>:</p> 
    229229 
    230230<pre class="code"><span class="comment">// Make an instance of wrapped_class</span> 
  • trunk/html_doc/func_wrapping.html

    r59 r64  
    6060} 
    6161 
    62 <span class="keyword">extern</span> (C) 
    63 <span class="keyword">export void</span> inittestmodule() { 
     62<span class="keyword">extern</span> (C) <span class="keyword">void</span> PydMain() { 
    6463    <span class="comment">// Plain old function</span> 
    6564    def!(foo); 
     
    7170    def!(baz); 
    7271 
    73     module_init(<span class="string">"testmodule"</span>); 
     72    module_init(); 
    7473}</pre> 
    7574 
  • trunk/html_doc/index.html

    r57 r64  
    3333<p>Pyd includes the <code>meta.Nameof</code> package by Don Clugston. The source files meta.Nameof and meta.Demangle are copyright &copy; 2005-2006 Don Clugston.</p> 
    3434 
    35 <!-- Not documented, yet. 
    36 <p>Pyd includes its own metaprogramming library, <code>meta</code>, which was written by Tomasz Stachowiak, Don Clugston, and Kirk McDonald. The <code>meta</code> library is documented <a href="meta/index.html">here</a>.</code> 
    37 --> 
    38  
    3935<p>Pyd's Trac page can be found <a href="http://dsource.org/projects/pyd/wiki">here</a>.</p> 
    4036 
     
    4844} 
    4945 
    50 <span class="keyword">extern</span> (C) 
    51 <span class="keyword">export void</span> inittestdll() { 
     46<span class="keyword">extern</span> (C) <span class="keyword">void</span> PydMain() { 
    5247    def!(hello_func); 
    53  
    54     module_init(<span class="string">"testdll"</span>); 
     48    module_init(); 
    5549}</pre> 
    5650 
  • trunk/infrastructure/pyd/def.d

    r59 r64  
    9999} 
    100100 
     101char[] pyd_module_name; 
     102 
    101103/** 
    102104 * Module initialization function. Should be called after the last call to def. 
    103105 */ 
    104 PyObject* module_init(char[] name, char[] docstring="") { 
     106PyObject* module_init(char[] docstring="") { 
    105107    //_loadPythonSupport(); 
     108    char[] name = pyd_module_name; 
    106109    ready_module_methods(""); 
    107110    pyd_modules[""] = Py_InitModule3((name ~ \0).ptr, module_methods[""].ptr, (docstring ~ \0).ptr); 
  • trunk/raw_html/basics.html

    r62 r64  
    1919<pre class="code"><span class="keyword">import</span> pyd.pyd; 
    2020 
    21 <span class="keyword">extern</span> (C) 
    22 <span class="keyword">export void</span> inittestmodule() { 
    23     module_init(<span class="string">"testmodule"</span>); 
     21<span class="keyword">extern</span> (C) <span class="keyword">void</span> PydMain() { 
     22    module_init(); 
    2423}</pre> 
    2524 
     
    3029<p>The <code>pyd</code> module in the <code>pyd</code> package publicly imports all of the other components of Pyd.</p> 
    3130 
    32 <p>The "init" function is a requirement of the Python/C API. It is a global function with the footprint <code>extern(C) export void function()</code>. Its name <em>must</em> be <code>init</code> plus the name of your module. This function must then contain a call to <code>module_init</code>, with the same module name as an argument. (Users of Boost.Python will be familiar with the <code>BOOST_PYTHON_MODULE</code> macro used in that library. Unfortunately for this purpose, D has no preprocessor, and cannot define the name of a function like the C preprocessor can. Therefore, users of Pyd must define their init functions manually.)</p> 
     31<p>The <code>PydMain</code> function is called when the module is imported by Python. You will call most of Pyd's API from here. At the very least, <code>PydMain</code> <em>must</em> contain a call to <code>module_init</code>. The <code>module_init</code> function has the following form:</p> 
    3332 
    34 <p>The <code>module_init</code> function has the following form:</p> 
    35  
    36 <p><code>PyObject* module_init(char[] <span class="arg">name</span>, char[] <span class="arg">docstring</span>="");</code></p> 
     33<p><code>PyObject* module_init(char[] <span class="arg">docstring</span>="");</code></p> 
    3734 
    3835<p>It does little more than call <a href="http://docs.python.org/api/allocating-objects.html">Py_InitModule</a> and return the new module object. This object is also available via the <code>Pyd_Module_p</code> property once you've called <code>module_init</code>.</p> 
    3936 
    40 <p>Due to the way in which Pyd implements function and class wrapping, any calls to <code>def</code> must occur <em>before</em> the call to <code>module_init</code>, and any calls to <code>finalize_class</code> must occur <em>after</em> the call. I know this seems like a rather arbitrary rule, but it is important. Calls to <code>def</code> in the wrong place will simply be ignored, and calls to <code>finalize_class</code> in the wrong place will throw an assert. (And this assert will cause the Python interpreter to crash. So be warned.)</p> 
     37<p>Due to the way in which Pyd implements function and class wrapping, any calls to <code>def</code> must occur <em>before</em> the call to <code>module_init</code>, and any calls to <code>finalize_class</code> must occur <em>after</em> the call. I know this seems like a rather arbitrary rule, but it is important. Calls to <code>def</code> in the wrong place will simply be ignored, and calls to <code>finalize_class</code> in the wrong place will throw an assert.</p> 
    4138 
    42 <p>It is important that no D exceptions escape from the init function. If you put any of your own code in the init function, be sure to guard it aginst exceptions. The <a href="except_wrapping.html">exception wrapping</a> facilities of Pyd provide some useful functions for this purpose.</p> 
     39<p><code>PydMain</code> will catch any D exception that is thrown from inside it, and <a href="except_wrapping.html">safely pass that exception to Python</a>.</p> 
    4340</div> 
    4441 
  • trunk/raw_html/celerid.html

    r63 r64  
    4040    <dt><code>version_flags</code></dt> <dd>This should be a list of strings, which will be passed to the D compiler as version flags.</dd> 
    4141    <dt><code>debug_flags</code></dt> <dd>Similar to <code>version_flags</code>, the strings in this list will be passed to D as debug flags.</dd> 
    42     <dt><code>raw_only</code></dt> <dd>This flag defaults to <code>False</code>. When <code>True</code>, it supresses the compilation and linkage of Pyd, StackThreads, and meta. This is useful if you only want to write a raw Python/C extension without the overhead of Pyd and its auxiliary packages. This is equivalent to specifying <code>False</code> to the next three flags.</dd> 
     42    <dt><code>raw_only</code></dt> <dd>This flag defaults to <code>False</code>. When <code>True</code>, it supresses the compilation and linkage of Pyd, StackThreads, and meta. This is useful if you only want to write a raw Python/C extension without the overhead of Pyd and its auxiliary packages. This is equivalent to specifying <code>False</code> to the next four flags.</dd> 
    4343    <dt><code>with_pyd</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the compilation and linkage of Pyd. This is useful if you want to write a raw Python/C extension and don't want the overhead of compiling Pyd.</dd> 
    4444    <dt><code>with_st</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the compilation and linkage of StackThreads. Pyd uses StackThreads for its iteration wrapping support. By setting this to <code>False</code>, opApply wrapping, <code>wrapped_class.iter</code>, and <code>wrapped_class.alt_iter</code> will be unavailable. If <code>with_pyd</code> and this are <code>True</code>, then the <code>Pyd_with_StackThreads</code> version flag will be defined (which is used internally by Pyd). <b>Important note:</b> StackThreads does not currently work with GDC! CeleriD will always set this flag to <code>False</code> when using GDC! This means that opApply wrapping is not available on Linux at this time.</dd> 
    4545    <dt><code>with_meta</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the compilation and linkage of <code>meta</code> (Pyd's metaprogramming package). Because Pyd depends on meta, an exception will be raised if <code>with_pyd</code> is <code>True</code> and this is not.</dd> 
     46    <dt><code>with_main</code></dt> <dd>This flag defaults to <code>True</code>. When <code>False</code>, it supresses the use of the "magic" <code>PydMain</code> function. (Instead, users must manually declare a C-style <code>init</code> function.) Do not use this unless you know what you are doing. If <code>with_pyd</code> is <code>False</code>, this will silently be set to <code>False</code> as well. <code>PydMain</code> can only be used if Pyd itself is in use.</dd> 
    4647    </dl> 
    4748</dd> 
  • trunk/raw_html/class_wrapping.html

    r63 r64  
    106106}</pre> 
    107107 
    108 <p>These would be exposed to Python by putting this code in out init function after the call to <code>module_init</code>:</p> 
     108<p>These would be exposed to Python by putting this code in <code>PydMain</code> after the call to <code>module_init</code>:</p> 
    109109 
    110110<pre class="code">wrapped_class!(Base) b; 
     
    211211}</pre> 
    212212 
    213 <p>We would expose this class to Python by putting this code in our init function after the call to <code>module_init</code>:</p> 
     213<p>We would expose this class to Python by putting this code in <code>PydMain</code> after the call to <code>module_init</code>:</p> 
    214214 
    215215<pre class="code"><span class="comment">// Make an instance of wrapped_class</span> 
  • trunk/raw_html/func_wrapping.html

    r62 r64  
    4545} 
    4646 
    47 <span class="keyword">extern</span> (C) 
    48 <span class="keyword">export void</span> inittestmodule() { 
     47<span class="keyword">extern</span> (C) <span class="keyword">void</span> PydMain() { 
    4948    <span class="comment">// Plain old function</span> 
    5049    def!(foo); 
     
    5655    def!(baz); 
    5756 
    58     module_init(<span class="string">"testmodule"</span>); 
     57    module_init(); 
    5958}</pre> 
    6059 
  • trunk/raw_html/index.html

    r62 r64  
    1818<p>Pyd includes the <code>meta.Nameof</code> package by Don Clugston. The source files meta.Nameof and meta.Demangle are copyright &copy; 2005-2006 Don Clugston.</p> 
    1919 
    20 <!-- Not documented, yet. 
    21 <p>Pyd includes its own metaprogramming library, <code>meta</code>, which was written by Tomasz Stachowiak, Don Clugston, and Kirk McDonald. The <code>meta</code> library is documented <a href="meta/index.html">here</a>.</code> 
    22 --> 
    23  
    2420<p>Pyd's Trac page can be found <a href="http://dsource.org/projects/pyd/wiki">here</a>.</p> 
    2521 
     
    3329} 
    3430 
    35 <span class="keyword">extern</span> (C) 
    36 <span class="keyword">export void</span> inittestdll() { 
     31<span class="keyword">extern</span> (C) <span class="keyword">void</span> PydMain() { 
    3732    def!(hello_func); 
    38  
    39     module_init(<span class="string">"testdll"</span>); 
     33    module_init(); 
    4034}</pre> 
    4135 
  • trunk/support.py

    r63 r64  
    3939                del kwargs['debug_flags'] 
    4040 
     41        # Pass in the extension name so the compiler class can know it 
     42        if 'name' in kwargs: 
     43            define_macros.append((kwargs['name'], 'name')) 
     44        elif len(args) > 0: 
     45            define_macros.append((args[0], 'name')) 
     46 
    4147        # Similarly, pass in no_pyd, &c, via define_macros. 
    4248        if 'raw_only' in kwargs: 
     
    4450            kwargs['with_st'] = False 
    4551            kwargs['with_meta'] = False 
     52            kwargs['with_main'] = False 
    4653            del kwargs['raw_only'] 
    4754        with_pyd  = kwargs.pop('with_pyd', True) 
    4855        with_st   = kwargs.pop('with_st', True) 
    4956        with_meta = kwargs.pop('with_meta', True) 
     57        with_main = kwargs.pop('with_main', True) 
    5058        if with_pyd and not with_meta: 
    5159            raise DistutilsOptionError( 
     
    5462                ' extension.' 
    5563            ) 
    56         define_macros.append(((with_pyd, with_st, with_meta), 'aux')) 
     64        if with_main and not with_pyd: 
     65            # The special PydMain function should only be used when using Pyd 
     66            with_main = False 
     67        define_macros.append(((with_pyd, with_st, with_meta, with_main), 'aux')) 
    5768        kwargs['define_macros'] = define_macros 
    5869