Skip to content

Commit 4f5971e

Browse files
committed
fix test for osx #123, remove warnings and simplify impl
1 parent a54ccd2 commit 4f5971e

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/_vmprof.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ resolve_addr(PyObject *module, PyObject *args) {
442442
static PyObject * vmp_get_profile_path(PyObject *module, PyObject *noargs) {
443443
PyObject * o;
444444
if (is_enabled) {
445-
char * buffer[4096];
445+
char buffer[4096];
446+
buffer[0] = 0;
446447
ssize_t buffer_len = vmp_fd_to_path(vmp_profile_fileno(), buffer, 4096);
447448
if (buffer_len == -1) {
448449
PyErr_Format(PyExc_NotImplementedError, "not implemented platform %s", vmp_machine_os_name());

src/machine.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#include "vmprof.h"
44
#include <stdio.h>
55

6+
#ifdef VMPROF_UNIX
7+
#include <unistd.h>
8+
#include <fcntl.h>
9+
#endif
10+
611
int vmp_machine_bits(void)
712
{
813
return sizeof(void*)*8;
@@ -34,12 +39,8 @@ long vmp_fd_to_path(int fd, char * buffer, long buffer_len)
3439
(void)snprintf(proffs, 24, "/proc/self/fd/%d", fd);
3540
return readlink(proffs, buffer, buffer_len);
3641
#elif defined(VMPROF_UNIX)
37-
char buf[MAXPATHLEN];
38-
int size = fcntl(fd, F_GETPATH, buf);
39-
if (size >= 0) {
40-
(void)strncpy(buffer, buf, buffer_len);
41-
}
42-
return size;
42+
fcntl(fd, F_GETPATH, buffer);
43+
return strlen(buffer);
4344
#endif
4445
return -1;
4546
}

src/symboltable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
*/
1818
void dump_all_known_symbols(int fd);
1919

20+
void dump_native_symbols(int fd);
21+
2022
int vmp_resolve_addr(void * addr, char * name, int name_len, int * lineno,
2123
char * srcfile, int srcfile_len);

vmprof/test/test_run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,10 @@ def test_get_profile_path(self):
433433
assert vmprof.get_profile_path() == None
434434
tmpfile = tempfile.NamedTemporaryFile(delete=False)
435435
vmprof.enable(tmpfile.fileno())
436-
assert vmprof.get_profile_path() == tmpfile.name
436+
if not vmprof.get_profile_path() == tmpfile.name:
437+
with open(vmprof.get_profile_path(), 'rb') as fd1:
438+
with open(tmpfile.name, "rb") as fd2:
439+
assert fd1.read() == fd2.read()
437440
vmprof.disable()
438441
assert vmprof.get_profile_path() == None
439442

0 commit comments

Comments
 (0)