Swig upgrade 2.0.12 to 3.0.12: %typemaps_string changed

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Swig upgrade 2.0.12 to 3.0.12: %typemaps_string changed

Raab, Karl (Semonit)

Hello!

 

I'd like to upgrade from Swig 2->3 and I'm facing a problem in a typemap definition.

I ran into really old legacy code defining something with typemaps_string and couldn't find any information about a macro.

 

The code in general seem to do a typemapping of QString's (C++) - target Language is Perl. ('seems' because that code was handed me over and I'm not very familiar with Swig)

 

The macro that swig>=3.0.0 is complaining with the message "error : Macro '%typemaps_string' expects 11 arguments" is:

---

%typemaps_string(%checkcode(UNISTRING), %checkcode(UNICHAR),

     QChar, QChar,

     SWIG_AsQtChPtrAndSize,

     SWIG_FromQtChPtrAndSize,

     Qt_init,

     "<qt_string.h>", (-2147483647 - 1), 2147483647);

---

Unfortunately I couldn't find any information about the %typemaps_string macro. This change happend exactly by the update from Swig 2.0.12 to Swig 3.0.0. Out of the changelog I couldn't get any useful information as well (but that may be a result of my lacking knowledge of Swig).

 

Any information what this macro is used for and what changed since Swig3.x so that it now needs one parameter more?

 

Thanks for your help!

 

Here ist the full file in which this error occours:

---CODE BEGIN---

%include <perlstrings.swg>

 

%fragment("<qt_string.h>","header")

%{

#include <QtCore/qstring.h>

#include <QtCore/qbytearray.h>

%}

 

%fragment("Qt_init", "header",fragment="<qt_string.h>") { SWIGINTERN int Qt_init(const QChar *val) {

    QString qTemp(val);

    std::wstring str = qTemp.toStdWString();

    return qTemp.length();

}

}

 

%fragment("SWIG_AsQtChPtrAndSize","header",fragment="SWIG_AsCharPtrAndSize",fragment="Qt_init") { SWIGINTERN int SWIG_AsQtChPtrAndSize(SV *obj, QChar **val, size_t* psize, int *alloc) {

  if (!val) {

    return SWIG_AsCharPtrAndSize(obj, 0,  0, 0);   

  } else {

    size_t size;

    char *cptr = 0;

    int calloc = SWIG_OLDOBJ;

    int res = SWIG_AsCharPtrAndSize(obj, &cptr, &size, &calloc);

    if (SWIG_IsOK(res)) {

      STRLEN length = size - 1;

      if (SvUTF8(obj)) {

    int charsEaten = 0;

    unsigned char* sizes = %new_array(size, unsigned char);

    *val = %new_array(size, QChar);

    QString qVal = QString::fromUtf8(cptr);

 

    for (int i = 0; i < qVal.length(); i++)

    {

        (*val)[i] = qVal.at(i);

    }

    // indicate the end of the string

    (*val)[qVal.length()] = '\0';

    } else {

 

    QString qVal = QString::fromLocal8Bit(cptr);

    int val_size = qVal.length();

    if (val_size)

    {

        *val = new QChar[val_size+1];

        if (*val)

        {

            for (size_t i = 0; i < val_size; ++i) {

                (*val)[i] = qVal.at(i);

            }

            (*val)[val_size] = 0;

        }      

    }

    else

        *val = NULL;

 

      }

      if (psize) *psize = size;

      if (alloc) *alloc = SWIG_NEWOBJ;     

      if (calloc == SWIG_NEWOBJ) %delete_array(cptr);

      return SWIG_NEWOBJ;     

    } else {

      return res;

    }

  }

}

}

 

%fragment("SWIG_FromQtChPtrAndSize","header",fragment="Qt_init") { SWIGINTERNINLINE SV * SWIG_FromQtChPtrAndSize(const QChar* input, size_t size) { if (size <= 0) return NULL;

  SV *output = sv_newmortal();

  int charsEaten = 0;

  int length  = size;                                        // string length

  unsigned char* res = %new_array(length * 13, unsigned char);          // output string

 

    QString qVal(input, size);

    QByteArray qBytes = qVal.toUtf8();

 

    char *data = qBytes.data();

    char* pRes = (char*)&res[0];

 

    while (*data) {

        *pRes = *data;

        ++data;

        pRes++;

 

    }

 

  res[qBytes.size()] = '\0';

  sv_setpv((SV*)output, (char *)res );

  SvUTF8_on((SV*)output);

  %delete_array(res);

  return output;

}

}

 

%include <typemaps/strings.swg>

%typemaps_string(%checkcode(UNISTRING), %checkcode(UNICHAR),

         QChar, QChar,

         SWIG_AsQtChPtrAndSize,

         SWIG_FromQtChPtrAndSize,

         Qt_init,

         "<qt_string.h>", (-2147483647 - 1), 2147483647);

---CODE END---

 


------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Swig upgrade 2.0.12 to 3.0.12: %typemaps_string changed

