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.
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"
18 #define ALLOC_IMPORT __declspec(dllimport)
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
);
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
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
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"