Ticket #8708: archivable_fix.patch

File archivable_fix.patch, 3.3 KB (added by anevilyak, 8 years ago)
  • src/kits/support/Archivable.cpp

    diff --git a/src/kits/support/Archivable.cpp b/src/kits/support/Archivable.cpp
    index 2bcb515..3dace71 100644
    a b check_signature(const char* signature, image_info& info)  
    236236}
    237237
    238238
     239namespace BPrivate
     240{
     241
     242
     243instantiation_func
     244find_instantiation_func(const char* className, const char* signature,
     245    image_id* id)
     246{
     247    if (className == NULL) {
     248        errno = B_BAD_VALUE;
     249        return NULL;
     250    }
     251
     252    thread_info threadInfo;
     253    status_t err = get_thread_info(find_thread(NULL), &threadInfo);
     254    if (err != B_OK) {
     255        errno = err;
     256        return NULL;
     257    }
     258
     259    instantiation_func instantiationFunc = NULL;
     260    image_info imageInfo;
     261
     262    BString name = className;
     263    for (int32 pass = 0; pass < 2; pass++) {
     264        BString funcName;
     265        build_function_name(name, funcName);
     266
     267        // for each image_id in team_id
     268        int32 cookie = 0;
     269        while (instantiationFunc == NULL
     270            && get_next_image_info(threadInfo.team, &cookie, &imageInfo)
     271                == B_OK) {
     272            instantiationFunc = find_function_in_image(funcName, imageInfo.id,
     273                err);
     274        }
     275        if (instantiationFunc != NULL) {
     276            // if requested, save the image id in
     277            // which the function was found
     278            if (id != NULL)
     279                *id = imageInfo.id;
     280            break;
     281        }
     282
     283        // Check if we have a private class, and add the BPrivate namespace
     284        // (for backwards compatibility)
     285        if (!add_private_namespace(name))
     286            break;
     287    }
     288
     289    if (instantiationFunc != NULL
     290        && check_signature(signature, imageInfo) != B_OK)
     291        return NULL;
     292
     293    return instantiationFunc;
     294}
     295
     296
     297}
     298
     299
    239300//  #pragma mark -
    240301
    241302
    instantiate_object(BMessage* archive, image_id* _id)  
    597658    const char* signature = NULL;
    598659    bool hasSignature = archive->FindString(B_ADD_ON_FIELD, &signature) == B_OK;
    599660
    600     instantiation_func instantiationFunc = find_instantiation_func(className,
    601         signature);
     661    instantiation_func instantiationFunc = BPrivate::find_instantiation_func(
     662        className, signature, _id);
    602663
    603664    // if find_instantiation_func() can't locate Class::Instantiate()
    604665    // and a signature was specified
    validate_instantiation(BMessage* from, const char* className)  
    714775instantiation_func
    715776find_instantiation_func(const char* className, const char* signature)
    716777{
    717     if (className == NULL) {
    718         errno = B_BAD_VALUE;
    719         return NULL;
    720     }
    721 
    722     thread_info threadInfo;
    723     status_t err = get_thread_info(find_thread(NULL), &threadInfo);
    724     if (err != B_OK) {
    725         errno = err;
    726         return NULL;
    727     }
    728 
    729     instantiation_func instantiationFunc = NULL;
    730     image_info imageInfo;
    731 
    732     BString name = className;
    733     for (int32 pass = 0; pass < 2; pass++) {
    734         BString funcName;
    735         build_function_name(name, funcName);
    736 
    737         // for each image_id in team_id
    738         int32 cookie = 0;
    739         while (instantiationFunc == NULL
    740             && get_next_image_info(threadInfo.team, &cookie, &imageInfo)
    741                 == B_OK) {
    742             instantiationFunc = find_function_in_image(funcName, imageInfo.id,
    743                 err);
    744         }
    745         if (instantiationFunc != NULL)
    746             break;
    747 
    748         // Check if we have a private class, and add the BPrivate namespace
    749         // (for backwards compatibility)
    750         if (!add_private_namespace(name))
    751             break;
    752     }
    753 
    754     if (instantiationFunc != NULL
    755         && check_signature(signature, imageInfo) != B_OK)
    756         return NULL;
    757 
    758     return instantiationFunc;
     778    return BPrivate::find_instantiation_func(className, signature, NULL);
    759779}
    760780
    761781