1. Brian Curtin
  2. minidumper

Commits

Brian Curtin  committed 0de6fd3

Add unicode support.

  • Participants
  • Parent commits 7a02d86
  • Branches default

Comments (0)

Files changed (1)

File minidumper.c

View file
  • Ignore whitespace
 HMODULE DbgHelp = NULL;
 LPTOP_LEVEL_EXCEPTION_FILTER previous_filter = NULL;
 
-const char *dir = ".";
-const char *app_name = "python";
+Py_UNICODE *dir = L".";
+Py_UNICODE *app_name = L"python";
 MINIDUMP_TYPE dump_type = MiniDumpNormal;
 
 LONG WINAPI
     HANDLE file;
     MINIDUMP_EXCEPTION_INFORMATION info;
     SYSTEMTIME st;
-    char name [MAX_PATH];
-    
+    Py_UNICODE name [MAX_PATH];
+
     GetSystemTime(&st);
-    sprintf(name, "%s\\%s_%04d%02d%02d-%02d%02d%02d.mdmp", dir, app_name,
-                  st.wYear, st.wMonth, st.wDay,
-                  st.wHour, st.wMinute, st.wSecond);
+    swprintf(name, MAX_PATH, L"%s\\%s_%04d%02d%02d-%02d%02d%02d.mdmp",
+             dir, app_name,
+             st.wYear, st.wMonth, st.wDay,
+             st.wHour, st.wMinute, st.wSecond);
 
-    file = CreateFile(name, GENERIC_WRITE, /* not shared */0, NULL,
+    file = CreateFileW(name, GENERIC_WRITE, /* not shared */0, NULL,
                CREATE_ALWAYS, /* Start fresh */
                FILE_FLAG_WRITE_THROUGH /* Write straigt to disk */,
                NULL);
 static PyObject *
 mdmp_enable(PyObject *self, PyObject *args, PyObject *kwargs)
 {
-    PyObject *bytes_name = NULL;
-    PyObject *bytes_dir = NULL;
+    Py_UNICODE *pyname = NULL;
+    Py_UNICODE *pydir = NULL;
     int type = MiniDumpNormal;
 
     char *keywords[] = {"dir", "name", "type", NULL};
     if (DbgHelp == NULL)
         return NULL;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&O&i:enable", keywords,
-                            PyUnicode_FSConverter, &bytes_dir,
-                            PyUnicode_FSConverter, &bytes_name, &type))
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|uui:enable", keywords,
+                                     &pydir, &pyname, &type))
         return NULL;
 
     /* If no value was given, these already has a default. */
-    if (bytes_dir != NULL)
-        dir = PyBytes_AsString(bytes_dir);
-    if (bytes_name != NULL)
-        app_name = PyBytes_AsString(bytes_name);
+    if (pydir != NULL)
+        dir = pydir;
+    if (pyname != NULL)
+        app_name = pyname;
 
     dump_type = type;