Skip to content

Commit ad6ffe4

Browse files
committed
Inline make_error
1 parent 970963e commit ad6ffe4

2 files changed

Lines changed: 17 additions & 23 deletions

File tree

av/container/core.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class Container:
9494
exc_val: BaseException | None,
9595
exc_tb: TracebackType | None,
9696
) -> bool: ...
97-
def err_check(self, value: int) -> int: ...
9897
def set_timeout(self, timeout: Real | None) -> None: ...
9998
def start_timeout(self) -> None: ...
10099

av/error.pyx

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -379,27 +379,6 @@ cdef int stash_exception(exc_info=None):
379379

380380
cdef int _last_log_count = 0
381381

382-
383-
cpdef make_error(int res, filename=None, log=None):
384-
cdef int code = -res
385-
cdef char* error_buffer = <char*>malloc(lib.AV_ERROR_MAX_STRING_SIZE * sizeof(char))
386-
if error_buffer == NULL:
387-
raise MemoryError()
388-
389-
try:
390-
if code == c_PYAV_STASHED_ERROR:
391-
message = PYAV_STASHED_ERROR_message
392-
else:
393-
lib.av_strerror(res, error_buffer, lib.AV_ERROR_MAX_STRING_SIZE)
394-
# Fallback to OS error string if no message
395-
message = error_buffer or os.strerror(code)
396-
397-
cls = classes.get(code, UndefinedError)
398-
return cls(code, message, filename, log)
399-
finally:
400-
free(error_buffer)
401-
402-
403382
cpdef int err_check(int res, filename=None) except -1:
404383
"""Raise appropriate exceptions from library return code."""
405384

@@ -425,7 +404,23 @@ cpdef int err_check(int res, filename=None) except -1:
425404
else:
426405
log = None
427406

428-
raise make_error(res, filename, log)
407+
cdef int code = -res
408+
cdef char* error_buffer = <char*>malloc(lib.AV_ERROR_MAX_STRING_SIZE * sizeof(char))
409+
if error_buffer == NULL:
410+
raise MemoryError()
411+
412+
try:
413+
if code == c_PYAV_STASHED_ERROR:
414+
message = PYAV_STASHED_ERROR_message
415+
else:
416+
lib.av_strerror(res, error_buffer, lib.AV_ERROR_MAX_STRING_SIZE)
417+
# Fallback to OS error string if no message
418+
message = error_buffer or os.strerror(code)
419+
420+
cls = classes.get(code, UndefinedError)
421+
raise cls(code, message, filename, log)
422+
finally:
423+
free(error_buffer)
429424

430425

431426
class UndefinedError(FFmpegError):

0 commit comments

Comments
 (0)