Skip to content

Commit 7e74953

Browse files
committed
Test fix attempt
1 parent 74b16c1 commit 7e74953

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

clang/test/Analysis/Checkers/WebKit/mock-types.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,55 +313,67 @@ class UniqueRef {
313313
UniqueRef &operator=(T &) { return *this; }
314314
};
315315

316-
template <typename T>
317316
class WeakPtrImpl {
318317
private:
319-
void* ptr;
318+
void* ptr { nullptr };
319+
mutable unsigned m_refCount { 0 };
320320

321321
template <typename U> friend class CanMakeWeakPtr;
322322
template <typename U> friend class WeakPtr;
323323

324-
Ref<WeakPtrImpl<T>> create(T& t)
324+
public:
325+
template <typename T>
326+
static Ref<WeakPtrImpl> create(T& t)
325327
{
326-
return adoptNS(new WeakPtrImpl<T>(t));
328+
return adoptRef(*new WeakPtrImpl(t));
327329
}
328330

331+
void ref() const { m_refCount++; }
332+
void deref() const {
333+
m_refCount--;
334+
if (!m_refCount)
335+
delete const_cast<WeakPtrImpl*>(this);
336+
}
337+
338+
template <typename T>
329339
T* get() { return static_cast<T*>(ptr); }
330340
operator bool() const { return !!ptr; }
331341
void clear() { ptr = nullptr; }
332342

333-
WeakPtrImpl(T& t)
343+
private:
344+
template <typename T>
345+
WeakPtrImpl(T* t)
334346
: ptr(static_cast<void*>(t))
335347
{ }
336348
};
337349

338350
template <typename T>
339351
class CanMakeWeakPtr {
340352
private:
341-
RefPtr<WeakPtrImpl<T>> impl;
353+
RefPtr<WeakPtrImpl> impl;
342354

343355
template <typename U> friend class CanMakeWeakPtr;
344356
template <typename U> friend class WeakPtr;
345357

346-
Ref<WeakPtrImpl<T>> createWeakPtrImpl() {
358+
Ref<WeakPtrImpl> createWeakPtrImpl() {
347359
if (!impl)
348-
impl = WeakPtrImpl<T>::create(static_cast<T>(*this));
360+
impl = WeakPtrImpl::create(static_cast<T>(*this));
349361
return *impl;
350362
}
351363

352364
public:
353365
~CanMakeWeakPtr() {
354366
if (!impl)
355367
return;
356-
impl->ptr = nullptr;
368+
impl->clear();
357369
impl = nullptr;
358370
}
359371
};
360372

361373
template <typename T>
362374
class WeakPtr {
363375
private:
364-
RefPtr<WeakPtrImpl<T>> impl;
376+
RefPtr<WeakPtrImpl> impl;
365377

366378
public:
367379
WeakPtr(T& t) {
@@ -382,7 +394,7 @@ class WeakPtr {
382394
}
383395

384396
T* get() {
385-
return impl ? impl->get() : nullptr;
397+
return impl ? impl->get<T>() : nullptr;
386398
}
387399

388400
};

0 commit comments

Comments
 (0)