Changeset 64
- Timestamp:
- 12/18/06 06:00:22 (2 years ago)
- Files:
-
- trunk/dcompiler.py (modified) (8 diffs)
- trunk/examples/hello/hello.d (modified) (1 diff)
- trunk/examples/inherit/inherit.d (modified) (1 diff)
- trunk/examples/testdll/testdll.d (modified) (2 diffs)
- trunk/html_doc/basics.html (modified) (2 diffs)
- trunk/html_doc/celerid.html (modified) (1 diff)
- trunk/html_doc/class_wrapping.html (modified) (2 diffs)
- trunk/html_doc/func_wrapping.html (modified) (2 diffs)
- trunk/html_doc/index.html (modified) (2 diffs)
- trunk/infrastructure/d/pydmain_template.d (added)
- trunk/infrastructure/pyd/def.d (modified) (1 diff)
- trunk/raw_html/basics.html (modified) (2 diffs)
- trunk/raw_html/celerid.html (modified) (1 diff)
- trunk/raw_html/class_wrapping.html (modified) (2 diffs)
- trunk/raw_html/func_wrapping.html (modified) (2 diffs)
- trunk/raw_html/index.html (modified) (2 diffs)
- trunk/support.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dcompiler.py
r63 r64 142 142 143 143 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 145 158 # To sources, add the appropriate D header file python.d, as well as 146 159 # any platform-specific boilerplate. … … 153 166 ' header files "%s" is missing.' % pythonHeaderPath 154 167 ) 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] 159 172 # And Pyd! 160 if flags[0]:173 if with_pyd: 161 174 # 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: 163 176 _pydFiles.remove('iteration.d'); 164 177 for file in _pydFiles: … … 168 181 " missing." % filePath 169 182 ) 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')) 171 203 # And StackThreads 172 if self._st_support and flags[1]:204 if self._st_support and with_st: 173 205 for file in _stFiles: 174 206 filePath = os.path.join(_infraDir, 'st', file) … … 177 209 " file '%s' is missing." % filePath 178 210 ) 179 sources.append( filePath)211 sources.append((filePath, 'infra')) 180 212 # Add the version conditional for st 181 213 macros.append(('Pyd_with_StackThreads', 'version')) 182 214 # And meta 183 if flags[2]:215 if with_meta: 184 216 for file in _metaFiles: 185 217 filePath = os.path.join(_infraDir, 'meta', file) … … 188 220 " '%s' is missing." % filePath 189 221 ) 190 sources.append( filePath)222 sources.append((filePath, 'infra')) 191 223 # 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): 193 225 includePathOpts += self._includeOpts 194 226 includePathOpts[-1] = includePathOpts[-1] % os.path.join(_infraDir) … … 207 239 ' is missing.' % boilerplatePath 208 240 ) 209 sources.append( boilerplatePath)241 sources.append((boilerplatePath, 'infra')) 210 242 211 243 # Extension subclass DExtension will have packed any user-supplied … … 239 271 optimizationOpts = self._defaultOptimizeOpts 240 272 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) 268 289 cmdElements = ( 269 290 [binpath] + extra_preargs + compileOpts + 270 291 [pythonVersionOpt, self._unicodeOpt] + optimizationOpts + 271 includePathOpts + userVersionAndDebugOpts +272 sources+ extra_postargs292 includePathOpts + outOpts + userVersionAndDebugOpts + 293 [_qp(source)] + extra_postargs 273 294 ) 274 295 cmdElements = [el for el in cmdElements if el] 275 276 296 try: 277 297 self.spawn(cmdElements) 278 298 except DistutilsExecError, msg: 279 #os.chdir(cwd)280 299 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 284 301 285 302 def link (self, … … 432 449 433 450 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') 435 452 f = file(defFilePath, 'wb') 436 453 try: trunk/examples/hello/hello.d
r46 r64 9 9 } 10 10 11 extern(C) 12 export void inithello() { 11 extern(C) void PydMain() { 13 12 def!(hello); 14 module_init( "hello");13 module_init(); 15 14 } trunk/examples/inherit/inherit.d
r57 r64 31 31 } 32 32 33 extern(C) 34 export void initinherit() { 33 extern(C) void PydMain() { 35 34 def!(call_poly); 36 35 37 module_init( "inherit");36 module_init(); 38 37 39 38 wrapped_class!(Base) b; trunk/examples/testdll/testdll.d
r57 r64 128 128 } 129 129 130 extern (C) 131 export void inittestdll() { 130 //extern (C) 131 //export void inittestdll() { 132 extern(C) void PydMain() { 132 133 def!(foo); 133 134 // Python does not support function overloading. This allows us to wrap … … 145 146 def!(throws); 146 147 147 module_init( "testdll");148 module_init(); 148 149 149 150 wrapped_class!(Foo) f; trunk/html_doc/basics.html
r59 r64 34 34 <pre class="code"><span class="keyword">import</span> pyd.pyd; 35 35 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(); 39 38 }</pre> 40 39 … … 45 44 <p>The <code>pyd</code> module in the <code>pyd</code> package publicly imports all of the other components of Pyd.</p> 46 45 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> 48 47 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> 52 49 53 50 <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> 54 51 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> 56 53 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> 58 55 </div> 59 56 trunk/html_doc/celerid.html
r63 r64 55 55 <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> 56 56 <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 threeflags.</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> 58 58 <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> 59 59 <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> 60 60 <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> 61 62 </dl> 62 63 </dd> trunk/html_doc/class_wrapping.html
r63 r64 121 121 }</pre> 122 122 123 <p>These would be exposed to Python by putting this code in out init functionafter 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> 124 124 125 125 <pre class="code">wrapped_class!(Base) b; … … 226 226 }</pre> 227 227 228 <p>We would expose this class to Python by putting this code in our init functionafter 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> 229 229 230 230 <pre class="code"><span class="comment">// Make an instance of wrapped_class</span> trunk/html_doc/func_wrapping.html
r59 r64 60 60 } 61 61 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() { 64 63 <span class="comment">// Plain old function</span> 65 64 def!(foo); … … 71 70 def!(baz); 72 71 73 module_init( <span class="string">"testmodule"</span>);72 module_init(); 74 73 }</pre> 75 74 trunk/html_doc/index.html
r57 r64 33 33 <p>Pyd includes the <code>meta.Nameof</code> package by Don Clugston. The source files meta.Nameof and meta.Demangle are copyright © 2005-2006 Don Clugston.</p> 34 34 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 39 35 <p>Pyd's Trac page can be found <a href="http://dsource.org/projects/pyd/wiki">here</a>.</p> 40 36 … … 48 44 } 49 45 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() { 52 47 def!(hello_func); 53 54 module_init(<span class="string">"testdll"</span>); 48 module_init(); 55 49 }</pre> 56 50 trunk/infrastructure/pyd/def.d
r59 r64 99 99 } 100 100 101 char[] pyd_module_name; 102 101 103 /** 102 104 * Module initialization function. Should be called after the last call to def. 103 105 */ 104 PyObject* module_init(char[] name, char[]docstring="") {106 PyObject* module_init(char[] docstring="") { 105 107 //_loadPythonSupport(); 108 char[] name = pyd_module_name; 106 109 ready_module_methods(""); 107 110 pyd_modules[""] = Py_InitModule3((name ~ \0).ptr, module_methods[""].ptr, (docstring ~ \0).ptr); trunk/raw_html/basics.html
r62 r64 19 19 <pre class="code"><span class="keyword">import</span> pyd.pyd; 20 20 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(); 24 23 }</pre> 25 24 … … 30 29 <p>The <code>pyd</code> module in the <code>pyd</code> package publicly imports all of the other components of Pyd.</p> 31 30 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> 33 32 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> 37 34 38 35 <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> 39 36 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> 41 38 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> 43 40 </div> 44 41 trunk/raw_html/celerid.html
r63 r64 40 40 <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> 41 41 <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 threeflags.</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> 43 43 <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> 44 44 <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> 45 45 <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> 46 47 </dl> 47 48 </dd> trunk/raw_html/class_wrapping.html
r63 r64 106 106 }</pre> 107 107 108 <p>These would be exposed to Python by putting this code in out init functionafter 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> 109 109 110 110 <pre class="code">wrapped_class!(Base) b; … … 211 211 }</pre> 212 212 213 <p>We would expose this class to Python by putting this code in our init functionafter 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> 214 214 215 215 <pre class="code"><span class="comment">// Make an instance of wrapped_class</span> trunk/raw_html/func_wrapping.html
r62 r64 45 45 } 46 46 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() { 49 48 <span class="comment">// Plain old function</span> 50 49 def!(foo); … … 56 55 def!(baz); 57 56 58 module_init( <span class="string">"testmodule"</span>);57 module_init(); 59 58 }</pre> 60 59 trunk/raw_html/index.html
r62 r64 18 18 <p>Pyd includes the <code>meta.Nameof</code> package by Don Clugston. The source files meta.Nameof and meta.Demangle are copyright © 2005-2006 Don Clugston.</p> 19 19 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 24 20 <p>Pyd's Trac page can be found <a href="http://dsource.org/projects/pyd/wiki">here</a>.</p> 25 21 … … 33 29 } 34 30 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() { 37 32 def!(hello_func); 38 39 module_init(<span class="string">"testdll"</span>); 33 module_init(); 40 34 }</pre> 41 35 trunk/support.py
r63 r64 39 39 del kwargs['debug_flags'] 40 40 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 41 47 # Similarly, pass in no_pyd, &c, via define_macros. 42 48 if 'raw_only' in kwargs: … … 44 50 kwargs['with_st'] = False 45 51 kwargs['with_meta'] = False 52 kwargs['with_main'] = False 46 53 del kwargs['raw_only'] 47 54 with_pyd = kwargs.pop('with_pyd', True) 48 55 with_st = kwargs.pop('with_st', True) 49 56 with_meta = kwargs.pop('with_meta', True) 57 with_main = kwargs.pop('with_main', True) 50 58 if with_pyd and not with_meta: 51 59 raise DistutilsOptionError( … … 54 62 ' extension.' 55 63 ) 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')) 57 68 kwargs['define_macros'] = define_macros 58 69
