diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2019-01-21 00:31:45 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-21 00:31:45 -0800 |
| commit | b369fa9013d3d0be48bef113811c4acddcd53ba5 (patch) | |
| tree | 00ebdb0656a8101363a7a1e16c44201045542b84 | |
| parent | 6b88d0f94eb1459562d0f159688b504a6f5d408f (diff) | |
| parent | 9558b3afa7d90e1f84070088b0f7c4c21def4683 (diff) | |
Merge pull request #1478 from dhalbert/struct-compat
Improve struct compatibility with CPython
| -rw-r--r-- | locale/ID.po | 44 | ||||
| -rw-r--r-- | locale/circuitpython.pot | 19 | ||||
| -rw-r--r-- | locale/de_DE.po | 82 | ||||
| -rw-r--r-- | locale/en_US.po | 19 | ||||
| -rw-r--r-- | locale/es.po | 98 | ||||
| -rw-r--r-- | locale/fil.po | 100 | ||||
| -rw-r--r-- | locale/fr.po | 98 | ||||
| -rw-r--r-- | locale/it_IT.po | 96 | ||||
| -rw-r--r-- | locale/pt_BR.po | 58 | ||||
| -rw-r--r-- | py/binary.c | 7 | ||||
| -rw-r--r-- | py/modstruct.c | 16 | ||||
| -rw-r--r-- | shared-bindings/struct/__init__.c | 63 | ||||
| -rw-r--r-- | shared-bindings/struct/__init__.h | 2 | ||||
| -rw-r--r-- | shared-module/struct/__init__.c | 113 |
14 files changed, 477 insertions, 338 deletions
diff --git a/locale/ID.po b/locale/ID.po index 8547493e9..cf317b42d 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -1363,9 +1363,9 @@ msgstr "" msgid "schedule stack full" msgstr "" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "" @@ -2649,10 +2649,20 @@ msgstr "" msgid "'S' and 'O' are not supported format types" msgstr "" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, fuzzy, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "Gagal untuk megalokasikan buffer RX dari %d byte" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "" +#: shared-module/struct/__init__.c:179 +#, fuzzy +msgid "buffer size must match format" +msgstr "buffers harus mempunyai panjang yang sama" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." @@ -2739,24 +2749,24 @@ msgid "" "exit safe mode.\n" msgstr "" +#~ msgid "Invalid UUID string length" +#~ msgstr "Panjang string UUID tidak valid" + #~ msgid "" -#~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" +#~ "enough power for the whole circuit and press reset (after ejecting " +#~ "CIRCUITPY).\n" #~ msgstr "" -#~ "Silahkan taruh masalah disini dengan isi dari CIRCUITPY drive: anda \n" - -#~ msgid "Invalid UUID parameter" -#~ msgstr "Parameter UUID tidak valid" +#~ "tegangan cukup untuk semua sirkuit dan tekan reset (setelah mencabut " +#~ "CIRCUITPY).\n" #~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" #~ msgstr "" #~ "Sepertinya inti kode CircuitPython kita crash dengan sangat keras. Ups!\n" +#~ msgid "Invalid UUID parameter" +#~ msgstr "Parameter UUID tidak valid" + #~ msgid "" -#~ "enough power for the whole circuit and press reset (after ejecting " -#~ "CIRCUITPY).\n" +#~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" #~ msgstr "" -#~ "tegangan cukup untuk semua sirkuit dan tekan reset (setelah mencabut " -#~ "CIRCUITPY).\n" - -#~ msgid "Invalid UUID string length" -#~ msgstr "Panjang string UUID tidak valid" +#~ "Silahkan taruh masalah disini dengan isi dari CIRCUITPY drive: anda \n" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 0a9e67685..4962a67ab 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" @@ -1330,9 +1330,9 @@ msgstr "" msgid "schedule stack full" msgstr "" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "" @@ -2612,10 +2612,19 @@ msgstr "" msgid "'S' and 'O' are not supported format types" msgstr "" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "" +#: shared-module/struct/__init__.c:179 +msgid "buffer size must match format" +msgstr "" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." diff --git a/locale/de_DE.po b/locale/de_DE.po index 170104e9f..fe16a724b 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: Sebastian Plamauer\n" "Language-Team: \n" @@ -1359,9 +1359,9 @@ msgstr "" msgid "schedule stack full" msgstr "" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "" @@ -2651,10 +2651,20 @@ msgstr "Kann '/' nicht remounten when USB aktiv ist" msgid "'S' and 'O' are not supported format types" msgstr "" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, fuzzy, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "Konnte keine RX Buffer mit %d allozieren" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "" +#: shared-module/struct/__init__.c:179 +#, fuzzy +msgid "buffer size must match format" +msgstr "Buffer müssen gleich lang sein" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." @@ -2739,22 +2749,29 @@ msgid "" "exit safe mode.\n" msgstr "" -#~ msgid "Invalid UUID string length" -#~ msgstr "Ungültige UUID-Stringlänge" +#~ msgid "Can not add Characteristic." +#~ msgstr "Kann das Merkmal nicht hinzufügen." -#~ msgid "Can encode UUID into the advertisement packet." -#~ msgstr "Kann UUID in das advertisement packet kodieren." +#~ msgid "Can not add Service." +#~ msgstr "Kann den Dienst nicht hinzufügen." -#~ msgid "" -#~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" -#~ msgstr "" -#~ "Bitte erstelle ein issue hier mit dem Inhalt deines CIRCUITPY-speichers:\n" +#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" +#~ msgstr "CircuitPython ist abgestürzt. Ups!\n" -#~ msgid "Invalid UUID parameter" -#~ msgstr "Ungültiger UUID-Parameter" +#~ msgid "Can not apply advertisement data. status: 0x%02x" +#~ msgstr "Kann advertisement data nicht anwenden. Status: 0x%02x" -#~ msgid "Invalid Service type" -#~ msgstr "Ungültiger Diensttyp" +#~ msgid "Cannot apply GAP parameters." +#~ msgstr "Kann GAP Parameter nicht anwenden." + +#~ msgid "Can not encode UUID, to check length." +#~ msgstr "Kann UUID nicht kodieren, um die Länge zu überprüfen." + +#~ msgid "Can not query for the device address." +#~ msgstr "Kann nicht nach der Geräteadresse suchen." + +#~ msgid "Can not apply device name in the stack." +#~ msgstr "Der Gerätename kann nicht im Stack verwendet werden." #~ msgid "" #~ "enough power for the whole circuit and press reset (after ejecting " @@ -2763,26 +2780,19 @@ msgstr "" #~ "genug Strom für den ganzen Schaltkreis liefert und drücke reset (nach dem " #~ "sicheren Auswerfen von CIRCUITPY.)\n" -#~ msgid "Can not apply device name in the stack." -#~ msgstr "Der Gerätename kann nicht im Stack verwendet werden." - -#~ msgid "Can not query for the device address." -#~ msgstr "Kann nicht nach der Geräteadresse suchen." - -#~ msgid "Can not encode UUID, to check length." -#~ msgstr "Kann UUID nicht kodieren, um die Länge zu überprüfen." - -#~ msgid "Cannot apply GAP parameters." -#~ msgstr "Kann GAP Parameter nicht anwenden." +#~ msgid "Invalid Service type" +#~ msgstr "Ungültiger Diensttyp" -#~ msgid "Can not apply advertisement data. status: 0x%02x" -#~ msgstr "Kann advertisement data nicht anwenden. Status: 0x%02x" +#~ msgid "Invalid UUID parameter" +#~ msgstr "Ungültiger UUID-Parameter" -#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" -#~ msgstr "CircuitPython ist abgestürzt. Ups!\n" +#~ msgid "" +#~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" +#~ msgstr "" +#~ "Bitte erstelle ein issue hier mit dem Inhalt deines CIRCUITPY-speichers:\n" -#~ msgid "Can not add Service." -#~ msgstr "Kann den Dienst nicht hinzufügen." +#~ msgid "Can encode UUID into the advertisement packet." +#~ msgstr "Kann UUID in das advertisement packet kodieren." -#~ msgid "Can not add Characteristic." -#~ msgstr "Kann das Merkmal nicht hinzufügen." +#~ msgid "Invalid UUID string length" +#~ msgstr "Ungültige UUID-Stringlänge" diff --git a/locale/en_US.po b/locale/en_US.po index acd5f54cb..33b1e614b 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: 2018-07-27 11:55-0700\n" "Last-Translator: \n" "Language-Team: \n" @@ -1330,9 +1330,9 @@ msgstr "" msgid "schedule stack full" msgstr "" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "" @@ -2612,10 +2612,19 @@ msgstr "" msgid "'S' and 'O' are not supported format types" msgstr "" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "" +#: shared-module/struct/__init__.c:179 +msgid "buffer size must match format" +msgstr "" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." diff --git a/locale/es.po b/locale/es.po index 799fc68bf..6daa4170b 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: 2018-08-24 22:56-0500\n" "Last-Translator: \n" "Language-Team: \n" @@ -1366,9 +1366,9 @@ msgstr "división por cero" msgid "schedule stack full" msgstr "" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "buffer demasiado pequeño" @@ -2673,10 +2673,20 @@ msgstr "No se puede volver a montar '/' cuando el USB esta activo." msgid "'S' and 'O' are not supported format types" msgstr "'S' y 'O' no son compatibles con los tipos de formato" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, fuzzy, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "Falló la asignación del buffer RX de %d bytes" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "demasiados argumentos provistos con el formato dado" +#: shared-module/struct/__init__.c:179 +#, fuzzy +msgid "buffer size must match format" +msgstr "los buffers deben de tener la misma longitud" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." @@ -2771,31 +2781,32 @@ msgstr "" "El botón reset fue presionado mientras arrancaba CircuitPython. Presiona " "otra vez para salir del modo seguro.\n" -#~ msgid "Invalid UUID string length" -#~ msgstr "Longitud de string UUID inválida" +#~ msgid "Baud rate too high for this SPI peripheral" +#~ msgstr "Baud rate demasiado alto para este periférico SPI" -#~ msgid "Invalid UUID parameter" -#~ msgstr "Parámetro UUID inválido" +#~ msgid "Invalid Service type" +#~ msgstr "Tipo de Servicio inválido" -#~ msgid "Can not query for the device address." -#~ msgstr "No se puede consultar la dirección del dispositivo." +#~ msgid "Can not apply advertisement data. status: 0x%02x" +#~ msgstr "No se puede aplicar los datos de anuncio. status: 0x%02x" -#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" -#~ msgstr "" -#~ "Parece que nuestro código CircuitPython dejó de funcionar. Whoops!\n" +#~ msgid "Can encode UUID into the advertisement packet." +#~ msgstr "Se puede codificar el UUID en el paquete de anuncio." -#~ msgid "Cannot set PPCP parameters." -#~ msgstr "No se pueden establecer los parámetros PPCP." +#~ msgid "Can not encode UUID, to check length." +#~ msgstr "No se puede codificar el UUID, para revisar la longitud." -#~ msgid "" -#~ "enough power for the whole circuit and press reset (after ejecting " -#~ "CIRCUITPY).\n" -#~ msgstr "" -#~ "suficiente poder para todo el circuito y presiona reset (después de " -#~ "expulsar CIRCUITPY).\n" +#~ msgid "Cannot apply GAP parameters." +#~ msgstr "No se pueden aplicar los parámetros GAP." -#~ msgid "Can not apply device name in the stack." -#~ msgstr "No se puede aplicar el nombre del dispositivo en el stack." +#~ msgid "Can not add Service." +#~ msgstr "No se puede agregar el Servicio." + +#~ msgid "Wrong number of bytes provided" +#~ msgstr "Numero erroneo de bytes dados" + +#~ msgid "Wrong address length" +#~ msgstr "Longitud de address erronea" #, fuzzy #~ msgid "" @@ -2804,29 +2815,28 @@ msgstr "" #~ "Por favor registra un issue en la siguiente URL con el contenidos de tu " #~ "unidad de almacenamiento CIRCUITPY:\n" -#~ msgid "Wrong address length" -#~ msgstr "Longitud de address erronea" - -#~ msgid "Wrong number of bytes provided" -#~ msgstr "Numero erroneo de bytes dados" - -#~ msgid "Can not add Service." -#~ msgstr "No se puede agregar el Servicio." +#~ msgid "Can not apply device name in the stack." +#~ msgstr "No se puede aplicar el nombre del dispositivo en el stack." -#~ msgid "Cannot apply GAP parameters." -#~ msgstr "No se pueden aplicar los parámetros GAP." +#~ msgid "" +#~ "enough power for the whole circuit and press reset (after ejecting " +#~ "CIRCUITPY).\n" +#~ msgstr "" +#~ "suficiente poder para todo el circuito y presiona reset (después de " +#~ "expulsar CIRCUITPY).\n" -#~ msgid "Can not encode UUID, to check length." -#~ msgstr "No se puede codificar el UUID, para revisar la longitud." +#~ msgid "Cannot set PPCP parameters." +#~ msgstr "No se pueden establecer los parámetros PPCP." -#~ msgid "Can encode UUID into the advertisement packet." -#~ msgstr "Se puede codificar el UUID en el paquete de anuncio." +#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" +#~ msgstr "" +#~ "Parece que nuestro código CircuitPython dejó de funcionar. Whoops!\n" -#~ msgid "Can not apply advertisement data. status: 0x%02x" -#~ msgstr "No se puede aplicar los datos de anuncio. status: 0x%02x" +#~ msgid "Can not query for the device address." +#~ msgstr "No se puede consultar la dirección del dispositivo." -#~ msgid "Invalid Service type" -#~ msgstr "Tipo de Servicio inválido" +#~ msgid "Invalid UUID parameter" +#~ msgstr "Parámetro UUID inválido" -#~ msgid "Baud rate too high for this SPI peripheral" -#~ msgstr "Baud rate demasiado alto para este periférico SPI" +#~ msgid "Invalid UUID string length" +#~ msgstr "Longitud de string UUID inválida" diff --git a/locale/fil.po b/locale/fil.po index 6b3e408c7..8d112726e 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy <me@timothygarcia.ca>\n" "Language-Team: fil\n" @@ -1367,9 +1367,9 @@ msgstr "dibisyon ng zero" msgid "schedule stack full" msgstr "puno na ang schedule stack" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "masyadong maliit ang buffer" @@ -2679,10 +2679,20 @@ msgstr "Hindi ma-remount '/' kapag aktibo ang USB." msgid "'S' and 'O' are not supported format types" msgstr "Ang 'S' at 'O' ay hindi suportadong uri ng format" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, fuzzy, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "Nabigong ilaan ang RX buffer ng %d bytes" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "masyadong maraming mga argumento na ibinigay sa ibinigay na format" +#: shared-module/struct/__init__.c:179 +#, fuzzy +msgid "buffer size must match format" +msgstr "aarehas na haba dapat ang buffer slices" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." @@ -2777,31 +2787,33 @@ msgstr "" "Ang reset button ay pinindot habang nag boot ang CircuitPython. Pindutin " "ulit para lumabas sa safe mode.\n" -#~ msgid "Invalid UUID string length" -#~ msgstr "Mali ang UUID string length" +#, fuzzy +#~ msgid "palette must be displayio.Palette" +#~ msgstr "ang palette ay dapat 32 bytes ang haba" -#~ msgid "Invalid UUID parameter" -#~ msgstr "Mali ang UUID parameter" +#~ msgid "Invalid Service type" +#~ msgstr "Mali ang tipo ng serbisyo" -#~ msgid "Can not query for the device address." -#~ msgstr "Hindi maaaring mag-query para sa address ng device." +#~ msgid "Can not apply advertisement data. status: 0x%02x" +#~ msgstr "Hindi ma i-apply ang advertisement data. status: 0x%02x" -#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" -#~ msgstr "" -#~ "Mukhang ang core CircuitPython code ay nag-crash ng malakas. Aray!\n" +#~ msgid "Can encode UUID into the advertisement packet." +#~ msgstr "Maaring i-encode ang UUID sa advertisement packet." -#~ msgid "Cannot set PPCP parameters." -#~ msgstr "Hindi ma-set ang PPCP parameters." +#~ msgid "Can not encode UUID, to check length." +#~ msgstr "Hindi ma-encode UUID, para suriin ang haba." -#~ msgid "" -#~ "enough power for the whole circuit and press reset (after ejecting " -#~ "CIRCUITPY).\n" -#~ msgstr "" -#~ "ay nagbibigay ng sapat na power para sa buong circuit at i-press ang " -#~ "reset (pagkatapos i-eject ang CIRCUITPY).\n" +#~ msgid "Cannot apply GAP parameters." +#~ msgstr "Hindi ma-apply ang GAP parameters." -#~ msgid "Can not apply device name in the stack." -#~ msgstr "Hindi maaaring ma-aplay ang device name sa stack." +#~ msgid "Can not add Service." +#~ msgstr "Hindi maidaragdag ang serbisyo." + +#~ msgid "Wrong number of bytes provided" +#~ msgstr "Mali ang bilang ng bytes" + +#~ msgid "Wrong address length" +#~ msgstr "Mali ang address length" #~ msgid "" #~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" @@ -2809,30 +2821,28 @@ msgstr "" #~ "Mag-file ng isang isyu dito gamit ang mga nilalaman ng iyong CIRCUITPY " #~ "drive:\n" -#~ msgid "Wrong address length" -#~ msgstr "Mali ang address length" - -#~ msgid "Wrong number of bytes provided" -#~ msgstr "Mali ang bilang ng bytes" - -#~ msgid "Can not add Service." -#~ msgstr "Hindi maidaragdag ang serbisyo." +#~ msgid "Can not apply device name in the stack." +#~ msgstr "Hindi maaaring ma-aplay ang device name sa stack." -#~ msgid "Cannot apply GAP parameters." -#~ msgstr "Hindi ma-apply ang GAP parameters." +#~ msgid "" +#~ "enough power for the whole circuit and press reset (after ejecting " +#~ "CIRCUITPY).\n" +#~ msgstr "" +#~ "ay nagbibigay ng sapat na power para sa buong circuit at i-press ang " +#~ "reset (pagkatapos i-eject ang CIRCUITPY).\n" -#~ msgid "Can not encode UUID, to check length." -#~ msgstr "Hindi ma-encode UUID, para suriin ang haba." +#~ msgid "Cannot set PPCP parameters." +#~ msgstr "Hindi ma-set ang PPCP parameters." -#~ msgid "Can encode UUID into the advertisement packet." -#~ msgstr "Maaring i-encode ang UUID sa advertisement packet." +#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" +#~ msgstr "" +#~ "Mukhang ang core CircuitPython code ay nag-crash ng malakas. Aray!\n" -#~ msgid "Can not apply advertisement data. status: 0x%02x" -#~ msgstr "Hindi ma i-apply ang advertisement data. status: 0x%02x" +#~ msgid "Can not query for the device address." +#~ msgstr "Hindi maaaring mag-query para sa address ng device." -#~ msgid "Invalid Service type" -#~ msgstr "Mali ang tipo ng serbisyo" +#~ msgid "Invalid UUID parameter" +#~ msgstr "Mali ang UUID parameter" -#, fuzzy -#~ msgid "palette must be displayio.Palette" -#~ msgstr "ang palette ay dapat 32 bytes ang haba" +#~ msgid "Invalid UUID string length" +#~ msgstr "Mali ang UUID string length" diff --git a/locale/fr.po b/locale/fr.po index 236ce4345..2110a4c6e 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: 2018-12-23 20:05+0100\n" "Last-Translator: Pierrick Couturier <arofarn@arofarn.info>\n" "Language-Team: fr\n" @@ -1366,9 +1366,9 @@ msgstr "division par zéro" msgid "schedule stack full" msgstr "pile de plannification pleine" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "tampon trop petit" @@ -2703,10 +2703,20 @@ msgstr "'/' ne peut être remonté quand l'USB est actif." msgid "'S' and 'O' are not supported format types" msgstr "'S' et 'O' ne sont pas des types de format supportés" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, fuzzy, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "Echec de l'allocation de %d octets du tampon RX" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "trop d'arguments fournis avec ce format" +#: shared-module/struct/__init__.c:179 +#, fuzzy +msgid "buffer size must match format" +msgstr "les slices de tampon doivent être de longueurs égales" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." @@ -2806,63 +2816,63 @@ msgstr "" "Le bouton 'reset' a été appuyé pendant le démarrage de CircuitPython. " "Appuyer denouveau pour quitter de le mode sans-échec.\n" -#~ msgid "Invalid UUID string length" -#~ msgstr "Longeur de chaîne UUID invalide" - -#~ msgid "Invalid UUID parameter" -#~ msgstr "Paramètre UUID invalide" - -#, fuzzy -#~ msgid "palette must be displayio.Palette" -#~ msgstr "la palette doit être une displayio.Palette" +#~ msgid "Cannot set PPCP parameters." +#~ msgstr "Impossible d'appliquer les paramètres PPCP" -#, fuzzy -#~ msgid "value_size must be power of two" -#~ msgstr "value_size doit être une puissance de 2" +#~ msgid "Can not add Characteristic." +#~ msgstr "Impossible d'ajouter la Characteristic." -#~ msgid "Cannot apply GAP parameters." -#~ msgstr "Impossible d'appliquer les paramètres GAP" +#~ msgid "Can not query for the device address." +#~ msgstr "Impossible d'obtenir l'adresse du périphérique" -#~ msgid "Invalid Service type" -#~ msgstr "Type de service invalide" +#~ msgid "Can not add Service." +#~ msgstr "Impossible d'ajouter le Service" #~ msgid "" -#~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" +#~ "enough power for the whole circuit and press reset (after ejecting " +#~ "CIRCUITPY).\n" #~ msgstr "" -#~ "SVP, remontez le problème là avec le contenu du lecteur CIRCUITPY:\n" +#~ "assez de puissance pour l'ensemble du circuit et appuyez sur " +#~ "'reset' (après avoir éjecter CIRCUITPY).\n" -#~ msgid "Can not encode UUID, to check length." -#~ msgstr "Impossible d'encoder l'UUID pour vérifier la longueur." +#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" +#~ msgstr "" +#~ "Il semblerait que votre code CircuitPython a durement planté. Oups!\n" -#~ msgid "Wrong address length" -#~ msgstr "Mauvaise longueur d'adresse" +#~ msgid "Can not apply device name in the stack." +#~ msgstr "Impossible d'appliquer le nom de périphérique dans la pile" #, fuzzy #~ msgid "Wrong number of bytes provided" #~ msgstr "mauvais nombre d'octets fourni'" -#~ msgid "Can not apply device name in the stack." -#~ msgstr "Impossible d'appliquer le nom de périphérique dans la pile" +#~ msgid "Wrong address length" +#~ msgstr "Mauvaise longueur d'adresse" -#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" -#~ msgstr "" -#~ "Il semblerait que votre code CircuitPython a durement planté. Oups!\n" +#~ msgid "Can not encode UUID, to check length." +#~ msgstr "Impossible d'encoder l'UUID pour vérifier la longueur." #~ msgid "" -#~ "enough power for the whole circuit and press reset (after ejecting " -#~ "CIRCUITPY).\n" +#~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" #~ msgstr "" -#~ "assez de puissance pour l'ensemble du circuit et appuyez sur " -#~ "'reset' (après avoir éjecter CIRCUITPY).\n" +#~ "SVP, remontez le problème là avec le contenu du lecteur CIRCUITPY:\n" -#~ msgid "Can not add Service." -#~ msgstr "Impossible d'ajouter le Service" +#~ msgid "Invalid Service type" +#~ msgstr "Type de service invalide" -#~ msgid "Can not query for the device address." -#~ msgstr "Impossible d'obtenir l'adresse du périphérique" +#~ msgid "Cannot apply GAP parameters." +#~ msgstr "Impossible d'appliquer les paramètres GAP" -#~ msgid "Can not add Characteristic." -#~ msgstr "Impossible d'ajouter la Characteristic." +#, fuzzy +#~ msgid "value_size must be power of two" +#~ msgstr "value_size doit être une puissance de 2" -#~ msgid "Cannot set PPCP parameters." -#~ msgstr "Impossible d'appliquer les paramètres PPCP" +#, fuzzy +#~ msgid "palette must be displayio.Palette" +#~ msgstr "la palette doit être une displayio.Palette" + +#~ msgid "Invalid UUID parameter" +#~ msgstr "Paramètre UUID invalide" + +#~ msgid "Invalid UUID string length" +#~ msgstr "Longeur de chaîne UUID invalide" diff --git a/locale/it_IT.po b/locale/it_IT.po index 225e51cf5..cb413f073 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin <enrico.paganin@mail.com>\n" "Language-Team: \n" @@ -1366,9 +1366,9 @@ msgstr "divisione per zero" msgid "schedule stack full" msgstr "" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "buffer troppo piccolo" @@ -2685,10 +2685,20 @@ msgstr "Non è possibile rimontare '/' mentre l'USB è attiva." msgid "'S' and 'O' are not supported format types" msgstr "'S' e 'O' non sono formati supportati" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, fuzzy, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "Fallita allocazione del buffer RX di %d byte" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "troppi argomenti forniti con il formato specificato" +#: shared-module/struct/__init__.c:179 +#, fuzzy +msgid "buffer size must match format" +msgstr "slice del buffer devono essere della stessa lunghezza" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." @@ -2775,27 +2785,35 @@ msgid "" "exit safe mode.\n" msgstr "" -#~ msgid "Invalid UUID string length" -#~ msgstr "Lunghezza della stringa UUID non valida" +#~ msgid "Cannot apply GAP parameters." +#~ msgstr "Impossibile applicare i parametri GAP." -#~ msgid "Invalid UUID parameter" -#~ msgstr "Parametro UUID non valido" +#~ msgid "" +#~ "enough power for the whole circuit and press reset (after ejecting " +#~ "CIRCUITPY).\n" +#~ msgstr "" +#~ "abbastanza potenza per l'intero circuito e premere reset (dopo aver " +#~ "espulso CIRCUITPY).\n" -#~ msgid "Invalid Service type" -#~ msgstr "Tipo di servizio non valido" +#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" +#~ msgstr "" +#~ "Sembra che il codice del core di CircuitPython sia crashato malamente. " +#~ "Whoops!\n" -#, fuzzy -#~ msgid "Wrong number of bytes provided" -#~ msgstr "numero di argomenti errato" +#~ msgid "Can not query for the device address." +#~ msgstr "Non è possibile trovare l'indirizzo del dispositivo." -#~ msgid "Cannot set PPCP parameters." -#~ msgstr "Impossibile impostare i parametri PPCP." +#~ msgid "Can not apply advertisement data. status: 0x%02x" +#~ msgstr "Impossible inserire dati advertisement. status: 0x%02x" -#~ msgid "Can not add Characteristic." -#~ msgstr "Non è possibile aggiungere Characteristic." +#~ msgid "Can not add Service." +#~ msgstr "Non è possibile aggiungere Service." -#~ msgid "Can not encode UUID, to check length." -#~ msgstr "Non è possibile codificare l'UUID, lunghezza da controllare." +#~ msgid "Can not apply device name in the stack." +#~ msgstr "Non è possibile inserire il nome del dipositivo nella lista." + +#~ msgid "Can encode UUID into the advertisement packet." +#~ msgstr "È possibile codificare l'UUID nel pacchetto di advertisement." #~ msgid "" #~ "Please file an issue here with the contents of your CIRCUITPY drive:\n" @@ -2803,32 +2821,24 @@ msgstr "" #~ "Ti preghiamo di compilare una issue con il contenuto del tuo drie " #~ "CIRCUITPY:\n" -#~ msgid "Can encode UUID into the advertisement packet." -#~ msgstr "È possibile codificare l'UUID nel pacchetto di advertisement." - -#~ msgid "Can not apply device name in the stack." -#~ msgstr "Non è possibile inserire il nome del dipositivo nella lista." +#~ msgid "Can not encode UUID, to check length." +#~ msgstr "Non è possibile codificare l'UUID, lunghezza da controllare." -#~ msgid "Can not add Service." -#~ msgstr "Non è possibile aggiungere Service." +#~ msgid "Can not add Characteristic." +#~ msgstr "Non è possibile aggiungere Characteristic." -#~ msgid "Can not apply advertisement data. status: 0x%02x" -#~ msgstr "Impossible inserire dati advertisement. status: 0x%02x" +#~ msgid "Cannot set PPCP parameters." +#~ msgstr "Impossibile impostare i parametri PPCP." -#~ msgid "Can not query for the device address." -#~ msgstr "Non è possibile trovare l'indirizzo del dispositivo." +#, fuzzy +#~ msgid "Wrong number of bytes provided" +#~ msgstr "numero di argomenti errato" -#~ msgid "Looks like our core CircuitPython code crashed hard. Whoops!\n" -#~ msgstr "" -#~ "Sembra che il codice del core di CircuitPython sia crashato malamente. " -#~ "Whoops!\n" +#~ msgid "Invalid Service type" +#~ msgstr "Tipo di servizio non valido" -#~ msgid "" -#~ "enough power for the whole circuit and press reset (after ejecting " -#~ "CIRCUITPY).\n" -#~ msgstr "" -#~ "abbastanza potenza per l'intero circuito e premere reset (dopo aver " -#~ "espulso CIRCUITPY).\n" +#~ msgid "Invalid UUID parameter" +#~ msgstr "Parametro UUID non valido" -#~ msgid "Cannot apply GAP parameters." -#~ msgstr "Impossibile applicare i parametri GAP." +#~ msgid "Invalid UUID string length" +#~ msgstr "Lunghezza della stringa UUID non valida" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index a0d81d182..457850a55 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-01-20 17:33-0800\n" +"POT-Creation-Date: 2019-01-20 22:46-0500\n" "PO-Revision-Date: 2018-10-02 21:14-0000\n" "Last-Translator: \n" "Language-Team: \n" @@ -1348,9 +1348,9 @@ msgstr "divisão por zero" msgid "schedule stack full" msgstr "" -#: py/modstruct.c:145 py/modstruct.c:153 py/modstruct.c:234 py/modstruct.c:244 -#: shared-bindings/struct/__init__.c:103 shared-bindings/struct/__init__.c:145 -#: shared-module/struct/__init__.c:91 shared-module/struct/__init__.c:175 +#: py/modstruct.c:148 py/modstruct.c:156 py/modstruct.c:244 py/modstruct.c:254 +#: shared-bindings/struct/__init__.c:102 shared-bindings/struct/__init__.c:161 +#: shared-module/struct/__init__.c:183 msgid "buffer too small" msgstr "" @@ -2642,10 +2642,20 @@ msgstr "Não é possível remontar '/' enquanto o USB estiver ativo." msgid "'S' and 'O' are not supported format types" msgstr "'S' e 'O' não são tipos de formato suportados" -#: shared-module/struct/__init__.c:83 +#: shared-module/struct/__init__.c:128 +#, fuzzy, c-format +msgid "unpack requires a buffer of %d bytes" +msgstr "Falha ao alocar buffer RX de %d bytes" + +#: shared-module/struct/__init__.c:136 msgid "too many arguments provided with the given format" msgstr "Muitos argumentos fornecidos com o formato dado" +#: shared-module/struct/__init__.c:179 +#, fuzzy +msgid "buffer size must match format" +msgstr "buffers devem ser o mesmo tamanho" + #: shared-module/usb_hid/Device.c:45 #, c-format msgid "Buffer incorrect size. Should be %d bytes." @@ -2726,32 +2736,32 @@ msgid "" "exit safe mode.\n" msgstr "" -#~ msgid "Can not query for the device address." -#~ msgstr "Não é possível consultar o endereço do dispositivo." - -#~ msgid "Invalid Service type" -#~ msgstr "Tipo de serviço inválido" +#~ msgid "Cannot set PPCP parameters." +#~ msgstr "Não é possível definir parâmetros PPCP." -#~ msgid "Can not apply device name in the stack." -#~ msgstr "Não é possível aplicar o nome do dispositivo na pilha." +#~ msgid "Can encode UUID into the advertisement packet." +#~ msgstr "Pode codificar o UUID no pacote de anúncios." -#~ msgid "Baud rate too high for this SPI peripheral" -#~ msgstr "Taxa de transmissão muito alta para esse periférico SPI" +#~ msgid "Can not apply advertisement data. status: 0x%02x" +#~ msgstr "Não é possível aplicar dados de anúncio. status: 0x%02x" -#~ msgid "Can not add Characteristic." -#~ msgstr "Não é possível adicionar Característica." +#~ msgid "Invalid UUID parameter" +#~ msgstr "Parâmetro UUID inválido" #~ msgid "Cannot apply GAP parameters." #~ msgstr "Não é possível aplicar parâmetros GAP." -#~ msgid "Invalid UUID parameter" -#~ msgstr "Parâmetro UUID inválido" +#~ msgid "Can not add Characteristic." +#~ msgstr "Não é possível adicionar Característica." -#~ msgid "Can not apply advertisement data. status: 0x%02x" -#~ msgstr "Não é possível aplicar dados de anúncio. status: 0x%02x" +#~ msgid "Baud rate too high for this SPI peripheral" +#~ msgstr "Taxa de transmissão muito alta para esse periférico SPI" -#~ msgid "Can encode UUID into the advertisement packet." -#~ msgstr "Pode codificar o UUID no pacote de anúncios." +#~ msgid "Can not apply device name in the stack." +#~ msgstr "Não é possível aplicar o nome do dispositivo na pilha." -#~ msgid "Cannot set PPCP parameters." -#~ msgstr "Não é possível definir parâmetros PPCP." +#~ msgid "Invalid Service type" +#~ msgstr "Tipo de serviço inválido" + +#~ msgid "Can not query for the device address." +#~ msgstr "Não é possível consultar o endereço do dispositivo." diff --git a/py/binary.c b/py/binary.c index ca851c936..9c3a49e8f 100644 --- a/py/binary.c +++ b/py/binary.c @@ -49,7 +49,7 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) { switch (struct_type) { case '<': case '>': switch (val_type) { - case 'b': case 'B': + case 'b': case 'B': case 'x': size = 1; break; case 'h': case 'H': size = 2; break; @@ -79,7 +79,7 @@ size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) { // particular (or any) ABI. switch (val_type) { case BYTEARRAY_TYPECODE: - case 'b': case 'B': + case 'b': case 'B': case 'x': align = size = 1; break; case 'h': case 'H': align = alignof(short); @@ -126,6 +126,7 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) { break; case BYTEARRAY_TYPECODE: case 'B': + case 'x': // value will be discarded val = ((unsigned char*)p)[index]; break; case 'h': @@ -364,6 +365,8 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m case 'B': ((unsigned char*)p)[index] = val; break; + case 'x': + ((unsigned char*)p)[index] = 0; case 'h': ((short*)p)[index] = val; break; diff --git a/py/modstruct.c b/py/modstruct.c index 3f1b2f8b8..a238d3935 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -97,7 +97,10 @@ STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) { total_cnt += 1; size += cnt; } else { - total_cnt += cnt; + // Pad bytes are skipped and don't get included in the item count. + if (*fmt != 'x') { + total_cnt += cnt; + } mp_uint_t align; size_t sz = mp_binary_get_size(fmt_type, *fmt, &align); while (cnt--) { @@ -166,7 +169,10 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { } else { while (cnt--) { item = mp_binary_get_val(fmt_type, *fmt, &p); - res->items[i++] = item; + // Pad bytes ('x') are just skipped. + if (*fmt != 'x') { + res->items[i++] = item; + } } } fmt++; @@ -204,7 +210,11 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c } else { // If we run out of args then we just finish; CPython would raise struct.error while (cnt-- && i < n_args) { - mp_binary_set_val(fmt_type, *fmt, args[i++], &p); + mp_binary_set_val(fmt_type, *fmt, args[i], &p); + // Pad bytes don't have a corresponding argument. + if (*fmt != 'x') { + i++; + } } } fmt++; diff --git a/shared-bindings/struct/__init__.c b/shared-bindings/struct/__init__.c index 093597785..9240a15bb 100644 --- a/shared-bindings/struct/__init__.c +++ b/shared-bindings/struct/__init__.c @@ -51,7 +51,7 @@ //| //| Supported size/byte order prefixes: *@*, *<*, *>*, *!*. //| -//| Supported format codes: *b*, *B*, *h*, *H*, *i*, *I*, *l*, *L*, *q*, *Q*, +//| Supported format codes: *b*, *B*, *x*, *h*, *H*, *i*, *I*, *l*, *L*, *q*, *Q*, //| *s*, *P*, *f*, *d* (the latter 2 depending on the floating-point support). //| @@ -74,7 +74,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(struct_calcsize_obj, struct_calcsize); //| STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { - // TODO: "The arguments must match the values required by the format exactly." mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0])); vstr_t vstr; vstr_init_len(&vstr, size); @@ -115,49 +114,67 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_into_obj, 3, MP_OBJ_FUN_ARGS_MAX //| .. function:: unpack(fmt, data) //| //| Unpack from the data according to the format string fmt. The return value -//| is a tuple of the unpacked values. +//| is a tuple of the unpacked values. The buffer size must match the size +//| required by the format. //| -//| .. function:: unpack_from(fmt, data, offset) +STATIC mp_obj_t struct_unpack(size_t n_args, const mp_obj_t *args) { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); + byte *p = bufinfo.buf; + byte *end_p = &p[bufinfo.len]; + + // true means check the size must be exactly right. + return MP_OBJ_FROM_PTR(shared_modules_struct_unpack_from(args[0] , p, end_p, true)); +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_obj, 2, 3, struct_unpack); + +//| .. function:: unpack_from(fmt, data, offset=0) //| //| Unpack from the data starting at offset according to the format string fmt. //| offset may be negative to count from the end of buffer. The return value is -//| a tuple of the unpacked values. +//| a tuple of the unpacked values. The buffer size must be at least as big +//| as the size required by the form. //| -STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { - // unpack requires that the buffer be exactly the right size. - // unpack_from requires that the buffer be "big enough". - // Since we implement unpack and unpack_from using the same function - // we relax the "exact" requirement, and only implement "big enough". +STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_format, ARG_buffer, ARG_offset }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_format, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_buffer, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_offset, MP_ARG_INT, {.u_int = 0} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); byte *p = bufinfo.buf; byte *end_p = &p[bufinfo.len]; - if (n_args > 2) { - mp_int_t offset = mp_obj_get_int(args[2]); - // offset arg provided + mp_int_t offset = args[ARG_offset].u_int; + if (offset < 0) { + // negative offsets are relative to the end of the buffer + offset = bufinfo.len + offset; if (offset < 0) { - // negative offsets are relative to the end of the buffer - offset = bufinfo.len + offset; - if (offset < 0) { - mp_raise_RuntimeError(translate("buffer too small")); - } + mp_raise_RuntimeError(translate("buffer too small")); } - p += offset; } + p += offset; - return MP_OBJ_FROM_PTR(shared_modules_struct_unpack_from(args[0] , p, end_p)); + // false means the size doesn't have to be exact. struct.unpack_from() only requires + // that be buffer be big enough. + return MP_OBJ_FROM_PTR(shared_modules_struct_unpack_from(args[ARG_format].u_obj, p, end_p, false)); } -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_from_obj, 2, 3, struct_unpack_from); +MP_DEFINE_CONST_FUN_OBJ_KW(struct_unpack_from_obj, 0, struct_unpack_from); STATIC const mp_rom_map_elem_t mp_module_struct_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_struct) }, { MP_ROM_QSTR(MP_QSTR_calcsize), MP_ROM_PTR(&struct_calcsize_obj) }, { MP_ROM_QSTR(MP_QSTR_pack), MP_ROM_PTR(&struct_pack_obj) }, { MP_ROM_QSTR(MP_QSTR_pack_into), MP_ROM_PTR(&struct_pack_into_obj) }, - { MP_ROM_QSTR(MP_QSTR_unpack), MP_ROM_PTR(&struct_unpack_from_obj) }, + { MP_ROM_QSTR(MP_QSTR_unpack), MP_ROM_PTR(&struct_unpack_obj) }, { MP_ROM_QSTR(MP_QSTR_unpack_from), MP_ROM_PTR(&struct_unpack_from_obj) }, }; diff --git a/shared-bindings/struct/__init__.h b/shared-bindings/struct/__init__.h index c4e867aaa..a7e72b11c 100644 --- a/shared-bindings/struct/__init__.h +++ b/shared-bindings/struct/__init__.h @@ -29,6 +29,6 @@ void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte* end_p, size_t n_args, const mp_obj_t *args); mp_uint_t shared_modules_struct_calcsize(mp_obj_t fmt_in); -mp_obj_tuple_t * shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byte *end_p); +mp_obj_tuple_t * shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byte *end_p, bool exact_size); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_RANDOM___INIT___H diff --git a/shared-module/struct/__init__.c b/shared-module/struct/__init__.c index 78c04f07b..28e7c0c3f 100644 --- a/shared-module/struct/__init__.c +++ b/shared-module/struct/__init__.c @@ -71,45 +71,6 @@ mp_uint_t get_fmt_num(const char **p) { return val; } -void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte* end_p, size_t n_args, const mp_obj_t *args) { - const char *fmt = mp_obj_str_get_str(fmt_in); - char fmt_type = get_fmt_type(&fmt); - - size_t i; - for (i = 0; i < n_args;) { - mp_uint_t sz = 1; - if (*fmt == '\0') { - // more arguments given than used by format string; CPython raises struct.error here - mp_raise_RuntimeError(translate("too many arguments provided with the given format")); - } - struct_validate_format(*fmt); - - if (unichar_isdigit(*fmt)) { - sz = get_fmt_num(&fmt); - } - if (p + sz > end_p) { - mp_raise_RuntimeError(translate("buffer too small")); - } - - if (*fmt == 's') { - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[i++], &bufinfo, MP_BUFFER_READ); - mp_uint_t to_copy = sz; - if (bufinfo.len < to_copy) { - to_copy = bufinfo.len; - } - memcpy(p, bufinfo.buf, to_copy); - memset(p + to_copy, 0, sz - to_copy); - p += sz; - } else { - while (sz--) { - mp_binary_set_val(fmt_type, *fmt, args[i++], &p); - } - } - fmt++; - } -} - mp_uint_t calcsize_items(const char *fmt) { mp_uint_t cnt = 0; while (*fmt) { @@ -120,7 +81,10 @@ mp_uint_t calcsize_items(const char *fmt) { num = 1; } } - cnt += num; + // Pad bytes are skipped and don't get included in the item count. + if (*fmt != 'x') { + cnt += num; + } fmt++; } return cnt; @@ -155,14 +119,71 @@ mp_uint_t shared_modules_struct_calcsize(mp_obj_t fmt_in) { return size; } +void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte* end_p, size_t n_args, const mp_obj_t *args) { + const char *fmt = mp_obj_str_get_str(fmt_in); + char fmt_type = get_fmt_type(&fmt); + const mp_uint_t total_sz = shared_modules_struct_calcsize(fmt_in); + + if (p + total_sz != end_p) { + mp_raise_msg_varg(&mp_type_RuntimeError, translate("unpack requires a buffer of %d bytes"), total_sz); + } + + size_t i; + for (i = 0; i < n_args;) { + mp_uint_t sz = 1; + if (*fmt == '\0') { + // more arguments given than used by format string; CPython raises struct.error here + mp_raise_RuntimeError(translate("too many arguments provided with the given format")); + } + struct_validate_format(*fmt); + + if (unichar_isdigit(*fmt)) { + sz = get_fmt_num(&fmt); + } + + if (*fmt == 's') { + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[i++], &bufinfo, MP_BUFFER_READ); + mp_uint_t to_copy = sz; + if (bufinfo.len < to_copy) { + to_copy = bufinfo.len; + } + memcpy(p, bufinfo.buf, to_copy); + memset(p + to_copy, 0, sz - to_copy); + p += sz; + } else { + while (sz--) { + mp_binary_set_val(fmt_type, *fmt, args[i], &p); + // Pad bytes don't have a corresponding argument. + if (*fmt != 'x') { + i++; + } + } + } + fmt++; + } +} -mp_obj_tuple_t * shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byte *end_p) { +mp_obj_tuple_t * shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byte *end_p, bool exact_size) { const char *fmt = mp_obj_str_get_str(fmt_in); char fmt_type = get_fmt_type(&fmt); - mp_uint_t num_items = calcsize_items(fmt); + const mp_uint_t num_items = calcsize_items(fmt); + const mp_uint_t total_sz = shared_modules_struct_calcsize(fmt_in); mp_obj_tuple_t *res = MP_OBJ_TO_PTR(mp_obj_new_tuple(num_items, NULL)); + // If exact_size, make sure the buffer is exactly the right size. + // Otherwise just make sure it's big enough. + if (exact_size) { + if (p + total_sz != end_p) { + mp_raise_RuntimeError(translate("buffer size must match format")); + } + } else { + if (p + total_sz > end_p) { + mp_raise_RuntimeError(translate("buffer too small")); + } + } + for (uint i = 0; i < num_items;) { mp_uint_t sz = 1; @@ -171,9 +192,6 @@ mp_obj_tuple_t * shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byt if (unichar_isdigit(*fmt)) { sz = get_fmt_num(&fmt); } - if (p + sz > end_p) { - mp_raise_RuntimeError(translate("buffer too small")); - } mp_obj_t item; if (*fmt == 's') { item = mp_obj_new_bytes(p, sz); @@ -182,7 +200,10 @@ mp_obj_tuple_t * shared_modules_struct_unpack_from(mp_obj_t fmt_in, byte *p, byt } else { while (sz--) { item = mp_binary_get_val(fmt_type, *fmt, &p); - res->items[i++] = item; + // Pad bytes are not stored. + if (*fmt != 'x') { + res->items[i++] = item; + } } } fmt++; |
