Menu

#844 [tcl] Constants and enums - apply rule not working

None
closed-fixed
nobody
tcl (60)
5
2023-11-10
2007-07-25
No

I am upgrading from version 1.3.19 to 1.3.31. The following code is working fine with the old version:

#ifdef SWIG
%{
#include "test.h"
%}
%include "tclsh.i"
%module test
%apply int CONSTANT { int };
#endif
#include <stdio.h>
#define FOO 42
void bar(int x)
{
printf("%d\n", x);
}

%bar FOO
42
%

But with the new version I receive this warning:

test.cpp:7: Warning(453): Can't apply (int CONSTANT). No typemaps are defined.
And as a result:

% bar FOO
expected integer but got "FOO":bar x argument 1
%

The documentation states:
31.3.4 Constants and enums
If a program relies on a lot of constants, this can be extremely annoying. To fix the problem, consider using the following typemap rule:
%apply int CONSTANT { int x };
#define FOO 42
void bar(int x);

Discussion

  • Olly Betts

    Olly Betts - 2007-09-18
    • summary: Constants and enums - apply rule not working --> [tcl] Constants and enums - apply rule not working
     
  • Olly Betts

    Olly Betts - 2022-02-01

    Still reproducible with git master.

    Looks like these CONSTANT typemaps got removed by:

    commit 7e5e4fd1f9c8adfcd0eb1328e35143e110e115ff
    Author: Marcelo Matus <mmatus@acms.arizona.edu>
    Date:   Tue Oct 18 13:24:15 2005 +0000
    
        massive typemap unification
    
    
        git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
    
     
  • Olly Betts

    Olly Betts - 2023-11-10
    • status: open --> closed-fixed
    • Group: -->
     
  • Olly Betts

    Olly Betts - 2023-11-10

    I think that given this feature was removed 18 years ago we should just update the documentation to match reality. Reinstating these typemaps looks hard as they seem to use some magic via a parse typemap attribute which there's no longer any code to handle, and I can't see where it used to be handle, or any documentation as to what it did:

    %typemap(in,parse="I") int CONSTANT, unsigned int CONSTANT "";
    

    I've remove the documentation in 10bab22248327642133fcb94a7a7c1eb5e041ab8.

    If someone wants to reinstate them I've no objections, but leaving them documented when they aren't actually supported isn't helping anyone.

     

Log in to post a comment.