Flutter Engine
The Flutter Engine
third_party
accessibility
base
win
scoped_bstr.cc
Go to the documentation of this file.
1
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#include "
base/win/scoped_bstr.h
"
6
7
#include <cstdint>
8
9
#include "
base/logging.h
"
10
#include "
base/numerics/safe_conversions.h
"
11
12
namespace
base
{
13
namespace
win {
14
15
namespace
{
16
17
BSTR AllocBstrOrDie(std::wstring_view non_bstr) {
18
BSTR
result
= ::SysAllocStringLen(non_bstr.data(),
19
checked_cast<UINT>(non_bstr.length()));
20
if
(!
result
)
21
std::abort();
22
return
result
;
23
}
24
25
BSTR AllocBstrBytesOrDie(
size_t
bytes) {
26
BSTR
result
= ::SysAllocStringByteLen(
nullptr
, checked_cast<UINT>(bytes));
27
if
(!
result
)
28
std::abort();
29
return
result
;
30
}
31
32
}
// namespace
33
34
ScopedBstr::ScopedBstr
(std::wstring_view non_bstr)
35
: bstr_(AllocBstrOrDie(non_bstr)) {}
36
37
ScopedBstr::~ScopedBstr
() {
38
static_assert
(
sizeof
(
ScopedBstr
) ==
sizeof
(BSTR),
"ScopedBstrSize"
);
39
::SysFreeString(bstr_);
40
}
41
42
void
ScopedBstr::Reset
(BSTR bstr) {
43
if
(bstr != bstr_) {
44
// SysFreeString handles null properly.
45
::SysFreeString(bstr_);
46
bstr_ = bstr;
47
}
48
}
49
50
BSTR
ScopedBstr::Release
() {
51
BSTR bstr = bstr_;
52
bstr_ =
nullptr
;
53
return
bstr;
54
}
55
56
void
ScopedBstr::Swap
(
ScopedBstr
& bstr2) {
57
BSTR tmp = bstr_;
58
bstr_ = bstr2.bstr_;
59
bstr2.bstr_ = tmp;
60
}
61
62
BSTR*
ScopedBstr::Receive
() {
63
BASE_DCHECK
(!bstr_) <<
"BSTR leak."
;
64
return
&bstr_;
65
}
66
67
BSTR
ScopedBstr::Allocate
(std::wstring_view str) {
68
Reset
(AllocBstrOrDie(str));
69
return
bstr_;
70
}
71
72
BSTR
ScopedBstr::AllocateBytes
(
size_t
bytes) {
73
Reset
(AllocBstrBytesOrDie(bytes));
74
return
bstr_;
75
}
76
77
void
ScopedBstr::SetByteLen
(
size_t
bytes) {
78
BASE_DCHECK
(bstr_);
79
uint32_t*
data
=
reinterpret_cast<
uint32_t*
>
(bstr_);
80
data
[-1] = checked_cast<uint32_t>(bytes);
81
}
82
83
size_t
ScopedBstr::Length
()
const
{
84
return ::SysStringLen(bstr_);
85
}
86
87
size_t
ScopedBstr::ByteLength
()
const
{
88
return ::SysStringByteLen(bstr_);
89
}
90
91
}
// namespace win
92
}
// namespace base
base::win::ScopedBstr
Definition:
scoped_bstr.h:22
base::win::ScopedBstr::Receive
BSTR * Receive()
Definition:
scoped_bstr.cc:62
base::win::ScopedBstr::Allocate
BSTR Allocate(std::wstring_view str)
Definition:
scoped_bstr.cc:67
base::win::ScopedBstr::ByteLength
size_t ByteLength() const
Definition:
scoped_bstr.cc:87
base::win::ScopedBstr::~ScopedBstr
~ScopedBstr()
Definition:
scoped_bstr.cc:37
base::win::ScopedBstr::SetByteLen
void SetByteLen(size_t bytes)
Definition:
scoped_bstr.cc:77
base::win::ScopedBstr::Release
BSTR Release()
Definition:
scoped_bstr.cc:50
base::win::ScopedBstr::Reset
void Reset(BSTR bstr=nullptr)
Definition:
scoped_bstr.cc:42
base::win::ScopedBstr::Swap
void Swap(ScopedBstr &bstr2)
Definition:
scoped_bstr.cc:56
base::win::ScopedBstr::AllocateBytes
BSTR AllocateBytes(size_t bytes)
Definition:
scoped_bstr.cc:72
base::win::ScopedBstr::Length
size_t Length() const
Definition:
scoped_bstr.cc:83
base::win::ScopedBstr::ScopedBstr
ScopedBstr()=default
result
GAsyncResult * result
Definition:
fl_text_input_plugin.cc:106
base
Definition:
ax_tree_id_registry.h:17
safe_conversions.h
scoped_bstr.h
data
std::shared_ptr< const fml::Mapping > data
Definition:
texture_gles.cc:63
logging.h
BASE_DCHECK
#define BASE_DCHECK(condition)
Definition:
logging.h:63
Generated on Sun Jun 23 2024 21:55:21 for Flutter Engine by
1.9.4