Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / third_party / libjingle / overrides / allocator_shim / allocator_stub.cc
blob1e23d821a5d3ca5d78620251abee38427c7909f3
1 // Copyright 2013 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.
5 #include <new>
7 #include "talk/base/basictypes.h"
10 typedef void* (*AllocateFunction)(std::size_t);
11 typedef void (*DellocateFunction)(void*);
13 #ifdef LIBPEERCONNECTION_IMPLEMENTATION
14 #error "Only compile the allocator stub with the client implementation"
15 #endif
17 #ifdef WIN32
18 #define ALLOC_IMPORT __declspec(dllimport)
19 #else
20 #define ALLOC_IMPORT
21 #endif
23 // The stub implementations that forward new / delete calls to the allocator
24 // in the current binary (usually tcmalloc).
26 static void* Allocate(std::size_t n) {
27 return operator new(n);
30 static void Dellocate(void* p) {
31 return operator delete(p);
34 ALLOC_IMPORT
35 bool SetProxyAllocator(AllocateFunction a, DellocateFunction d);
37 // Initialize the proxy by supplying it with a pointer to our
38 // allocator/deallocator routines.
39 // This unfortunately costs a single static initializer. The alternatives
40 // are:
41 // * A circular reference from libjingle back to chrome (or any other binary)
42 // * Reworking libjingle interfaces to not use stl types in classinterfaces.
43 // This is currently not feasible.
44 // * Hack internal peerconnectionfactory implementation details such as
45 // PeerConnectionFactory::Initialize to initialize the proxy. While possible,
46 // this would be very prone to regressions due to any changes in the libjingle
47 // library.
48 // * Make modifications to libjingle to support initializing the proxy when
49 // needed. I'm (tommi) currently working on this.
50 static const bool proxy_allocator_initialized =
51 SetProxyAllocator(&Allocate, &Dellocate);
53 // Include the implementation of peerconnectionfactory.cc here.
54 // This is done to ensure that the stub initialization code and
55 // peerconnectionfactory belong to the same object file. That way the
56 // linker cannot discard the necessary stub initialization code that goes with
57 // the factory, even though there aren't any explicit dependencies.
58 // See libjingle.gyp for how we exclude peerconnectionfactory.cc from the
59 // target in this case.
60 #include "talk/app/webrtc/peerconnectionfactory.cc"