⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 275042 in webkit


Ignore:
Timestamp:
Mar 25, 2021, 10:06:29 AM (5 years ago)
Author:
Carlos Garcia Campos
Message:

Merge r274479 - [GTK][WPE] Stop using g_memdup
https://bugs.webkit.org/show_bug.cgi?id=223189

Reviewed by Philippe Normand.

Source/WebCore:

Add gstBufferNewWrappedFast() to create a GstBuffer wrapping data allocated with fast malloc and use it when
possible in combination with fastMemDup() instead of g_memdup().

  • platform/graphics/gstreamer/GStreamerCommon.cpp:

(WebCore::gstBufferNewWrappedFast):

  • platform/graphics/gstreamer/GStreamerCommon.h:
  • platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:

(CachedResourceStreamingClient::dataReceived):

  • platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp:

(WebCore::RealtimeIncomingAudioSourceLibWebRTC::OnData):

  • platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:

Source/WebKit:

  • UIProcess/API/glib/WebKitWebResource.cpp:

(webkit_web_resource_get_data_finish): Use g_malloc + memcpy instead of g_memdup.

  • UIProcess/API/glib/WebKitWebView.cpp:

(webkit_web_view_save_finish): Use fastMemDup instead g_memdup.

Source/WTF:

Add fastMemDup() to replace g_memdup() that is now deprecated in GLib because of the possibility of overflow
when converting from size_t to unsigned int. There's a replacement in GLib already, but we would need to depend
on very new GLib version, so better use fastMemDup() when possible. In cases where we still need to use GLib
allocator, we can simply call g_malloc() + memcpy().

  • wtf/FastMalloc.cpp:

(WTF::fastMemDup):

  • wtf/FastMalloc.h:
