Clean up HiiLib.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5481 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2008-07-16 01:22:51 +00:00
parent 631c199143
commit 29870c8d61
3 changed files with 39 additions and 19 deletions

View File

@ -124,7 +124,6 @@ HiiLibGetSupportedLanguages (
UINTN BufferSize;
CHAR8 *LanguageString;
ASSERT (HiiHandle != NULL);
ASSERT (IsHiiHandleRegistered (HiiHandle));
//
// Collect current supported Languages for given HII handle
@ -140,7 +139,7 @@ HiiLibGetSupportedLanguages (
Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);
if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (LanguageString);
FreePool (LanguageString);
LanguageString = AllocateZeroPool (BufferSize);
if (LanguageString == NULL) {
return NULL;
@ -190,7 +189,7 @@ HiiLibGetSupportedLanguageNumber (
HiiLibGetNextLanguage (&LanguageString, Lang);
LangNumber++;
}
gBS->FreePool (Languages);
FreePool (Languages);
return LangNumber;
}
@ -235,7 +234,7 @@ HiiLibGetSupportedSecondaryLanguages (
Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (LanguageString);
FreePool (LanguageString);
LanguageString = AllocateZeroPool (BufferSize);
if (LanguageString == NULL) {
return NULL;

View File

@ -32,6 +32,9 @@ LocateHiiProtocols (
EFI_STATUS Status;
if (mHiiProtocolsInitialized) {
//
// Only need to initialize the protocol instance once.
//
return;
}
@ -52,6 +55,13 @@ LocateHiiProtocols (
package header that defined by UEFI VFR compiler and StringGather
tool.
#pragma pack (push, 1)
typedef struct {
UINT32 BinaryLength;
EFI_HII_PACKAGE_HEADER PackageHeader;
} TIANO_AUTOGEN_PACKAGES_HEADER;
#pragma pack (pop)
If there is not enough resource for the new package list,
the function will ASSERT.
@ -86,6 +96,9 @@ InternalHiiLibPreparePackages (
for (Index = 0; Index < NumberOfPackages; Index++) {
CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32));
//
// Do not count the BinaryLength field.
//
PackageListLength += (PackageLength - sizeof (UINT32));
}
@ -95,6 +108,7 @@ InternalHiiLibPreparePackages (
PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER);
PackageListHeader = AllocateZeroPool (PackageListLength);
ASSERT (PackageListHeader != NULL);
CopyMem (&PackageListHeader->PackageListGuid, GuidId, sizeof (EFI_GUID));
PackageListHeader->PackageLength = PackageListLength;
@ -222,8 +236,6 @@ HiiLibAddPackages (
@param HiiHandle The handle that was previously registered to the data base that is requested for removal.
List later.
@return VOID
**/
VOID
EFIAPI
@ -232,7 +244,7 @@ HiiLibRemovePackages (
)
{
EFI_STATUS Status;
ASSERT (HiiHandle != NULL);
ASSERT (IsHiiHandleRegistered (HiiHandle));
LocateHiiProtocols ();
@ -328,6 +340,7 @@ HiiLibExtractGuidFromHiiHandle (
EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList;
ASSERT (Guid != NULL);
ASSERT (IsHiiHandleRegistered (Handle));
//
// Get HII PackageList
@ -355,7 +368,7 @@ HiiLibExtractGuidFromHiiHandle (
//
CopyMem (Guid, &HiiPackageList->PackageListGuid, sizeof (EFI_GUID));
gBS->FreePool (HiiPackageList);
FreePool (HiiPackageList);
return EFI_SUCCESS;
}
@ -425,7 +438,7 @@ HiiLibDevicePathToHiiHandle (
break;
}
}
gBS->FreePool (Handles);
FreePool (Handles);
if (DriverHandle == NULL) {
return NULL;
@ -447,7 +460,7 @@ HiiLibDevicePathToHiiHandle (
HiiHandles
);
if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (HiiHandles);
FreePool (HiiHandles);
HiiHandles = AllocatePool (BufferSize);
ASSERT (HiiHandles != NULL);
@ -461,7 +474,7 @@ HiiLibDevicePathToHiiHandle (
}
if (EFI_ERROR (Status)) {
gBS->FreePool (HiiHandles);
FreePool (HiiHandles);
return NULL;
}
@ -482,7 +495,7 @@ HiiLibDevicePathToHiiHandle (
}
}
gBS->FreePool (HiiHandles);
FreePool (HiiHandles);
return HiiHandle;
}

View File

@ -57,6 +57,10 @@ HiiLibNewString (
while (*LangStrings != 0) {
HiiLibGetNextLanguage (&LangStrings, Lang);
//
// For each language supported by the package,
// a string token is created.
//
Status = mHiiStringProt->NewString (
mHiiStringProt,
PackageList,
@ -119,6 +123,10 @@ HiiLibSetString (
while (*LangStrings != 0) {
HiiLibGetNextLanguage (&LangStrings, Lang);
//
// For each language supported by the package,
// the string is updated.
//
Status = mHiiStringProt->SetString (
mHiiStringProt,
PackageList,
@ -195,7 +203,7 @@ HiiLibGetStringFromToken (
Out:
if (HiiHandleBuffer != NULL) {
gBS->FreePool (HiiHandleBuffer);
FreePool (HiiHandleBuffer);
}
return Status;
}
@ -262,7 +270,7 @@ HiiLibGetString (
LangStrings = Languages;
HiiLibGetNextLanguage (&LangStrings, Lang);
gBS->FreePool (Languages);
FreePool (Languages);
Status = mHiiStringProt->GetString (
mHiiStringProt,
@ -318,7 +326,7 @@ HiiLibGetStringFromHandle (
Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize);
if (Status == EFI_BUFFER_TOO_SMALL) {
gBS->FreePool (*String);
FreePool (*String);
*String = AllocateZeroPool (StringSize);
if (*String == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -336,7 +344,7 @@ HiiLibGetStringFromHandle (
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code.
//
CHAR8 Iso639ToRfc3066ConversionTable[] =
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =
"\
aaraa\
abkab\