memzip not working as intended any more

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

memzip not working as intended any more

Post by Ephreal » Tue Sep 21, 2021 2:35 pm

Hi

I have an old code and an old makefile. When i execute it i get the following error:

Code: Select all

Creating build/memzip-files.c
python3 ../micropython-master/lib/memzip/make-memzip.py --zip-file build/memzip-files.zip --c-file build/memzip-files.c memzip_files
  adding: test_file.rpd (stored 0%)
args.zip_filename = build/memzip-files.zip
args.c_filename = build/memzip-files.c
args.source_dir = memzip_files
Traceback (most recent call last):
  File "../micropython-master/lib/memzip/make-memzip.py", line 78, in <module>
    main()
  File "../micropython-master/lib/memzip/make-memzip.py", line 75, in main
    create_c_from_file(args.c_filename, args.zip_filename)
  File "../micropython-master/lib/memzip/make-memzip.py", line 30, in create_c_from_file
    print('#include <stdint.h>', file=c_file)
TypeError: a bytes-like object is required, not 'str'
make[2]: *** [Makefile:55: build/memzip-files.c] Error 1
make[2]: *** Deleting file 'build/memzip-files.c'
make[2]: Leaving directory '/home/avbe/git-projects/triton_func/tst_sw/mpyshell/micropy-lib/nios2'
make[1]: *** [makefile:3: all] Error 2
make[1]: Leaving directory '/home/avbe/git-projects/triton_func/tst_sw/mpyshell/micropy-lib'
make: *** [makefile:8: mpyshell] Error 2
My memzip part of the make file looks as following.

Code: Select all

SRC_C += \
	lib/memzip/import.c \
	lib/memzip/lexermemzip.c \
	lib/memzip/memzip.c \

OBJ += $(BUILD)/memzip-files.o

MAKE_MEMZIP = ../micropython-master/lib/memzip/make-memzip.py
ifeq ($(MEMZIP_DIR),)
MEMZIP_DIR = memzip_files
endif

$(BUILD)/memzip-files.o: $(BUILD)/memzip-files.c
	$(call compile_c)

$(BUILD)/memzip-files.c: $(shell find ${MEMZIP_DIR} -type f)
	@$(ECHO) "Creating $@"
	$(Q)$(PYTHON) $(MAKE_MEMZIP) --zip-file $(BUILD)/memzip-files.zip --c-file $@ $(MEMZIP_DIR)
can anyone help to why I get this error? All I really need is to put the "test_file.rpd" binary in memory so I can read it using "memzip_locate". I have been able to do this with an older version of micropython. But it has been changed and updated a few times over the last year, and now I'm back and need this piece to work again.

Regards

Ephreal
Posts: 28
Joined: Tue Jan 15, 2019 1:41 pm

Re: memzip not working as intended any more

Post by Ephreal » Tue Sep 21, 2021 4:06 pm

Found the solution.

I had to change a few lines of code in the make-memzip.py for it to work.

Code: Select all

line 29:         with open(c_filename, 'wb') as c_file: ->         with open(c_filename, 'w') as c_file:
and

Code: Select all

line 39:                     if type(byte) is types.StringType: ->                     if type(byte) is str:
and it's working now.

regards

Post Reply