[edk2-devel] [PATCH v1 1/1] BaseTools: BinToPcd: Resolve xdrlib deprecation

Joey Vagedes via groups.io joeyvagedes=microsoft.com at groups.io
Thu Jul 13 15:26:58 UTC 2023


Thank you for the review Michael. @Rebecca Cran <rebecca at bsdio.com>, @Liming
Gao <gaoliming at byosoft.com.cn> have you had time to take a look at this? It
is a fairly simple change, following the same logic as xdrlib with a few
modifications to use some newer python functionality.

Thanks,
Joey

On Tue, Jun 27, 2023 at 10:21 AM Kinney, Michael D <
michael.d.kinney at intel.com> wrote:

> Thank you for fixing this.
>
> Reviewed-by: Michael D Kinney <michael.d.kinney at intel.com>
>
> > -----Original Message-----
> > From: Joey Vagedes <joey.vagedes at gmail.com>
> > Sent: Tuesday, June 27, 2023 9:27 AM
> > To: devel at edk2.groups.io
> > Cc: Rebecca Cran <rebecca at bsdio.com>; Gao, Liming
> > <gaoliming at byosoft.com.cn>; Feng, Bob C <bob.c.feng at intel.com>; Chen,
> > Christine <yuwei.chen at intel.com>; Kinney, Michael D
> > <michael.d.kinney at intel.com>
> > Subject: [PATCH v1 1/1] BaseTools: BinToPcd: Resolve xdrlib deprecation
> >
> > Removes the dependency on xdrlib and replaces it with custom logic to
> > pack a per the xdr requirements. Necessary as xdrlib is being deprecated
> > in python 3.13.
> >
> > Cc: Rebecca Cran <rebecca at bsdio.com>
> > Cc: Liming Gao <gaoliming at byosoft.com.cn>
> > Cc: Bob Feng <bob.c.feng at intel.com>
> > Cc: Yuwei Chen <yuwei.chen at intel.com>
> > Cc: Michael D Kinney <michael.d.kinney at intel.com>
> > Signed-off-by: Joey Vagedes <joeyvagedes at gmail.com>
> > ---
> >  BaseTools/Scripts/BinToPcd.py | 19 +++++++++++++++----
> >  1 file changed, 15 insertions(+), 4 deletions(-)
> >
> > diff --git a/BaseTools/Scripts/BinToPcd.py
> b/BaseTools/Scripts/BinToPcd.py
> > index 3bc557b8412c..460c08b7f7cd 100644
> > --- a/BaseTools/Scripts/BinToPcd.py
> > +++ b/BaseTools/Scripts/BinToPcd.py
> > @@ -14,6 +14,9 @@ import sys
> >  import argparse
> >
> >  import re
> >
> >  import xdrlib
> >
> > +import io
> >
> > +import struct
> >
> > +import math
> >
> >
> >
> >  #
> >
> >  # Globals for help information
> >
> > @@ -46,16 +49,24 @@ if __name__ == '__main__':
> >              raise argparse.ArgumentTypeError (Message)
> >
> >          return Argument
> >
> >
> >
> > +    def XdrPackBuffer (buffer):
> >
> > +        packed_bytes = io.BytesIO()
> >
> > +        for unpacked_bytes in buffer:
> >
> > +            n = len(unpacked_bytes)
> >
> > +            packed_bytes.write(struct.pack('>L',n))
> >
> > +            data = unpacked_bytes[:n]
> >
> > +            n = math.ceil(n/4)*4
> >
> > +            data = data + (n - len(data)) * b'\0'
> >
> > +            packed_bytes.write(data)
> >
> > +        return packed_bytes.getvalue()
> >
> > +
> >
> >      def ByteArray (Buffer, Xdr = False):
> >
> >          if Xdr:
> >
> >              #
> >
> >              # If Xdr flag is set then encode data using the Variable-
> > Length Opaque
> >
> >              # Data format of RFC 4506 External Data Representation
> > Standard (XDR).
> >
> >              #
> >
> > -            XdrEncoder = xdrlib.Packer ()
> >
> > -            for Item in Buffer:
> >
> > -                XdrEncoder.pack_bytes (Item)
> >
> > -            Buffer = bytearray (XdrEncoder.get_buffer ())
> >
> > +            Buffer = bytearray (XdrPackBuffer (Buffer))
> >
> >          else:
> >
> >              #
> >
> >              # If Xdr flag is not set, then concatenate all the data
> >
> > --
> > 2.41.0.windows.1
>
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106911): https://edk2.groups.io/g/devel/message/106911
Mute This Topic: https://groups.io/mt/99813913/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/edk2-devel-archive/attachments/20230713/091cad22/attachment.htm>


More information about the edk2-devel-archive mailing list