Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator.generate_slice_for_vector function only handles .c files. #12

Open
RobotSail opened this issue Feb 6, 2024 · 2 comments
Open

Comments

@RobotSail
Copy link

RobotSail commented Feb 6, 2024

Hello,

I recently ran into an error generating a patch for a repository where changes were made to both header and implementation files. It seems like the error is rooted in the implementation of the generate_slice_for_vector function in app/tools/generator.py, where it expects the vector path to contain a .c file:

def generate_slice_for_vector(vector_path, use_macro=False):
    # ...
    source_file, segment = vector_path.split(".c.")
    # ...

However, this breaks when FixMorph passes it a vectorfile that was constructed from a header file: /dirs/iotop-c-a/src/iotop.h.func_humanize_val.vec:

                        [ERROR] Crash during finding segment clones in target, after 0.100 minutes.
                        [ERROR] Transformation Failed
                        [ERROR] not enough values to unpack (expected 2, got 1)
                        [ERROR] Unexpected error during finding segment clones in target.
                        [ERROR] Runtime Error
                        [ERROR] Error. Exiting...
@RobotSail
Copy link
Author

RobotSail commented Feb 6, 2024

To update this issue, after introducing logic to properly handle whether a file is a header or source,
I was then met with this error output:

                        [ERROR] [error] neighborhood not found
                        [ERROR] Seg Code: func
                        [ERROR] PA: /dirs/iotop-c-a/src/iotop.h-humanize_val
                        [ERROR] PB: /dirs/iotop-c-b/src/iotop.h-humanize_val
                        [ERROR] PC: /dirs/iotop-c-c/src/iotop.h-turn_into_human_value
                        [ERROR] Transformation Failed
                        [ERROR] unable to evolve the code
                        [ERROR] Crash during evaluate code slices, after 0.082 minutes.
                        [ERROR] Transformation Failed
                        [ERROR] Error. Exiting...
                        [ERROR] Unexpected error during evaluate code slices.
                        [ERROR] Runtime Error
                        [ERROR] Error. Exiting...

The logic I introduced was simply:

def determine_splitter_from_filepath(fp: str) -> str:
    if ".c." in fp:
        return ".c."
    if ".h." in fp:
        return ".h."
    raise Exception(f'could not determine how to split path: "{fp}"')

Which would then be used like

def generate_slice_for_vector(vector_path, use_macro=False):
    # ...
    splitter = determine_splitter_from_filepath(vector_path)
    source_file, segment = vector_path.split(splitter)
    # ...

@RobotSail
Copy link
Author

Here's the patch in question that caused this:

The "upstream patch" being backported:

