This is an automated email from Gerrit.

Andreas Fritiofson ([email protected]) just uploaded a new patch set 
to Gerrit, which you can find at http://openocd.zylin.com/3666

-- gerrit

commit 22dfb46e17655ede61a358145eb5b92aeb7db7a9
Author: Andreas Fritiofson <[email protected]>
Date:   Thu Aug 11 15:21:52 2016 +0200

    target: Constify struct target_type
    
    It's bad design to have the targets' methods replaceable by generic
    code. Make all target_types const and store them by reference
    instead of by copy in struct target.
    
    Change-Id: If58389c0f51994cf250dbbbc9f04c2d69bedfb1f
    Signed-off-by: Andreas Fritiofson <[email protected]>

diff --git a/src/target/arm11.c b/src/target/arm11.c
index 50c8132..85cc7f7 100644
--- a/src/target/arm11.c
+++ b/src/target/arm11.c
@@ -1349,7 +1349,7 @@ static const struct command_registration 
arm11_command_handlers[] = {
 };
 
 /** Holds methods for ARM11xx targets. */
-struct target_type arm11_target = {
+const struct target_type arm11_target = {
        .name = "arm11",
 
        .poll = arm11_poll,
diff --git a/src/target/arm720t.c b/src/target/arm720t.c
index 3991e19..cd1a267 100644
--- a/src/target/arm720t.c
+++ b/src/target/arm720t.c
@@ -546,7 +546,7 @@ static const struct command_registration 
arm720t_command_handlers[] = {
 };
 
 /** Holds methods for ARM720 targets. */
-struct target_type arm720t_target = {
+const struct target_type arm720t_target = {
        .name = "arm720t",
 
        .poll = arm7_9_poll,
diff --git a/src/target/arm7tdmi.c b/src/target/arm7tdmi.c
index 58ab027..655d232 100644
--- a/src/target/arm7tdmi.c
+++ b/src/target/arm7tdmi.c
@@ -682,7 +682,7 @@ static int arm7tdmi_target_create(struct target *target, 
Jim_Interp *interp)
 }
 
 /** Holds methods for ARM7TDMI targets. */
-struct target_type arm7tdmi_target = {
+const struct target_type arm7tdmi_target = {
        .name = "arm7tdmi",
 
        .poll = arm7_9_poll,
diff --git a/src/target/arm920t.c b/src/target/arm920t.c
index 2c96d19..b3d08e4 100644
--- a/src/target/arm920t.c
+++ b/src/target/arm920t.c
@@ -1677,7 +1677,7 @@ const struct command_registration 
arm920t_command_handlers[] = {
 };
 
 /** Holds methods for ARM920 targets. */
-struct target_type arm920t_target = {
+const struct target_type arm920t_target = {
        .name = "arm920t",
 
        .poll = arm7_9_poll,
diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c
index 6998398..7f8a94c 100644
--- a/src/target/arm926ejs.c
+++ b/src/target/arm926ejs.c
@@ -788,7 +788,7 @@ const struct command_registration 
arm926ejs_command_handlers[] = {
 };
 
 /** Holds methods for ARM926 targets. */
-struct target_type arm926ejs_target = {
+const struct target_type arm926ejs_target = {
        .name = "arm926ejs",
 
        .poll = arm7_9_poll,
diff --git a/src/target/arm946e.c b/src/target/arm946e.c
index 5ee31cc..e0893b0 100644
--- a/src/target/arm946e.c
+++ b/src/target/arm946e.c
@@ -740,7 +740,7 @@ const struct command_registration 
arm946e_command_handlers[] = {
 };
 
 /** Holds methods for ARM946 targets. */
-struct target_type arm946e_target = {
+const struct target_type arm946e_target = {
        .name = "arm946e",
 
        .poll = arm7_9_poll,
diff --git a/src/target/arm966e.c b/src/target/arm966e.c
index 0429c54..33ae075 100644
--- a/src/target/arm966e.c
+++ b/src/target/arm966e.c
@@ -243,7 +243,7 @@ const struct command_registration 
arm966e_command_handlers[] = {
 };
 
 /** Holds methods for ARM966 targets. */
-struct target_type arm966e_target = {
+const struct target_type arm966e_target = {
        .name = "arm966e",
 
        .poll = arm7_9_poll,
diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c
index eed965a..0abae0c 100644
--- a/src/target/arm9tdmi.c
+++ b/src/target/arm9tdmi.c
@@ -884,7 +884,7 @@ const struct command_registration 
arm9tdmi_command_handlers[] = {
 };
 
 /** Holds methods for ARM9TDMI targets. */
-struct target_type arm9tdmi_target = {
+const struct target_type arm9tdmi_target = {
        .name = "arm9tdmi",
 
        .poll = arm7_9_poll,
diff --git a/src/target/avr32_ap7k.c b/src/target/avr32_ap7k.c
index e5634f2..6a86d10 100644
--- a/src/target/avr32_ap7k.c
+++ b/src/target/avr32_ap7k.c
@@ -591,7 +591,7 @@ int avr32_ap7k_get_gdb_reg_list(struct target *target, 
struct reg **reg_list[],
        return ERROR_FAIL;
 }
 
-struct target_type avr32_ap7k_target = {
+const struct target_type avr32_ap7k_target = {
        .name = "avr32_ap7k",
 
        .poll = avr32_ap7k_poll,
diff --git a/src/target/avrt.c b/src/target/avrt.c
index 40a1297..2374803 100644
--- a/src/target/avrt.c
+++ b/src/target/avrt.c
@@ -47,7 +47,7 @@ static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, 
uint8_t *dr_out, i
 static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t 
ir_out, int ir_len, int rti);
 static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t 
ir_out, int dr_len, int rti);
 
-struct target_type avr_target = {
+const struct target_type avr_target = {
        .name = "avr",
 
        .poll = avr_poll,
diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c
index 7ad9dc4..cd7d17c 100644
--- a/src/target/cortex_a.c
+++ b/src/target/cortex_a.c
@@ -3463,7 +3463,7 @@ static const struct command_registration 
cortex_a_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct target_type cortexa_target = {
+const struct target_type cortexa_target = {
        .name = "cortex_a",
        .deprecated_name = "cortex_a8",
 
@@ -3552,7 +3552,7 @@ static const struct command_registration 
cortex_r4_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct target_type cortexr4_target = {
+const struct target_type cortexr4_target = {
        .name = "cortex_r4",
 
        .poll = cortex_a_poll,
diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c
index a6a9309..e5d6e63 100644
--- a/src/target/cortex_m.c
+++ b/src/target/cortex_m.c
@@ -2388,7 +2388,7 @@ static const struct command_registration 
cortex_m_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct target_type cortexm_target = {
+const struct target_type cortexm_target = {
        .name = "cortex_m",
        .deprecated_name = "cortex_m3",
 
diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c
index 783a019..47ccecf 100644
--- a/src/target/dsp563xx.c
+++ b/src/target/dsp563xx.c
@@ -2304,7 +2304,7 @@ static const struct command_registration 
dsp563xx_command_handlers[] = {
 };
 
 /** Holds methods for DSP563XX targets. */
-struct target_type dsp563xx_target = {
+const struct target_type dsp563xx_target = {
        .name = "dsp563xx",
 
        .poll = dsp563xx_poll,
diff --git a/src/target/dsp5680xx.c b/src/target/dsp5680xx.c
index 205d8fe..b2f8581 100644
--- a/src/target/dsp5680xx.c
+++ b/src/target/dsp5680xx.c
@@ -2270,7 +2270,7 @@ static int dsp5680xx_step(struct target *target, int 
current, uint32_t address,
 }
 
 /** Holds methods for dsp5680xx targets. */
-struct target_type dsp5680xx_target = {
+const struct target_type dsp5680xx_target = {
        .name = "dsp5680xx",
 
        .poll = dsp5680xx_poll,
diff --git a/src/target/fa526.c b/src/target/fa526.c
index 9f6b805..3518238 100644
--- a/src/target/fa526.c
+++ b/src/target/fa526.c
@@ -348,7 +348,7 @@ static int fa526_target_create(struct target *target, 
Jim_Interp *interp)
 }
 
 /** Holds methods for FA526 targets. */
-struct target_type fa526_target = {
+const struct target_type fa526_target = {
        .name = "fa526",
 
        .poll = arm7_9_poll,
diff --git a/src/target/feroceon.c b/src/target/feroceon.c
index f12e4e4..57cea34 100644
--- a/src/target/feroceon.c
+++ b/src/target/feroceon.c
@@ -694,7 +694,7 @@ static int feroceon_examine(struct target *target)
        return ERROR_OK;
 }
 
-struct target_type feroceon_target = {
+const struct target_type feroceon_target = {
        .name = "feroceon",
 
        .poll = arm7_9_poll,
@@ -731,7 +731,7 @@ struct target_type feroceon_target = {
        .examine = feroceon_examine,
 };
 
-struct target_type dragonite_target = {
+const struct target_type dragonite_target = {
        .name = "dragonite",
 
        .poll = arm7_9_poll,
diff --git a/src/target/hla_target.c b/src/target/hla_target.c
index e02abc4..4eb2da7 100644
--- a/src/target/hla_target.c
+++ b/src/target/hla_target.c
@@ -776,7 +776,7 @@ static const struct command_registration 
adapter_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct target_type hla_target = {
+const struct target_type hla_target = {
        .name = "hla_target",
        .deprecated_name = "stm32_stlink",
 
diff --git a/src/target/ls1_sap.c b/src/target/ls1_sap.c
index 944e725..be453e9 100644
--- a/src/target/ls1_sap.c
+++ b/src/target/ls1_sap.c
@@ -222,7 +222,7 @@ static int ls1_sap_write_memory(struct target *target, 
uint32_t address,
        return jtag_execute_queue();
 }
 
-struct target_type ls1_sap_target = {
+const struct target_type ls1_sap_target = {
        .name = "ls1_sap",
 
        .target_create = ls1_sap_target_create,
diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c
index 0daa71c..587859b 100644
--- a/src/target/mips_m4k.c
+++ b/src/target/mips_m4k.c
@@ -1403,7 +1403,7 @@ const struct command_registration 
mips_m4k_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct target_type mips_m4k_target = {
+const struct target_type mips_m4k_target = {
        .name = "mips_m4k",
 
        .poll = mips_m4k_poll,
diff --git a/src/target/nds32_v2.c b/src/target/nds32_v2.c
index 2db8194..b942d99 100644
--- a/src/target/nds32_v2.c
+++ b/src/target/nds32_v2.c
@@ -737,7 +737,7 @@ static int nds32_v2_write_memory(struct target *target, 
uint32_t address,
 }
 
 /** Holds methods for V2 targets. */
-struct target_type nds32_v2_target = {
+const struct target_type nds32_v2_target = {
        .name = "nds32_v2",
 
        .poll = nds32_poll,
diff --git a/src/target/nds32_v3.c b/src/target/nds32_v3.c
index 43d7054..0772369 100644
--- a/src/target/nds32_v3.c
+++ b/src/target/nds32_v3.c
@@ -468,7 +468,7 @@ static int nds32_v3_examine(struct target *target)
 }
 
 /** Holds methods for Andes1337 targets. */
-struct target_type nds32_v3_target = {
+const struct target_type nds32_v3_target = {
        .name = "nds32_v3",
 
        .poll = nds32_poll,
diff --git a/src/target/nds32_v3m.c b/src/target/nds32_v3m.c
index 919c0c8..8ef2e46 100644
--- a/src/target/nds32_v3m.c
+++ b/src/target/nds32_v3m.c
@@ -455,7 +455,7 @@ static int nds32_v3m_examine(struct target *target)
 }
 
 /** Holds methods for NDS32 V3m targets. */
-struct target_type nds32_v3m_target = {
+const struct target_type nds32_v3m_target = {
        .name = "nds32_v3m",
 
        .poll = nds32_poll,
diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c
index 2cc869f..1e5d1ba 100644
--- a/src/target/openrisc/or1k.c
+++ b/src/target/openrisc/or1k.c
@@ -1424,7 +1424,7 @@ static const struct command_registration 
or1k_command_handlers[] = {
 };
 
 
-struct target_type or1k_target = {
+const struct target_type or1k_target = {
        .name = "or1k",
 
        .poll = or1k_poll,
diff --git a/src/target/quark_d20xx.c b/src/target/quark_d20xx.c
index 42d3b8c..6e974f4 100644
--- a/src/target/quark_d20xx.c
+++ b/src/target/quark_d20xx.c
@@ -87,7 +87,7 @@ static int quark_d20xx_reset_deassert(struct target *t)
        return ERROR_OK;
 }
 
-struct target_type quark_d20xx_target = {
+const struct target_type quark_d20xx_target = {
        .name = "quark_d20xx",
        .target_create = quark_d20xx_target_create,
        .init_target = quark_d20xx_init_target,
diff --git a/src/target/quark_x10xx.c b/src/target/quark_x10xx.c
index 189f6cc..68f784b 100644
--- a/src/target/quark_x10xx.c
+++ b/src/target/quark_x10xx.c
@@ -69,7 +69,7 @@ int quark_x10xx_init_target(struct command_context *cmd_ctx, 
struct target *t)
        return lakemont_init_target(cmd_ctx, t);
 }
 
-struct target_type quark_x10xx_target = {
+const struct target_type quark_x10xx_target = {
        .name = "quark_x10xx",
        /* Quark X1000 SoC */
        .target_create = quark_x10xx_target_create,
diff --git a/src/target/target.c b/src/target/target.c
index e3228d0..37c2ab7 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -71,37 +71,37 @@ static int target_profiling_default(struct target *target, 
uint32_t *samples,
                uint32_t max_num_samples, uint32_t *num_samples, uint32_t 
seconds);
 
 /* targets */
-extern struct target_type arm7tdmi_target;
-extern struct target_type arm720t_target;
-extern struct target_type arm9tdmi_target;
-extern struct target_type arm920t_target;
-extern struct target_type arm966e_target;
-extern struct target_type arm946e_target;
-extern struct target_type arm926ejs_target;
-extern struct target_type fa526_target;
-extern struct target_type feroceon_target;
-extern struct target_type dragonite_target;
-extern struct target_type xscale_target;
-extern struct target_type cortexm_target;
-extern struct target_type cortexa_target;
-extern struct target_type cortexr4_target;
-extern struct target_type arm11_target;
-extern struct target_type ls1_sap_target;
-extern struct target_type mips_m4k_target;
-extern struct target_type avr_target;
-extern struct target_type dsp563xx_target;
-extern struct target_type dsp5680xx_target;
-extern struct target_type testee_target;
-extern struct target_type avr32_ap7k_target;
-extern struct target_type hla_target;
-extern struct target_type nds32_v2_target;
-extern struct target_type nds32_v3_target;
-extern struct target_type nds32_v3m_target;
-extern struct target_type or1k_target;
-extern struct target_type quark_x10xx_target;
-extern struct target_type quark_d20xx_target;
-
-static struct target_type *target_types[] = {
+extern const struct target_type arm7tdmi_target;
+extern const struct target_type arm720t_target;
+extern const struct target_type arm9tdmi_target;
+extern const struct target_type arm920t_target;
+extern const struct target_type arm966e_target;
+extern const struct target_type arm946e_target;
+extern const struct target_type arm926ejs_target;
+extern const struct target_type fa526_target;
+extern const struct target_type feroceon_target;
+extern const struct target_type dragonite_target;
+extern const struct target_type xscale_target;
+extern const struct target_type cortexm_target;
+extern const struct target_type cortexa_target;
+extern const struct target_type cortexr4_target;
+extern const struct target_type arm11_target;
+extern const struct target_type ls1_sap_target;
+extern const struct target_type mips_m4k_target;
+extern const struct target_type avr_target;
+extern const struct target_type dsp563xx_target;
+extern const struct target_type dsp5680xx_target;
+extern const struct target_type testee_target;
+extern const struct target_type avr32_ap7k_target;
+extern const struct target_type hla_target;
+extern const struct target_type nds32_v2_target;
+extern const struct target_type nds32_v3_target;
+extern const struct target_type nds32_v3m_target;
+extern const struct target_type or1k_target;
+extern const struct target_type quark_x10xx_target;
+extern const struct target_type quark_d20xx_target;
+
+static const struct target_type * const target_types[] = {
        &arm7tdmi_target,
        &arm9tdmi_target,
        &arm920t_target,
@@ -1221,7 +1221,7 @@ static int target_init_one(struct command_context 
*cmd_ctx,
 {
        target_reset_examined(target);
 
-       struct target_type *type = target->type;
+       const struct target_type *type = target->type;
 
        assert(type->init_target != NULL);
 
@@ -5277,10 +5277,7 @@ static int target_create(Jim_GetOptInfo *goi)
        target->target_number = new_target_number();
        cmd_ctx->current_target = target->target_number;
 
-       /* allocate memory for each unique target type */
-       target->type = calloc(1, sizeof(struct target_type));
-
-       memcpy(target->type, target_types[x], sizeof(struct target_type));
+       target->type = target_types[x];
 
        /* will be set by "-endian" */
        target->endianness = TARGET_ENDIAN_UNKNOWN;
@@ -5333,7 +5330,6 @@ static int target_create(Jim_GetOptInfo *goi)
        }
 
        if (e != JIM_OK) {
-               free(target->type);
                free(target);
                return e;
        }
diff --git a/src/target/target.h b/src/target/target.h
index bc36504..956f59c 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -124,7 +124,7 @@ enum target_register_class {
 
 /* target_type.h contains the full definition of struct target_type */
 struct target {
-       struct target_type *type;                       /* target type 
definition (name, access functions) */
+       const struct target_type *type;         /* target type definition 
(name, access functions) */
        const char *cmd_name;                           /* tcl Name of target */
        int target_number;                                      /* DO NOT USE!  
field to be removed in 2010 */
        struct jtag_tap *tap;                           /* where on the jtag 
chain is this */
diff --git a/src/target/testee.c b/src/target/testee.c
index 5b6cced..3d64235 100644
--- a/src/target/testee.c
+++ b/src/target/testee.c
@@ -61,7 +61,7 @@ static int testee_reset_deassert(struct target *target)
        target->state = TARGET_RUNNING;
        return ERROR_OK;
 }
-struct target_type testee_target = {
+const struct target_type testee_target = {
        .name = "testee",
        .commands = testee_command_handlers,
 
diff --git a/src/target/xscale.c b/src/target/xscale.c
index 3d5abdf..8ef8c81 100644
--- a/src/target/xscale.c
+++ b/src/target/xscale.c
@@ -3688,7 +3688,7 @@ static const struct command_registration 
xscale_command_handlers[] = {
        COMMAND_REGISTRATION_DONE
 };
 
-struct target_type xscale_target = {
+const struct target_type xscale_target = {
        .name = "xscale",
 
        .poll = xscale_poll,

-- 

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. http://sdm.link/zohodev2dev
_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to