Przeglądaj źródła

libdpkg: Expand buffer_copy_TYPE macro instances

This makes the code easier to debug, as it will be able to track
correct code lines, it also allows to more easily see the code
duplication explicitly, and makes the code slightly more clear as
it's using the real structure member and type names.
Guillem Jover 15 lat temu
rodzic
commit
7e7236f7e1
1 zmienionych plików z 41 dodań i 23 usunięć
  1. 41 23
      lib/dpkg/buffer.c

+ 41 - 23
lib/dpkg/buffer.c

@@ -204,28 +204,46 @@ buffer_copy(struct buffer_data *read_data, struct buffer_data *write_data,
 	return totalread;
 }
 
-#define buffer_copy_TYPE(name, type1, name1, type2, name2) \
-off_t \
-buffer_copy_##name(type1 n1, int typeIn, \
-                   type2 n2, int typeOut, \
-                   off_t limit, const char *desc, ...) \
-{ \
-	va_list args; \
-	struct buffer_data read_data = { .arg.name1 = n1, .type = typeIn }; \
-	struct buffer_data write_data = { .arg.name2 = n2, .type = typeOut }; \
-	struct varbuf v = VARBUF_INIT; \
-	off_t ret; \
-\
-	va_start(args, desc); \
-	varbuf_vprintf(&v, desc, args); \
-	va_end(args); \
-\
-	ret = buffer_copy(&read_data, &write_data, limit, v.buf); \
-\
-	varbuf_destroy(&v); \
-\
-	return ret; \
+off_t
+buffer_copy_IntInt(int Iin, int Tin,
+                   int Iout, int Tout,
+                   off_t limit, const char *desc, ...)
+{
+	va_list args;
+	struct buffer_data read_data = { .type = Tin, .arg.i = Iin };
+	struct buffer_data write_data = { .type = Tout, .arg.i = Iout };
+	struct varbuf v = VARBUF_INIT;
+	off_t ret;
+
+	va_start(args, desc);
+	varbuf_vprintf(&v, desc, args);
+	va_end(args);
+
+	ret = buffer_copy(&read_data, &write_data, limit, v.buf);
+
+	varbuf_destroy(&v);
+
+	return ret;
 }
 
-buffer_copy_TYPE(IntInt, int, i, int, i);
-buffer_copy_TYPE(IntPtr, int, i, void *, ptr);
+off_t
+buffer_copy_IntPtr(int Iin, int Tin,
+                   void *Pout, int Tout,
+                   off_t limit, const char *desc, ...)
+{
+	va_list args;
+	struct buffer_data read_data = { .type = Tin, .arg.i = Iin };
+	struct buffer_data write_data = { .type = Tout, .arg.ptr = Pout };
+	struct varbuf v = VARBUF_INIT;
+	off_t ret;
+
+	va_start(args, desc);
+	varbuf_vprintf(&v, desc, args);
+	va_end(args);
+
+	ret = buffer_copy(&read_data, &write_data, limit, v.buf);
+
+	varbuf_destroy(&v);
+
+	return ret;
+}