Javascript: fix warnings in li_std_string test.

Old typemaps for std::string were in place instead of delegating to UTL.
This commit is contained in:
Oliver Buchtala 2014-05-18 22:40:22 +02:00
commit 7824322b14
2 changed files with 2 additions and 148 deletions

View file

@ -1,69 +1 @@
/* -----------------------------------------------------------------------------
* std_string.i
*
* Typemaps for const std::string&.
* To use non-const std::string references use the following %apply:
* %apply const std::string & {std::string &};
*
* ----------------------------------------------------------------------------- */
%{
#include <string>
std::string SWIGJSC_valueToString(JSContextRef context, JSValueRef value) {
JSStringRef jsstring = JSValueToStringCopy(context, value, /* JSValueRef *exception */ 0);
unsigned int length = JSStringGetLength(jsstring);
char *cstr = new char[length + 1];
JSStringGetUTF8CString(jsstring, cstr, length + 1);
// create a copy
std::string result(cstr);
JSStringRelease(jsstring);
delete[] cstr;
return result;
}
JSValueRef SWIGJSC_stringToValue(JSContextRef context, const std::string& s)
{
JSValueRef result;
JSStringRef jsstring = JSStringCreateWithUTF8CString(s.c_str());
result = JSValueMakeString(context, jsstring);
JSStringRelease(jsstring);
return result;
}
%}
namespace std {
%naturalvar string;
class string;
%typemap(in) string
%{
$1 = SWIGJSC_valueToString(context, $input);
%}
%typemap(in) const string &
%{
$1 = new std::string(SWIGJSC_valueToString(context, $input));
%}
%typemap(freearg) const string &
%{
delete $1;
%}
%typemap(out) string
%{
$result = SWIGJSC_stringToValue(context, $1);
%}
%typemap(out) const string &
%{
$result = SWIGJSC_stringToValue(context, *$1);
%}
}
%include <typemaps/std_string.swg>

View file

@ -1,79 +1 @@
/* -----------------------------------------------------------------------------
* std_string.i
*
* Typemaps for std::string and const std::string&.
*
* To use non-const std::string references use the following %apply:
* %apply const std::string & {std::string &};
*
* ----------------------------------------------------------------------------- */
%{
#include <string>
%}
%fragment("SWIGV8_valueToString", "header", fragment="SWIG_AsCharPtrAndSize") {
std::string* SWIGV8_valueToStringPtr(v8::Handle<v8::Value> val) {
if (!val->IsString()) return 0;
int alloc;
size_t size;
char* chars;
int res = SWIG_AsCharPtrAndSize(val, &chars, &size, &alloc);
if(res != SWIG_OK) {
v8::ThrowException(v8::Exception::TypeError(v8::String::New("Could not convert to string.")));
return 0;
}
// copies the data (again)
std::string *str = new std::string(chars);
if (alloc) delete[] chars;
return str;
}
}
%fragment("SWIGV8_stringToValue", "header", fragment="SWIG_FromCharPtrAndSize") {
v8::Handle<v8::Value> SWIGV8_stringToValue(const std::string &str) {
return SWIG_FromCharPtrAndSize(str.c_str(), str.length());
}
}
namespace std {
%naturalvar string;
class string;
%typemap(in, fragment="SWIGV8_valueToString") string (std::string* tmp)
%{
tmp = SWIGV8_valueToStringPtr($input);
$1 = *tmp;
if (tmp == 0) { v8::ThrowException(v8::Exception::TypeError(v8::String::New("Null pointer."))); goto fail; }
if (tmp) delete tmp;
%}
%typemap(in, fragment="SWIGV8_valueToString") const string &
%{
$1 = SWIGV8_valueToStringPtr($input);
if ($1 == 0) { v8::ThrowException(v8::Exception::TypeError(v8::String::New("Null pointer."))); goto fail; }
%}
%typemap(freearg) const string &
%{
if ($1) delete $1;
%}
%typemap(out, fragment="SWIGV8_stringToValue") string
%{
$result = SWIGV8_stringToValue($1);
%}
%typemap(out, fragment="SWIGV8_stringToValue") const string &
%{
$result = SWIGV8_stringToValue(*$1);
%}
}
%include <typemaps/std_string.swg>