On Sun, Aug 7, 2016 at 11:53 AM, leif <not.rea...@online.de> wrote:
> Jeroen Demeyer wrote:
>> On 2016-08-07 17:26, Simon King wrote:
>>>    I build all these extension modules with
>>>         libraries = ['mtx', 'modres']
>>
>> This isn't the topic of this thread, but I think it is better style to
>> never put libraries in module_list.py. I prefer putting libraries in "#
>> distutils" directives where you actually declare the library interface
>> (that would be src/sage/libs/meataxe.pxd). See
>> src/sage/libs/pari/paridecl.pxd for an example.
>>
>> This way, you never need to guess which modules need to link against
>> -lmtx. Cython will automatically add -lmtx to anything cimporting
>> meataxe.pxd.
>
> But this has a drawback as well, since people tend to import / include
> randomly (with recursive effects) more than perhaps randomly adding
> libraries in module_list (although the latter happened as well, and more
> than once caused problems). ;-)

It's still the recommended way to go, as cimporting from a module that
requires library X without linking library X is always an error.

> And sometimes it's easier to look at one file (module_list.py) than to
> scan all Cython files and guess what effectively an extension module
> includes and (probably unintentionally) links to.

When does one need this information? Perhaps Cython could provide
better introspection (though the set of C files now include a
"metadata" header about what distutils arguments should be passed for
each).

As to the original question, having a single meataxe shared library
seems cleaner to me than each extension linking in its own separate
copy, with the global set once by __init__.py, but I don't know how
well meataxe lends itself to this.

>> One caveat: this works better if you split the declarations of types
>> from the declarations of functions. See src/sage/libs/gmp/types.pxd for
>> an example. This types.pxd does not need to link against the library.
>>
>> In src/sage/matrix/matrix_gfpn_dense.pxd you can then replace the line
>> from sage.libs.meataxe cimport *
>> by
>> from sage.libs.meataxe.types cimport Matrix_t
>> Of course, the file src/sage/matrix/matrix_gfpn_dense.pyx would need to
>> cimport more stuff from meataxe.
>
> That doesn't just apply to Cython headers, but also upstream (in this
> case, meataxe.h).  Also PARI is a good example to look at; split public
> and private/internal, type definitions, inline functions, macros,
> function declarations, [global] variable *declarations* (if at all
> necessary) into separate header files.  (Likewise, if at all needed,
> global variables could be put into a separate module, as opposed to
> putting them also into the library everybody links to.)
>
>
> -leif
>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to