William S Fulton
The change came from this commit: https://github.com/swig/swig/commit/88a0e228a9c80bedc414164f17b26be0147da333 and should help you make suitable changes in your own code.

William

On 12 March 2017 at 08:07, Raab, Karl (Semonit) <[hidden email]> wrote:

Hello!

 

I'd like to upgrade from Swig 2->3 and I'm facing a problem in a typemap definition.

I ran into really old legacy code defining something with typemaps_string and couldn't find any information about a macro.

 

The code in general seem to do a typemapping of QString's (C++) - target Language is Perl. ('seems' because that code was handed me over and I'm not very familiar with Swig)

 

The macro that swig>=3.0.0 is complaining with the message "error : Macro '%typemaps_string' expects 11 arguments" is:

---

%typemaps_string(%checkcode(UNISTRING), %checkcode(UNICHAR),

     QChar, QChar,

     SWIG_AsQtChPtrAndSize,

     SWIG_FromQtChPtrAndSize,

     Qt_init,

     "<qt_string.h>", (-2147483647 - 1), 2147483647);

---

Unfortunately I couldn't find any information about the %typemaps_string macro. This change happend exactly by the update from Swig 2.0.12 to Swig 3.0.0. Out of the changelog I couldn't get any useful information as well (but that may be a result of my lacking knowledge of Swig).

 

Any information what this macro is used for and what changed since Swig3.x so that it now needs one parameter more?

 

Thanks for your help!

 

Here ist the full file in which this error occours:

---CODE BEGIN---

%include <perlstrings.swg>

 

%fragment("<qt_string.h>","header")

%{

#include <QtCore/qstring.h>

#include <QtCore/qbytearray.h>

%}

 

%fragment("Qt_init", "header",fragment="<qt_string.h>") { SWIGINTERN int Qt_init(const QChar *val) {

    QString qTemp(val);

    std::wstring str = qTemp.toStdWString();

    return qTemp.length();

}

}

 

%fragment("SWIG_AsQtChPtrAndSize","header",fragment="SWIG_AsCharPtrAndSize",fragment="Qt_init") { SWIGINTERN int SWIG_AsQtChPtrAndSize(SV *obj, QChar **val, size_t* psize, int *alloc) {

  if (!val) {

    return SWIG_AsCharPtrAndSize(obj, 0,  0, 0);   

  } else {

    size_t size;

    char *cptr = 0;

    int calloc = SWIG_OLDOBJ;

    int res = SWIG_AsCharPtrAndSize(obj, &cptr, &size, &calloc);

    if (SWIG_IsOK(res)) {

      STRLEN length = size - 1;

      if (SvUTF8(obj)) {

    int charsEaten = 0;

    unsigned char* sizes = %new_array(size, unsigned char);

    *val = %new_array(size, QChar);

    QString qVal = QString::fromUtf8(cptr);

 

    for (int i = 0; i < qVal.length(); i++)

    {

        (*val)[i] = qVal.at(i);

    }

    // indicate the end of the string

    (*val)[qVal.length()] = '\0';

    } else {

 

    QString qVal = QString::fromLocal8Bit(cptr);

    int val_size = qVal.length();

    if (val_size)

    {

        *val = new QChar[val_size+1];

        if (*val)

        {

            for (size_t i = 0; i < val_size; ++i) {

                (*val)[i] = qVal.at(i);

            }

            (*val)[val_size] = 0;

        }      

    }

    else

        *val = NULL;

 

      }

      if (psize) *psize = size;

      if (alloc) *alloc = SWIG_NEWOBJ;     

      if (calloc == SWIG_NEWOBJ) %delete_array(cptr);

      return SWIG_NEWOBJ;     

    } else {

      return res;

    }

  }

}

}

 

%fragment("SWIG_FromQtChPtrAndSize","header",fragment="Qt_init") { SWIGINTERNINLINE SV * SWIG_FromQtChPtrAndSize(const QChar* input, size_t size) { if (size <= 0) return NULL;

  SV *output = sv_newmortal();

  int charsEaten = 0;

  int length  = size;                                        // string length

  unsigned char* res = %new_array(length * 13, unsigned char);          // output string

 

    QString qVal(input, size);

    QByteArray qBytes = qVal.toUtf8();

 

    char *data = qBytes.data();

    char* pRes = (char*)&res[0];

 

    while (*data) {

        *pRes = *data;

        ++data;

        pRes++;

 

    }

 

  res[qBytes.size()] = '\0';

  sv_setpv((SV*)output, (char *)res );

  SvUTF8_on((SV*)output);

  %delete_array(res);

  return output;

}

}

 

%include <typemaps/strings.swg>

%typemaps_string(%checkcode(UNISTRING), %checkcode(UNICHAR),

         QChar, QChar,

         SWIG_AsQtChPtrAndSize,

         SWIG_FromQtChPtrAndSize,

         Qt_init,

         "<qt_string.h>", (-2147483647 - 1), 2147483647);

---CODE END---

 


------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user



------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...