@@ -30,15 +30,12 @@ diff --git a/memory/mozalloc/mozalloc_abort.cpp b/memory/mozalloc/mozalloc_abort
3030index 3cfc92533..9c487ac45 100644
3131--- a/memory/mozalloc/mozalloc_abort.cpp
3232+++ b/memory/mozalloc/mozalloc_abort.cpp
33- @@ -9,6 +9,11 @@
33+ @@ -9,6 +9,8 @@
3434
3535 #ifdef ANDROID
3636 # include <android/log.h>
37- + #elif defined(XP_OHOS)
38- + extern "C" {
39- + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
40- + __attribute__((__format__(os_log, 5, 6)));
41- + }
37+ + #elif defined(OHOS)
38+ + # include <hilog/log.h>
4239 #endif
4340 #ifdef MOZ_WIDGET_ANDROID
4441 # include "APKOpen.h"
@@ -49,8 +46,8 @@ index 3cfc92533..9c487ac45 100644
4946- #ifndef ANDROID
5047+ #ifdef ANDROID
5148+ __android_log_print(ANDROID_LOG_ERROR, "Gecko", "mozalloc_abort: %s", msg);
52- + #elif defined(XP_OHOS )
53- + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "Gecko",
49+ + #elif defined(OHOS )
50+ + (void) OH_LOG_Print(LOG_APP, LOG_ERROR , 0, "Gecko",
5451+ "mozalloc_abort: %{public}s\n", msg);
5552+ #else
5653 fputs(msg, stderr);
@@ -64,58 +61,50 @@ diff --git a/mfbt/Assertions.h b/mfbt/Assertions.h
6461index 0b7395177..e84d76aba 100644
6562--- a/mfbt/Assertions.h
6663+++ b/mfbt/Assertions.h
67- @@ -88,6 +88,11 @@ MOZ_END_EXTERN_C
64+ @@ -88,6 +88,8 @@ MOZ_END_EXTERN_C
6865 #endif
6966 #ifdef ANDROID
7067 # include <android/log.h>
71- + #elif defined(XP_OHOS)
72- + MOZ_BEGIN_EXTERN_C
73- + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
74- + __attribute__((__format__(os_log, 5, 6)));
75- + MOZ_END_EXTERN_C
68+ + #elif defined(OHOS)
69+ + # include <hilog/log.h>
7670 #endif
7771
7872 MOZ_BEGIN_EXTERN_C
7973@@ -120,6 +122,10 @@ MOZ_ReportAssertionFailure(const char* aStr, const char* aFilename,
8074 MozWalkTheStackWithWriter(MOZ_ReportAssertionFailurePrintFrame, CallerPC(),
8175 /* aMaxFrames */ 0);
8276 # endif
83- + #elif defined(XP_OHOS )
84- + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "MOZ_Assert",
77+ + #elif defined(OHOS )
78+ + (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_Assert",
8579+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",
8680+ aStr, aFilename, aLine);
8781 #else
8882 # if defined(MOZ_BUFFER_STDERR)
8983 char msg[1024] = "";
90- @@ -144,8 +150,12 @@ MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void MOZ_ReportCrash(
84+ @@ -144,6 +150,10 @@ MOZ_MAYBE_UNUSED static MOZ_COLD MOZ_NEVER_INLINE void MOZ_ReportCrash(
9185 __android_log_print(ANDROID_LOG_FATAL, "MOZ_CRASH",
9286 "[%d] Hit MOZ_CRASH(%s) at %s:%d\n", MOZ_GET_PID(), aStr,
9387 aFilename, aLine);
88+ + #elif defined(OHOS)
89+ + (void) OH_LOG_Print(LOG_APP, LOG_FATAL, 0, "MOZ_CRASH",
90+ + "Hit MOZ_CRASH(%{public}s), at %{public}s:%{public}d\n",
91+ + aStr, aFilename, aLine);
9492 # if defined(MOZ_DUMP_ASSERTION_STACK)
9593 MozWalkTheStackWithWriter(MOZ_CrashPrintFrame, CallerPC(),
9694 /* aMaxFrames */ 0);
97- # endif
98- + #elif defined(XP_OHOS)
99- + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */, 0, "MOZ_CRASH",
100- + "Hit MOZ_CRASH(%{public}s), at %{public}s:%{public}d\n",
101- + aStr, aFilename, aLine);
102- #else
10395diff --git a/mfbt/DbgMacro.h b/mfbt/DbgMacro.h
10496index 3247b993c..c7039d5f8 100644
10597--- a/mfbt/DbgMacro.h
10698+++ b/mfbt/DbgMacro.h
107- @@ -18,8 +18,13 @@
99+ @@ -18,8 +18,10 @@
108100 template <typename T>
109101 class nsTSubstring;
110102
111103- #ifdef ANDROID
112104+ #if defined(ANDROID)
113105 # include <android/log.h>
114- + #elif defined(XP_OHOS)
115- + MOZ_BEGIN_EXTERN_C
116- + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
117- + __attribute__((__format__(os_log, 5, 6)));
118- + MOZ_END_EXTERN_C
106+ + #elif defined(OHOS)
107+ + # include <hilog/log.h>
119108 #endif
120109
121110 namespace mozilla {
@@ -126,41 +115,35 @@ index 3247b993c..c7039d5f8 100644
126115- #ifdef ANDROID
127116+ #if defined(ANDROID)
128117 __android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", s.str().c_str());
129- + #elif defined(XP_OHOS )
130- + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */ , 0, "Gecko", "%{public}s\n", s.str().c_str());
118+ + #elif defined(OHOS )
119+ + (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", "%{public}s\n", s.str().c_str());
131120 #else
132121 fputs(s.str().c_str(), stderr);
133122 #endif
134123diff --git a/mozglue/misc/Debug.cpp b/mozglue/misc/Debug.cpp
135124index c3a2ca89e..3fea33f4b 100644
136125--- a/mozglue/misc/Debug.cpp
137126+++ b/mozglue/misc/Debug.cpp
138- @@ -18,9 +18,14 @@
127+ @@ -18,9 +18,11 @@
139128
140129 #ifdef ANDROID
141130 # include <android/log.h>
142- + #elif defined(XP_OHOS)
143- + extern "C" {
144- + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
145- + __attribute__((__format__(os_log, 5, 6)));
146- + }
131+ + #elif defined(OHOS)
132+ + # include <hilog/log.h>
147133 #endif
148134
149135- #ifndef ANDROID
150- + #if ! (defined(ANDROID) || defined(XP_OHOS ))
136+ + #if ! (defined(ANDROID) || defined(OHOS ))
151137 static void vprintf_stderr_buffered(const char* aFmt, va_list aArgs) {
152138 // Avoid interleaving by writing to an on-stack buffer and then writing in one
153139 // go with fputs, as long as the output fits into the buffer.
154- @@ -66,6 +68,13 @@ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
140+ @@ -66,6 +68,10 @@ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
155141 MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
156142 __android_log_vprint(ANDROID_LOG_INFO, "Gecko", aFmt, aArgs);
157143 }
158- + #elif defined(XP_OHOS )
144+ + #elif defined(OHOS )
159145+ MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
160- + // OH_LOG_VPrint is available with API-level 18 (19?) or higher.
161- + char buffer[1024];
162- + VsprintfBuf(buffer, 1024, aFmt, aArgs);
163- + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, 0, "Gecko", "%{public}s", buffer);
146+ + (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "Gecko", aFmt, aArgs);
164147+ }
165148 #elif defined(FUZZING_SNAPSHOT)
166149 MFBT_API void vprintf_stderr(const char* aFmt, va_list aArgs) {
@@ -170,15 +153,15 @@ index c3a2ca89e..3fea33f4b 100644
170153
171154 MFBT_API void print_stderr(std::stringstream& aStr) {
172155- #if defined(ANDROID)
173- + #if defined(ANDROID) || defined(XP_OHOS )
156+ + #if defined(ANDROID) || defined(OHOS )
174157 // On Android logcat output is truncated to 1024 chars per line, and
175158 // we usually use std::stringstream to build up giant multi-line gobs
176159 // of output. So to avoid the truncation we find the newlines and
177160 // print the lines individually.
178161 std::string line;
179162 while (std::getline(aStr, line)) {
180- + # ifdef XP_OHOS
181- + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */, 0, "Gecko", " %{public}s", line.c_str());
163+ + # ifdef OHOS
164+ + printf_stderr(" %{public}s\n ", line.c_str());
182165+ # else
183166 printf_stderr("%s\n", line.c_str());
184167+ # endif
@@ -189,31 +172,30 @@ diff --git a/nsprpub/pr/src/io/prlog.c b/nsprpub/pr/src/io/prlog.c
189172index 52bd6abc5..781402d56 100644
190173--- a/nsprpub/pr/src/io/prlog.c
191174+++ b/nsprpub/pr/src/io/prlog.c
192- @@ -8,8 +8,11 @@
175+ @@ -8,8 +8,10 @@
193176 #include "prenv.h"
194177 #include "prprf.h"
195178 #include <string.h>
196179- #ifdef ANDROID
197180+ #if defined(ANDROID)
198181 # include <android/log.h>
199- + #elif defined(XP_OHOS)
200- + int OH_LOG_Print(unsigned int type, unsigned int level, unsigned int domain, const char *tag, const char *fmt, ...)
201- + __attribute__((__format__(os_log, 5, 6)));
182+ + #elif defined(OHOS)
183+ + # include <hilog/log.h>
202184 #endif
203185
204186 /*
205187@@ -108,6 +110,19 @@ static void OutputDebugStringA(const char* msg) {
206188 PR_Write(fd, buf, nb); \
207189 } \
208190 PR_END_MACRO
209- + #elif defined(XP_OHOS )
210- + # define _PUT_LOG(fd, buf, nb) \
191+ + #elif defined(OHOS )
192+ + #define _PUT_LOG(fd, buf, nb) \
211193+ PR_BEGIN_MACRO \
212194+ if (fd == _pr_stderr) { \
213195+ char savebyte = buf[nb]; \
214196+ buf[nb] = '\0'; \
215- + (void) OH_LOG_Print(0 /* LOG_APP */, 4 /* LOG_INFO */ , \
216- + 0, "PRLog", "%{public}s\n", buf); \
197+ + (void) OH_LOG_Print(LOG_APP, LOG_INFO, 0, "PRLog" , \
198+ + "%{public}s\n", buf); \
217199+ buf[nb] = savebyte; \
218200+ } else { \
219201+ PR_Write(fd, buf, nb); \
@@ -226,17 +208,17 @@ index 52bd6abc5..781402d56 100644
226208 PR_LogPrint("Aborting");
227209 #ifdef ANDROID
228210 __android_log_write(ANDROID_LOG_ERROR, "PRLog", "Aborting");
229- + #elif defined(XP_OHOS )
230- + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "PRLog", "Aborting\n");
211+ + #elif defined(OHOS )
212+ + (void) OH_LOG_Print(LOG_APP, LOG_ERROR , 0, "PRLog", "Aborting\n");
231213 #endif
232214 abort();
233215 }
234216@@ -567,6 +584,9 @@ PR_IMPLEMENT(void) PR_Assert(const char *s, const char *file, PRIntn ln)
235217 #elif defined(ANDROID)
236218 __android_log_assert(NULL, "PRLog", "Assertion failure: %s, at %s:%d\n", s,
237219 file, ln);
238- + #elif defined(XP_OHOS )
239- + (void) OH_LOG_Print(0 /* LOG_APP */, 7 /* LOG_FATAL */ , 0, "PRLog",
220+ + #elif defined(OHOS )
221+ + (void) OH_LOG_Print(LOG_APP, LOG_ERROR , 0, "PRLog",
240222+ "Assertion failure: %{public}s, at %{public}s:%{public}d\n",s, file, ln);
241223 #endif
242224 abort();
0 commit comments