Permalink
Browse files

Ditch that symbol table hack. It's not portable.

In particular, Mac OS and probably BSD don't like it.

Closes gh-8.
  • Loading branch information...
kr committed May 15, 2009
1 parent 95ff706 commit 5192ce554ba612b302052314564bd5eb2981b913
Showing with 15 additions and 59 deletions.
  1. +1 −51 cut.c
  2. +0 −3 cut.h
  3. +7 −0 job.c
  4. +3 −0 job.h
  5. +4 −5 tests/test_job.c
View
52 cut.c
@@ -224,56 +224,6 @@ collect(pid_t *pid, collect_fn fn, void *data)
}
}
-static void
-exec(void *data)
-{
- int r;
-
- char **info = (char **) data;
- r = execvp(info[0], info);
- die(5, "Wrong execvp");
-}
-
-/* Read the full symbol table (not just the dynamic symbols) and return the
- * value of the specified symbol. If an error occurs, print an error message
- * and exit.
- *
- * We cheat by using "nm" to parse the symbol table of the file on disk.
- */
-void *
-__cut_debug_addr(const char *sym, const char *file, int line)
-{
- void *val;
- FILE *out;
- pid_t pid;
- int status, r;
- char cmd[BUF_SIZE], s[BUF_SIZE];
- char *args[] = { "sh", "-c", cmd, 0 };
-
- sprintf(cmd, "nm %s | grep ' %s$'", program, sym);
-
- out = collect(&pid, exec, args);
- if (!out) die(1, " %s:%d: collect", file, line);
-
- pid = waitpid(pid, &status, 0);
- if (pid < 1) die(1, " %s:%d: wait", file, line);
-
- rewind(out);
- r = fread(s, 1, BUF_SIZE - 1, out);
- if (!r) printf(" %s:%d: no symbol: %s\n", file, line, sym), exit(1);
-
- s[r] = 0;
-
- errno = 0;
- val = (void *) strtoul(s, 0, 16);
- if (errno) die(1, " %s:%d: strtoul on ``%s''", file, line, s);
- if (((size_t) val) < 100) {
- die(1, " %s:%d: strtoul on ``%s''", file, line, s);
- }
-
- return val;
-}
-
static void
run_in_child(void *data)
{
@@ -294,7 +244,7 @@ void
__cut_run(char *group_name, cut_fn bringup, cut_fn takedown, char *test_name,
cut_fn test, char *filename, int lineno)
{
- pid_t pid;
+ pid_t pid = -1;
int status, r;
FILE *out;
test_output to;
View
3 cut.h
@@ -41,8 +41,6 @@ void cut_exit(void);
__FILE__, \
__LINE__);
-#define ADDR(S) (__cut_debug_addr(#S, __FILE__, __LINE__))
-
#define ASSERT(X,msg) __cut_assert(__FILE__,__LINE__,msg,#X,X)
#define STATIC_ASSERT(X) extern bool __static_ASSERT_at_line_##__LINE__##__[ (0!=(X))*2-1 ];
@@ -55,7 +53,6 @@ void cut_exit(void);
void __cut_run(char *, cut_fn, cut_fn, char *, cut_fn, char *, int);
void __cut_assert( char *, int, char *, char *, int );
-void *__cut_debug_addr(const char *, const char *, int);
#endif
View
7 job.c
@@ -263,6 +263,13 @@ total_jobs()
return next_id - 1;
}
+/* for unit tests */
+size_t
+get_all_jobs_used()
+{
+ return all_jobs_used;
+}
+
void
job_init()
{
View
3 job.h
@@ -87,6 +87,9 @@ void job_insert(job head, job j);
unsigned long long int total_jobs();
+/* for unit tests */
+size_t get_all_jobs_used();
+
void job_init();
#endif /*job_h*/
View
@@ -97,19 +97,18 @@ void
__CUT__job_test_all_jobs_used()
{
job j, x;
- size_t *all_jobs_used_ptr = ADDR(all_jobs_used);
j = make_job(0, 0, 1, 0, default_tube);
- ASSERT(*all_jobs_used_ptr == 1, "should match");
+ ASSERT(get_all_jobs_used() == 1, "should match");
x = allocate_job(10);
- ASSERT(*all_jobs_used_ptr == 1, "should match");
+ ASSERT(get_all_jobs_used() == 1, "should match");
job_free(x);
- ASSERT(*all_jobs_used_ptr == 1, "should match");
+ ASSERT(get_all_jobs_used() == 1, "should match");
job_free(j);
- ASSERT(*all_jobs_used_ptr == 0, "should match");
+ ASSERT(get_all_jobs_used() == 0, "should match");
}
void

0 comments on commit 5192ce5

Please sign in to comment.