Do not copy string if we send string to C# 81/306481/4
authorEunki, Hong <eunkiki.hong@samsung.com>
Thu, 22 Feb 2024 04:07:21 +0000 (13:07 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Thu, 22 Feb 2024 05:23:22 +0000 (14:23 +0900)
C# copy native string if we call C# API. So duplicate string and send it is useless.
And also, it's behavior might occure some memory leak.

To resolve it, let we just send const char* directly.

Change-Id: I9f18b25503406081c3866cc979dfca90d5113bb2
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
dali-csharp-binder/common/dali-wrap.cpp
dali-csharp-binder/common/dali-wrap.h
dali-csharp-binder/dali-toolkit/web-view-wrap.cpp

index 85040d5..a41b5a1 100644 (file)
@@ -1195,30 +1195,26 @@ SwigDirector_WidgetImpl::~SwigDirector_WidgetImpl() {
 }
 
 void SwigDirector_WidgetImpl::OnCreate(std::string const &contentInfo, Dali::Window window) {
-  char * jcontentInfo = 0 ;
   void * jwindow  ;
 
   if (!swig_callbackOnCreate) {
     Dali::Internal::Adaptor::Widget::OnCreate(contentInfo,window);
     return;
   } else {
-    jcontentInfo = SWIG_csharp_string_callback((&contentInfo)->c_str());
     jwindow = (void *)new Dali::Window((const Dali::Window &)window);
-    swig_callbackOnCreate(jcontentInfo, jwindow);
+    swig_callbackOnCreate(contentInfo.c_str(), jwindow);
   }
 }
 
 void SwigDirector_WidgetImpl::OnTerminate(std::string const &contentInfo, Dali::Widget::Termination type) {
-  char * jcontentInfo = 0 ;
   int jtype  ;
 
   if (!swig_callbackOnTerminate) {
     Dali::Internal::Adaptor::Widget::OnTerminate(contentInfo,type);
     return;
   } else {
-    jcontentInfo = SWIG_csharp_string_callback((&contentInfo)->c_str());
     jtype = (int)type;
-    swig_callbackOnTerminate(jcontentInfo, jtype);
+    swig_callbackOnTerminate(contentInfo.c_str(), jtype);
   }
 }
 
@@ -1253,16 +1249,14 @@ void SwigDirector_WidgetImpl::OnResize(Dali::Window window) {
 }
 
 void SwigDirector_WidgetImpl::OnUpdate(std::string const &contentInfo, int force) {
-  char * jcontentInfo = 0 ;
   int jforce  ;
 
   if (!swig_callbackOnUpdate) {
     Dali::Internal::Adaptor::Widget::OnUpdate(contentInfo,force);
     return;
   } else {
-    jcontentInfo = SWIG_csharp_string_callback((&contentInfo)->c_str());
     jforce = force;
-    swig_callbackOnUpdate(jcontentInfo, jforce);
+    swig_callbackOnUpdate(contentInfo.c_str(), jforce);
   }
 }
 
index fb4765f..8a0c5a3 100755 (executable)
@@ -25,12 +25,12 @@ public:
     virtual void SignalConnected(Dali::SlotObserver *slotObserver, Dali::CallbackBase *callback);
     virtual void SignalDisconnected(Dali::SlotObserver *slotObserver, Dali::CallbackBase *callback);
 
-    typedef void (SWIGSTDCALL* SWIG_Callback0_t)(char *, void *);
-    typedef void (SWIGSTDCALL* SWIG_Callback1_t)(char *, int);
+    typedef void (SWIGSTDCALL* SWIG_Callback0_t)(const char *, void *);
+    typedef void (SWIGSTDCALL* SWIG_Callback1_t)(const char *, int);
     typedef void (SWIGSTDCALL* SWIG_Callback2_t)();
     typedef void (SWIGSTDCALL* SWIG_Callback3_t)();
     typedef void (SWIGSTDCALL* SWIG_Callback4_t)(void *);
-    typedef void (SWIGSTDCALL* SWIG_Callback5_t)(char *, int);
+    typedef void (SWIGSTDCALL* SWIG_Callback5_t)(const char *, int);
     typedef void (SWIGSTDCALL* SWIG_Callback6_t)(void *, void *);
     typedef void (SWIGSTDCALL* SWIG_Callback7_t)(void *, void *);
     void swig_connect_director(SWIG_Callback0_t callbackOnCreate, SWIG_Callback1_t callbackOnTerminate, SWIG_Callback2_t callbackOnPause, SWIG_Callback3_t callbackOnResume, SWIG_Callback4_t callbackOnResize, SWIG_Callback5_t callbackOnUpdate, SWIG_Callback6_t callbackSignalConnected, SWIG_Callback7_t callbackSignalDisconnected);
index bf72420..05702ac 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -605,9 +605,9 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_EvaluateJavaScript(void * jarg1,
   {
     try {
       if (jarg3) {
-        void (*handler)(char *) = (void (*)(char *))jarg3;
+        void (*handler)(const char *) = (void (*)(const char *))jarg3;
         (arg1)->EvaluateJavaScript((std::string const &)*arg2, [handler](const std::string &result) {
-              handler(SWIG_csharp_string_callback(result.c_str()));
+              handler(result.c_str());
             });
       }
       else {
@@ -625,12 +625,12 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_AddJavaScriptMessageHandler(void
 
   Dali::Toolkit::WebView* webview = (Dali::Toolkit::WebView*)jarg1;
   std::string exposedObjectName = jarg2;
-  void (*handler)(char*) = (void (*)(char*))jarg3;
+  void (*handler)(const char*) = (void (*)(const char*))jarg3;
 
   {
     try {
       webview->AddJavaScriptMessageHandler(exposedObjectName, [handler](const std::string &message) {
-            handler(SWIG_csharp_string_callback(message.c_str()));
+            handler(message.c_str());
           });
     } CALL_CATCH_EXCEPTION();
   }
@@ -638,13 +638,13 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_AddJavaScriptMessageHandler(void
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterJavaScriptAlertCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView* webview = (Dali::Toolkit::WebView*)jarg1;
-  bool (*handler)(char*) = (bool (*)(char*))jarg2;
+  bool (*handler)(const char*) = (bool (*)(const char*))jarg2;
   {
     try {
       if (handler)
       {
         webview->RegisterJavaScriptAlertCallback([handler](const std::string &message) -> bool {
-            return handler(SWIG_csharp_string_callback(message.c_str()));
+            return handler(message.c_str());
           });
       }
       else
@@ -666,14 +666,14 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_JavaScriptAlertReply(void * jarg
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterJavaScriptConfirmCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView* webview = (Dali::Toolkit::WebView*)jarg1;
-  bool (*handler)(char*) = (bool (*)(char*))jarg2;
+  bool (*handler)(const char*) = (bool (*)(const char*))jarg2;
 
   {
     try {
       if (handler)
       {
         webview->RegisterJavaScriptConfirmCallback([handler](const std::string &message) -> bool {
-            return handler(SWIG_csharp_string_callback(message.c_str()));
+            return handler(message.c_str());
           });
       }
       else
@@ -695,7 +695,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_JavaScriptConfirmReply(void * ja
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterJavaScriptPromptCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView* webview = (Dali::Toolkit::WebView*)jarg1;
-  bool (*handler)(char *, char*) = (bool (*)(char *, char*))jarg2;
+  bool (*handler)(const char *, const char*) = (bool (*)(const char *, const char*))jarg2;
 
   {
     try {
@@ -703,8 +703,8 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterJavaScriptPromptCallback
       {
         webview->RegisterJavaScriptPromptCallback([handler](const std::string &message1,
                     const std::string &message2) -> bool {
-            return handler(SWIG_csharp_string_callback(message1.c_str()),
-                           SWIG_csharp_string_callback(message2.c_str()));
+            return handler(message1.c_str(),
+                           message2.c_str());
           });
       }
       else
@@ -886,14 +886,14 @@ SWIGEXPORT bool SWIGSTDCALL CSharp_Dali_WebView_CheckVideoPlayingAsynchronously(
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterGeolocationPermissionCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView *arg1 = (Dali::Toolkit::WebView *)jarg1;
-  bool (*handler)(char *, char *) = (bool (*)(char *, char *))jarg2;
+  bool (*handler)(const char *, const char *) = (bool (*)(const char *, const char *))jarg2;
   {
     try {
       if (handler)
       {
         (arg1)->RegisterGeolocationPermissionCallback([handler](const std::string &host, const std::string &protocol) -> bool {
-            return handler(SWIG_csharp_string_callback(host.c_str()),
-                           SWIG_csharp_string_callback(protocol.c_str()));
+            return handler(host.c_str(),
+                           protocol.c_str());
           });
       }
       else
@@ -917,13 +917,13 @@ SWIGEXPORT Dali::Toolkit::Control *SWIGSTDCALL CSharp_Dali_WebView_SWIGUpcast(Da
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterPageLoadStartedCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView *arg1 = (Dali::Toolkit::WebView *)jarg1;
-  void (*handler)(char*) = (void (*)(char*))jarg2;
+  void (*handler)(const char*) = (void (*)(const char*))jarg2;
   {
     try {
       if (handler)
       {
         (arg1)->RegisterPageLoadStartedCallback([handler](const std::string& url) {
-            handler(SWIG_csharp_string_callback(url.c_str()));
+            handler(url.c_str());
           });
       }
       else
@@ -936,13 +936,13 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterPageLoadStartedCallback(
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterPageLoadInProgressCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView *arg1 = (Dali::Toolkit::WebView *)jarg1;
-  void (*handler)(char*) = (void (*)(char*))jarg2;
+  void (*handler)(const char*) = (void (*)(const char*))jarg2;
   {
     try {
       if (handler)
       {
         (arg1)->RegisterPageLoadInProgressCallback([handler](const std::string& url) {
-            handler(SWIG_csharp_string_callback(url.c_str()));
+            handler(url.c_str());
           });
       }
       else
@@ -955,13 +955,13 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterPageLoadInProgressCallba
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterPageLoadFinishedCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView *arg1 = (Dali::Toolkit::WebView *)jarg1;
-  void (*handler)(char*) = (void (*)(char*))jarg2;
+  void (*handler)(const char*) = (void (*)(const char*))jarg2;
   {
     try {
       if (handler)
       {
         (arg1)->RegisterPageLoadFinishedCallback([handler](const std::string& url) {
-            handler(SWIG_csharp_string_callback(url.c_str()));
+            handler(url.c_str());
           });
       }
       else
@@ -1012,13 +1012,13 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterScrollEdgeReachedCallbac
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterUrlChangedCallback(void * jarg1, void * jarg2) {
   Dali::Toolkit::WebView *arg1 = (Dali::Toolkit::WebView *)jarg1;
-  void (*handler)(char*) = (void (*)(char*))jarg2;
+  void (*handler)(const char*) = (void (*)(const char*))jarg2;
   {
     try {
       if (handler)
       {
         (arg1)->RegisterUrlChangedCallback([handler](const std::string& url) {
-            handler(SWIG_csharp_string_callback(url.c_str()));
+            handler(url.c_str());
           });
       }
       else
@@ -1245,11 +1245,11 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_RegisterContextMenuHiddenCallbac
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebView_GetPlainTextAsynchronously(void * nuiWebView, void * nuiCallback) {
   Dali::Toolkit::WebView *webview = (Dali::Toolkit::WebView *)nuiWebView;
-  void (*callback)(char*) = (void (*)(char*))nuiCallback;
+  void (*handler)(const char*) = (void (*)(const char*))nuiCallback;
   {
     try {
-      webview->GetPlainTextAsynchronously([callback](const std::string& url) {
-            callback(SWIG_csharp_string_callback(url.c_str()));
+      webview->GetPlainTextAsynchronously([handler](const std::string& url) {
+            handler(url.c_str());
           });
     } CALL_CATCH_EXCEPTION();
   }
@@ -1800,14 +1800,14 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebContext_GetFormPasswordList(void *jar
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebContext_RegisterDownloadStartedCallback(void * jarg1, void * jarg2) {
   Dali::WebEngineContext *arg1 = (Dali::WebEngineContext *)jarg1;
-  void (*handler)(char *) = (void (*)(char *))jarg2;
+  void (*handler)(const char *) = (void (*)(const char *))jarg2;
   {
     try {
       if (handler)
       {
         (arg1)->RegisterDownloadStartedCallback(
                  [handler](const std::string& url) {
-                   handler(SWIG_csharp_string_callback(url.c_str()));
+                   handler(url.c_str());
                  });
       }
       else
@@ -1820,16 +1820,16 @@ SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebContext_RegisterDownloadStartedCallba
 
 SWIGEXPORT void SWIGSTDCALL CSharp_Dali_WebContext_RegisterMimeOverriddenCallback(void *jarg1, void *jarg2) {
   Dali::WebEngineContext *arg1 = (Dali::WebEngineContext *)jarg1;
-  bool (*handler)(char *, char *, char *) = (bool (*)(char *, char *, char *))jarg2;
+  bool (*handler)(const char *, const char *, const char *) = (bool (*)(const char *, const char *, const char *))jarg2;
   {
     try {
       if (handler)
       {
         (arg1)->RegisterMimeOverriddenCallback(
           [handler](const std::string& url, const std::string& mime, std::string& newMime) -> bool {
-            return handler(SWIG_csharp_string_callback(url.c_str()),
-                           SWIG_csharp_string_callback(mime.c_str()),
-                           SWIG_csharp_string_callback(newMime.c_str()));
+            return handler(url.c_str(),
+                           mime.c_str(),
+                           newMime.c_str());
           });
       }
       else