diff --git a/src/iotop.h b/src/iotop.h
index 0048a59..64175c7 100644
--- a/src/iotop.h
+++ b/src/iotop.h
@@ -261,7 +261,7 @@ inline void arr_sort(struct xxxid_stats_arr *pa,int (*cb)(const void *a,const vo
 
 inline void calc_total(struct xxxid_stats_arr *cs,double *read,double *write);
 inline void calc_a_total(struct act_stats *act,double *read,double *write,double time_s);
-inline void humanize_val(double *value,char *str,int allow_accum);
+inline void humanize_val(double *value,char *str,int allow_accum, char *dummy_var);
 inline int iotop_sort_cb(const void *a,const void *b);
 inline int create_diff(struct xxxid_stats_arr *cs,struct xxxid_stats_arr *ps,double time_s,uint64_t ts_c,filter_callback_w cb,int width,int *cnt);
 inline int value2scale(double val,double mx);
diff --git a/src/view_batch.c b/src/view_batch.c
index 62dc3b8..0f83b9c 100644
--- a/src/view_batch.c
+++ b/src/view_batch.c
@@ -30,10 +30,10 @@ static inline void view_batch(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 	calc_total(cs,&total_read,&total_write);
 	calc_a_total(act,&total_a_read,&total_a_write,time_s);
 
-	humanize_val(&total_read,str_read,1);
-	humanize_val(&total_write,str_write,1);
-	humanize_val(&total_a_read,str_a_read,0);
-	humanize_val(&total_a_write,str_a_write,0);
+	humanize_val(&total_read,str_read,1, "");
+	humanize_val(&total_write,str_write,1, "");
+	humanize_val(&total_a_read,str_a_read,0, "");
+	humanize_val(&total_a_write,str_a_write,0, "");
 
 	printf(HEADER1_FORMAT,total_read,str_read,"",total_write,str_write,"");
 
@@ -77,8 +77,8 @@ static inline void view_batch(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 		if (s->exited) // do not show exited processes in batch view
 			continue;
 
-		humanize_val(&read_val,read_str,1);
-		humanize_val(&write_val,write_str,1);
+		humanize_val(&read_val,read_str,1, "");
+		humanize_val(&write_val,write_str,1, "");
 
 		pw_name=u8strpadt(s->pw_name,10);
 
diff --git a/src/view_curses.c b/src/view_curses.c
index c2334e4..f1a87f5 100644
--- a/src/view_curses.c
+++ b/src/view_curses.c
@@ -733,10 +733,10 @@ static inline void view_curses(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 		hist_a_w[0]=total_a_write;
 	}
 
-	humanize_val(&total_read,str_read,1);
-	humanize_val(&total_write,str_write,1);
-	humanize_val(&total_a_read,str_a_read,0);
-	humanize_val(&total_a_write,str_a_write,0);
+	humanize_val(&total_read,str_read,1, "");
+	humanize_val(&total_write,str_write,1, "");
+	humanize_val(&total_a_read,str_a_read,0, "");
+	humanize_val(&total_a_write,str_a_write,0, "");
 
 	gr_width_h=gr_width;
 	if (maxy<10||maxx<(int)strlen(HEADER1_FORMAT)+2*(7-5+3-2+(!config.f.hidegraph?gr_width_h+1:0)-2)) {
@@ -1066,8 +1066,8 @@ static inline void view_curses(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 				write_val=s->write_val;
 			}
 
-			humanize_val(&read_val,read_str,1);
-			humanize_val(&write_val,write_str,1);
+			humanize_val(&read_val,read_str,1, "");
+			humanize_val(&write_val,write_str,1, "");
 
 			pwt=esc_low_ascii(s->pw_name);
 			pw_name=u8strpadt(pwt,9);
diff --git a/src/views.c b/src/views.c
index 78bc076..9e1a3d1 100644
--- a/src/views.c
+++ b/src/views.c
@@ -213,7 +213,8 @@ inline int create_diff(struct xxxid_stats_arr *cs,struct xxxid_stats_arr *ps,dou
 	return cs->length;
 }
 
-inline void humanize_val(double *value,char *str,int allow_accum) {
+inline void humanize_val(double *value,char *str,int allow_accum, char *dummy_var) {
+	printf("dummy var: %s\n", dummy_var);
 	const char *u="BKMGTPEZY";
 	size_t p=0;

Patch that generated the "downstream":

diff --git a/src/iotop.h b/src/iotop.h
index 0048a59..ec95b26 100644
--- a/src/iotop.h
+++ b/src/iotop.h
@@ -261,7 +261,7 @@ inline void arr_sort(struct xxxid_stats_arr *pa,int (*cb)(const void *a,const vo
 
 inline void calc_total(struct xxxid_stats_arr *cs,double *read,double *write);
 inline void calc_a_total(struct act_stats *act,double *read,double *write,double time_s);
-inline void humanize_val(double *value,char *str,int allow_accum);
+inline void turn_into_human_value(double *value,char *str,int allow_accum);
 inline int iotop_sort_cb(const void *a,const void *b);
 inline int create_diff(struct xxxid_stats_arr *cs,struct xxxid_stats_arr *ps,double time_s,uint64_t ts_c,filter_callback_w cb,int width,int *cnt);
 inline int value2scale(double val,double mx);
diff --git a/src/view_batch.c b/src/view_batch.c
index 62dc3b8..408b8c0 100644
--- a/src/view_batch.c
+++ b/src/view_batch.c
@@ -30,10 +30,10 @@ static inline void view_batch(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 	calc_total(cs,&total_read,&total_write);
 	calc_a_total(act,&total_a_read,&total_a_write,time_s);
 
-	humanize_val(&total_read,str_read,1);
-	humanize_val(&total_write,str_write,1);
-	humanize_val(&total_a_read,str_a_read,0);
-	humanize_val(&total_a_write,str_a_write,0);
+	turn_into_human_value(&total_read,str_read,1);
+	turn_into_human_value(&total_write,str_write,1);
+	turn_into_human_value(&total_a_read,str_a_read,0);
+	turn_into_human_value(&total_a_write,str_a_write,0);
 
 	printf(HEADER1_FORMAT,total_read,str_read,"",total_write,str_write,"");
 
@@ -77,8 +77,8 @@ static inline void view_batch(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 		if (s->exited) // do not show exited processes in batch view
 			continue;
 
-		humanize_val(&read_val,read_str,1);
-		humanize_val(&write_val,write_str,1);
+		turn_into_human_value(&read_val,read_str,1);
+		turn_into_human_value(&write_val,write_str,1);
 
 		pw_name=u8strpadt(s->pw_name,10);
 
diff --git a/src/view_curses.c b/src/view_curses.c
index c2334e4..96df5b6 100644
--- a/src/view_curses.c
+++ b/src/view_curses.c
@@ -733,10 +733,10 @@ static inline void view_curses(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 		hist_a_w[0]=total_a_write;
 	}
 
-	humanize_val(&total_read,str_read,1);
-	humanize_val(&total_write,str_write,1);
-	humanize_val(&total_a_read,str_a_read,0);
-	humanize_val(&total_a_write,str_a_write,0);
+	turn_into_human_value(&total_read,str_read,1);
+	turn_into_human_value(&total_write,str_write,1);
+	turn_into_human_value(&total_a_read,str_a_read,0);
+	turn_into_human_value(&total_a_write,str_a_write,0);
 
 	gr_width_h=gr_width;
 	if (maxy<10||maxx<(int)strlen(HEADER1_FORMAT)+2*(7-5+3-2+(!config.f.hidegraph?gr_width_h+1:0)-2)) {
@@ -1066,8 +1066,8 @@ static inline void view_curses(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
 				write_val=s->write_val;
 			}
 
-			humanize_val(&read_val,read_str,1);
-			humanize_val(&write_val,write_str,1);
+			turn_into_human_value(&read_val,read_str,1);
+			turn_into_human_value(&write_val,write_str,1);
 
 			pwt=esc_low_ascii(s->pw_name);
 			pw_name=u8strpadt(pwt,9);
diff --git a/src/views.c b/src/views.c
index 78bc076..3927b73 100644
--- a/src/views.c
+++ b/src/views.c
@@ -213,7 +213,7 @@ inline int create_diff(struct xxxid_stats_arr *cs,struct xxxid_stats_arr *ps,dou
 	return cs->length;
 }
 
-inline void humanize_val(double *value,char *str,int allow_accum) {
+inline void turn_into_human_value(double *value,char *str,int allow_accum) {
 	const char *u="BKMGTPEZY";
 	size_t p=0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant