Skip to content

Commit 45c7a1e

Browse files
authored
fix Windows compilation
1 parent 11ee17c commit 45c7a1e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Modules/_ssl.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,12 @@ format_ssl_error_message(PyObject *lib, PyObject *reason, PyObject *verify,
537537
const size_t libstr_len = libstr == NULL ? 0 : strlen(libstr);
538538
const size_t reastr_len = reastr == NULL ? 0 : strlen(reastr);
539539
const size_t verstr_len = verstr == NULL ? 0 : strlen(verstr);
540-
const size_t filename_len = 6; /* strlen("_ssl.c") == strlen(__FILE__) */
540+
/*
541+
* Sometimes, __FILE__ is an absolute path, so we hardcode "_ssl.c".
542+
* In the future, we might want to use the "filename" parameter but
543+
* for now (and for backward compatibility), we ignore it.
544+
*/
545+
const size_t filename_len = 6; /* strlen("_ssl.c") */
541546
/* upper bound on the number of characters taken by the line number */
542547
const size_t lineno_len = ceil(log10(abs(lineno) + 1));
543548
const size_t base_alloc = (
@@ -549,36 +554,36 @@ format_ssl_error_message(PyObject *lib, PyObject *reason, PyObject *verify,
549554
char *buf;
550555

551556
if (lib && reason && verify) {
552-
/* [LIB: REASON] ERROR: VERIFY (FILENAME:LINENO) */
557+
/* [LIB: REASON] ERROR: VERIFY (_ssl.c:LINENO) */
553558
const size_t alloc = base_alloc + (4 + 3 + 4);
554559
buf = (char *)PyMem_RawMalloc(alloc);
555-
rc = PyOS_snprintf(buf, alloc, "[%s: %s] %s: %s (" __FILE__ ":%d)",
560+
rc = PyOS_snprintf(buf, alloc, "[%s: %s] %s: %s (_ssl.c:%d)",
556561
libstr, reastr, errstr, verstr, lineno);
557562
}
558563
else if (lib && reason) {
559-
/* [LIB: REASON] ERROR (FILENAME:LINENO) */
564+
/* [LIB: REASON] ERROR (_ssl.c:LINENO) */
560565
const size_t alloc = base_alloc + (3 + 2 + 4);
561566
buf = (char *)PyMem_RawMalloc(alloc);
562-
rc = PyOS_snprintf(buf, alloc, "[%s: %s] %s (" __FILE__ ":%d)",
567+
rc = PyOS_snprintf(buf, alloc, "[%s: %s] %s (_ssl.c:%d)",
563568
libstr, reastr, errstr, lineno);
564569
}
565570
else if (lib) {
566-
/* [LIB] ERROR (FILENAME:LINENO) */
571+
/* [LIB] ERROR (_ssl.c:LINENO) */
567572
const size_t alloc = base_alloc + (2 + 1 + 4);
568573
buf = (char *)PyMem_RawMalloc(alloc);
569-
rc = PyOS_snprintf(buf, alloc, "[%s] %s (" __FILE__ ":%d)",
574+
rc = PyOS_snprintf(buf, alloc, "[%s] %s (_ssl.c:%d)",
570575
libstr, errstr, lineno);
571576
}
572577
else {
573-
/* ERROR (FILENAME:LINENO) */
578+
/* ERROR (_ssl.c:LINENO) */
574579
const size_t alloc = base_alloc + (1 + 1 + 2);
575580
buf = (char *)PyMem_RawMalloc(alloc);
576-
rc = PyOS_snprintf(buf, alloc, "%s (" __FILE__ ":%d)",
581+
rc = PyOS_snprintf(buf, alloc, "%s (_ssl.c:%d)",
577582
errstr, lineno);
578583
}
579584

580585
PyObject *res = rc < 0
581-
? PyUnicode_FromFormat("%s (" __FILE__ ":%d)", errstr, lineno)
586+
? PyUnicode_FromFormat("%s (_ssl.c:%d)", errstr, lineno)
582587
: PyUnicode_FromString(buf) /* uses the ASCII fast path */;
583588
PyMem_RawFree(buf);
584589
return res;

0 commit comments

Comments
 (0)