Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. diff --git a/src/corelib/kernel/qcore_mac.cpp b/src/corelib/kernel/qcore_mac.cpp
  2. index e7d0a99..4912104 100644
  3. --- a/src/corelib/kernel/qcore_mac.cpp
  4. +++ b/src/corelib/kernel/qcore_mac.cpp
  5. @@ -66,10 +66,56 @@ QCFString::operator QString() const
  6. return string;
  7. }
  8.  
  9. +#include <QHash>
  10. +QHash<const void*, int> pointerMap;
  11. +
  12. +extern QHash<const void*, int> getPointerMap() { return ::pointerMap; }
  13. +
  14. +const void *retain(const void *info)
  15. +{
  16. + qDebug("my retain");
  17. + pointerMap.insert(info, pointerMap.value(info)+1);
  18. +}
  19. +
  20. +void release(const void *info)
  21. +{
  22. + qDebug("my release");
  23. + pointerMap.insert(info, pointerMap.value(info)-1);
  24. + free(const_cast<void *>(info));
  25. +}
  26. +
  27. +void * myAlloc(CFIndex size, CFOptionFlags hint, void *info)
  28. +{
  29. + qDebug("my alloc");
  30. +// Q_ASSERT(false);
  31. + if (size <= 0)
  32. + return NULL;
  33. + return malloc(size);
  34. +}
  35. +
  36. +static CFAllocatorRef myAllocator(void) {
  37. + static CFAllocatorRef allocator = NULL;
  38. + if (!allocator) {
  39. + CFAllocatorContext context =
  40. + {0, NULL, retain, release, /*(void *)(void (*)(const void*))free,*/ NULL,
  41. + myAlloc,
  42. + NULL,
  43. + NULL,
  44. + NULL};
  45. + context.info = malloc(sizeof(int));
  46. + allocator = CFAllocatorCreate(NULL, &context);
  47. + }
  48. + return allocator;
  49. +}
  50. +
  51. CFStringRef QCFString::toCFStringRef(const QString &string)
  52. {
  53. - return CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar *>(string.unicode()),
  54. - string.length());
  55. + CFAllocatorRef myAllocPtr = myAllocator();
  56. + CFAllocatorRef myDeallocPtr = myAllocator();
  57. + ushort *buf = (ushort *)malloc(string.length() * sizeof(ushort));
  58. + memcpy(buf, reinterpret_cast<const ushort *>(string.constData()), string.length() * sizeof(ushort));
  59. + return CFStringCreateWithCharactersNoCopy(myAllocPtr, reinterpret_cast<const UniChar *>(buf),
  60. + string.length(), myDeallocPtr);
  61. }
  62.  
  63. QCFString::operator CFStringRef() const
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement