From d73f2d76a050e8ae21ab0ab50e330a82c716656f Mon Sep 17 00:00:00 2001
From: David Carlier <[EMAIL REDACTED]>
Date: Fri, 24 Feb 2023 15:10:57 +0000
Subject: [PATCH] Haiku modernizing a bit the C++ code with C++11 heuristics
with BApplication
---
src/core/haiku/SDL_BeApp.cc | 7 ++++---
src/video/haiku/SDL_bmessagebox.cc | 9 +++------
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/src/core/haiku/SDL_BeApp.cc b/src/core/haiku/SDL_BeApp.cc
index 9a2f98fb062c..6eecb26e996b 100644
--- a/src/core/haiku/SDL_BeApp.cc
+++ b/src/core/haiku/SDL_BeApp.cc
@@ -30,6 +30,7 @@
#include <storage/Entry.h>
#include <storage/File.h>
#include <unistd.h>
+#include <memory>
#include "SDL_BApp.h" /* SDL_BApp class definition */
#include "SDL_BeApp.h"
@@ -51,8 +52,9 @@ const char *signature = "application/x-SDL-executable";
static int StartBeApp(void *unused)
{
- BApplication *App;
+ std::unique_ptr<BApplication> App;
+ (void)unused;
// dig resources for correct signature
image_info info;
int32 cookie = 0;
@@ -69,10 +71,9 @@ static int StartBeApp(void *unused)
}
}
- App = new SDL_BApp(signature);
+ App = std::unique_ptr<BApplication>(new SDL_BApp(signature));
App->Run();
- delete App;
return 0;
}
diff --git a/src/video/haiku/SDL_bmessagebox.cc b/src/video/haiku/SDL_bmessagebox.cc
index 86ba990dec84..9f36e94b5771 100644
--- a/src/video/haiku/SDL_bmessagebox.cc
+++ b/src/video/haiku/SDL_bmessagebox.cc
@@ -45,6 +45,7 @@
#include <new>
#include <vector>
#include <algorithm>
+#include <memory>
enum
{
@@ -355,9 +356,9 @@ HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
// because it is possible to create a MessageBox from another thread. This fixes the following errors:
// "You need a valid BApplication object before interacting with the app_server."
// "2 BApplication objects were created. Only one is allowed."
- BApplication *application = NULL;
+ std::unique_ptr<BApplication> application;
if (be_app == NULL) {
- application = new(std::nothrow) BApplication(signature);
+ application = std::unique_ptr<BApplication>(new(std::nothrow) BApplication(signature));
if (application == NULL) {
return SDL_SetError("Cannot create the BApplication object. Lack of memory?");
}
@@ -381,10 +382,6 @@ HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
delete messageBox;
}
*/
- if (application != NULL) {
- delete application;
- }
-
// Initialize button by real pushed value then.
*buttonid = pushedButton;