Location:
releases/WebKitGTK/webkit-2.32/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • releases/WebKitGTK/webkit-2.32/Source/WTF/ChangeLog

    r275030 r275042  
     12021-03-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][WPE] Stop using g_memdup
     4        https://bugs.webkit.org/show_bug.cgi?id=223189
     5
     6        Reviewed by Philippe Normand.
     7
     8        Add fastMemDup() to replace g_memdup() that is now deprecated in GLib because of the possibility of overflow
     9        when converting from size_t to unsigned int. There's a replacement in GLib already, but we would need to depend
     10        on very new GLib version, so better use fastMemDup() when possible. In cases where we still need to use GLib
     11        allocator, we can simply call g_malloc() + memcpy().
     12
     13        * wtf/FastMalloc.cpp:
     14        (WTF::fastMemDup):
     15        * wtf/FastMalloc.h:
     16
    1172021-03-25  Alberto Garcia  <berto@igalia.com>
    218
  • releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.cpp

    r265735 r275042  
    9898}
    9999
     100void* fastMemDup(const void* mem, size_t bytes)
     101{
     102    if (!mem || !bytes)
     103        return nullptr;
     104
     105    void* result = fastMalloc(bytes);
     106    memcpy(result, mem, bytes);
     107    return result;
     108}
     109
    100110TryMallocReturnValue tryFastZeroedMalloc(size_t n)
    101111{
  • releases/WebKitGTK/webkit-2.32/Source/WTF/wtf/FastMalloc.h

    r260409 r275042  
    9494WTF_EXPORT_PRIVATE void* fastRealloc(void*, size_t) RETURNS_NONNULL;
    9595WTF_EXPORT_PRIVATE char* fastStrDup(const char*) RETURNS_NONNULL;
     96WTF_EXPORT_PRIVATE void* fastMemDup(const void*, size_t);
    9697
    9798WTF_EXPORT_PRIVATE TryMallocReturnValue tryFastMalloc(size_t);
     
    309310using WTF::fastMallocGoodSize;
    310311using WTF::fastMallocSize;
     312using WTF::fastMemDup;
    311313using WTF::fastRealloc;
    312314using WTF::fastStrDup;
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/ChangeLog

    r275041 r275042  
     12021-03-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][WPE] Stop using g_memdup
     4        https://bugs.webkit.org/show_bug.cgi?id=223189
     5
     6        Reviewed by Philippe Normand.
     7
     8        Add gstBufferNewWrappedFast() to create a GstBuffer wrapping data allocated with fast malloc and use it when
     9        possible in combination with fastMemDup() instead of g_memdup().
     10
     11        * platform/graphics/gstreamer/GStreamerCommon.cpp:
     12        (WebCore::gstBufferNewWrappedFast):
     13        * platform/graphics/gstreamer/GStreamerCommon.h:
     14        * platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp:
     15        (CachedResourceStreamingClient::dataReceived):
     16        * platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp:
     17        (WebCore::RealtimeIncomingAudioSourceLibWebRTC::OnData):
     18        * platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp:
     19
    1202021-03-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    221
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp

    r273311 r275042  
    504504}
    505505
     506GstBuffer* gstBufferNewWrappedFast(void* data, size_t length)
     507{
     508    return gst_buffer_new_wrapped_full(static_cast<GstMemoryFlags>(0), data, length, 0, length, data, fastFree);
     509}
     510
    506511}
    507512
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h

    r271512 r275042  
    301301});
    302302
     303GstBuffer* gstBufferNewWrappedFast(void* data, size_t length);
     304
    303305}
    304306
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/graphics/gstreamer/WebKitWebSourceGStreamer.cpp

    r272908 r275042  
    11241124    checkUpdateBlocksize(length);
    11251125
    1126     GstBuffer* buffer = gst_buffer_new_wrapped(g_memdup(data, length), length);
     1126    GstBuffer* buffer = gstBufferNewWrappedFast(fastMemDup(data, length), length);
    11271127    gst_adapter_push(members->adapter.get(), buffer);
    11281128    stopLoaderIfNeeded(src, members);
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp

    r269849 r275042  
    6666
    6767    auto bufferSize = GST_AUDIO_INFO_BPF(&info) * numberOfFrames;
    68     gpointer bufferData = g_malloc(bufferSize);
     68    gpointer bufferData = fastMalloc(bufferSize);
    6969    if (muted())
    7070        gst_audio_format_fill_silence(info.finfo, bufferData, bufferSize);
     
    7272        memcpy(bufferData, audioData, bufferSize);
    7373
    74     auto buffer = adoptGRef(gst_buffer_new_wrapped(bufferData, bufferSize));
     74    auto buffer = adoptGRef(gstBufferNewWrappedFast(bufferData, bufferSize));
    7575    auto caps = adoptGRef(gst_audio_info_to_caps(&info));
    7676    auto sample = adoptGRef(gst_sample_new(buffer.get(), caps.get(), nullptr, nullptr));
  • releases/WebKitGTK/webkit-2.32/Source/WebCore/platform/mediastream/libwebrtc/GStreamerVideoDecoderFactory.cpp

    r271396 r275042  
    222222
    223223        // FIXME- Use a GstBufferPool.
    224         auto buffer = adoptGRef(gst_buffer_new_wrapped(g_memdup(inputImage.data(), inputImage.size()),
     224        auto buffer = adoptGRef(gstBufferNewWrappedFast(fastMemDup(inputImage.data(), inputImage.size()),
    225225            inputImage.size()));
    226226        GST_BUFFER_DTS(buffer.get()) = (static_cast<guint64>(inputImage.Timestamp()) * GST_MSECOND) - m_firstBufferDts;
  • releases/WebKitGTK/webkit-2.32/Source/WebKit/ChangeLog

    r275041 r275042  
     12021-03-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK][WPE] Stop using g_memdup
     4        https://bugs.webkit.org/show_bug.cgi?id=223189
     5
     6        Reviewed by Philippe Normand.
     7
     8        * UIProcess/API/glib/WebKitWebResource.cpp:
     9        (webkit_web_resource_get_data_finish): Use g_malloc + memcpy instead of g_memdup.
     10        * UIProcess/API/glib/WebKitWebView.cpp:
     11        (webkit_web_view_save_finish): Use fastMemDup instead g_memdup.
     12
    1132021-03-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    214
  • releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebResource.cpp

    r272991 r275042  
    402402guchar* webkit_web_resource_get_data_finish(WebKitWebResource* resource, GAsyncResult* result, gsize* length, GError** error)
    403403{
    404     g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(resource), 0);
    405     g_return_val_if_fail(g_task_is_valid(result, resource), 0);
     404    g_return_val_if_fail(WEBKIT_IS_WEB_RESOURCE(resource), nullptr);
     405    g_return_val_if_fail(g_task_is_valid(result, resource), nullptr);
    406406
    407407    GTask* task = G_TASK(result);
    408408    if (!g_task_propagate_boolean(task, error))
    409         return 0;
     409        return nullptr;
    410410
    411411    ResourceGetDataAsyncData* data = static_cast<ResourceGetDataAsyncData*>(g_task_get_task_data(task));
    412412    if (length)
    413413        *length = data->webData->size();
    414     return static_cast<guchar*>(g_memdup(data->webData->bytes(), data->webData->size()));
    415 }
     414
     415    auto* bytes = data->webData->bytes();
     416    if (!bytes || !data->webData->size())
     417        return nullptr;
     418
     419    auto* returnValue = g_malloc(data->webData->size());
     420    memcpy(returnValue, bytes, data->webData->size());
     421    return static_cast<guchar*>(returnValue);
     422}
  • releases/WebKitGTK/webkit-2.32/Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp

    r272636 r275042  
    41974197    gsize length = data->webData->size();
    41984198    if (length)
    4199         g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(dataStream), g_memdup(data->webData->bytes(), length), length, g_free);
     4199        g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(dataStream), fastMemDup(data->webData->bytes(), length), length, fastFree);
    42004200
    42014201    return dataStream;
Note: See TracChangeset for help on using the changeset viewer.