Ignore:
Timestamp:
Sep 7, 2017, 1:14:30 AM (8 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Remove "malloc" and "free" from JSC/API
https://bugs.webkit.org/show_bug.cgi?id=176331

Reviewed by Keith Miller.

Remove "malloc" and "free" manual calls in JSC/API.

  • API/JSValue.mm:

(createStructHandlerMap):

  • API/JSWrapperMap.mm:

(parsePropertyAttributes):
(makeSetterName):
(copyPrototypeProperties):
Use RetainPtr<NSString> to keep NSString. We avoid repeated "char*" to "NSString" conversion.

  • API/ObjcRuntimeExtras.h:

(adoptSystem):
Add adoptSystem to automate calling system free().

(protocolImplementsProtocol):
(forEachProtocolImplementingProtocol):
(forEachMethodInClass):
(forEachMethodInProtocol):
(forEachPropertyInProtocol):
(StringRange::StringRange):
(StringRange::operator const char* const):
(StringRange::get const):
Use CString for backend.

(StructBuffer::StructBuffer):
(StructBuffer::~StructBuffer):
(StringRange::~StringRange): Deleted.
Use fastAlignedMalloc/astAlignedFree to get aligned memory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSValue.mm

    r211247 r221723  
    10551055        char idType[3];
    10561056        // Check 2nd argument type is "@"
    1057         char* secondType = method_copyArgumentType(method, 3);
    1058         if (strcmp(secondType, "@") != 0) {
    1059             free(secondType);
    1060             return;
     1057        {
     1058            auto secondType = adoptSystem<char[]>(method_copyArgumentType(method, 3));
     1059            if (strcmp(secondType.get(), "@") != 0)
     1060                return;
    10611061        }
    1062         free(secondType);
    10631062        // Check result type is also "@"
    10641063        method_getReturnType(method, idType, 3);
    10651064        if (strcmp(idType, "@") != 0)
    10661065            return;
    1067         char* type = method_copyArgumentType(method, 2);
    1068         structHandlers->add(StringImpl::create(type), (StructTagHandler){ selector, 0 });
    1069         free(type);
     1066        {
     1067            auto type = adoptSystem<char[]>(method_copyArgumentType(method, 2));
     1068            structHandlers->add(StringImpl::create(type.get()), (StructTagHandler) { selector, 0 });
     1069        }
    10701070    });
    10711071
     
    10821082            return;
    10831083        // Try to find a matching valueWith<Foo>:context: method.
    1084         char* type = method_copyReturnType(method);
    1085 
    1086         StructHandlers::iterator iter = structHandlers->find(type);
    1087         free(type);
     1084        auto type = adoptSystem<char[]>(method_copyReturnType(method));
     1085        StructHandlers::iterator iter = structHandlers->find(type.get());
    10881086        if (iter == structHandlers->end())
    10891087            return;
Note: See TracChangeset for help on using the changeset viewer.