diff --git a/camlibs/ptp2/ptp-pack.c b/camlibs/ptp2/ptp-pack.c index eb6ac421a..ffca2ee32 100644 --- a/camlibs/ptp2/ptp-pack.c +++ b/camlibs/ptp2/ptp-pack.c @@ -1698,12 +1698,20 @@ ptp_pack_EOS_CustomFuncEx (PTPParams* params, unsigned char* data, char* str) static inline PTPDevicePropDesc* ptp_find_eos_devicepropdesc(PTPParams *params, uint32_t dpc) { - for (unsigned j=0; j < params->canon_props_len; j++) - if (params->canon_props[j].DevicePropCode == dpc) - return ¶ms->canon_props[j]; + for_each (PTPDevicePropDesc*, pdpd, params->canon_props) + if (pdpd->DevicePropCode == dpc) + return pdpd; return NULL; } +/* this helper is required, since array_push_back contains a "return GP_ERROR_NO_MEMEORY" statement */ +static int +_swallow_error_push_back_dpd(PTPDevicePropDescs *dpds, PTPDevicePropDesc new) +{ + array_push_back(dpds, new); + return 0; +} + static PTPDevicePropDesc* _lookup_or_allocate_canon_prop(PTPParams *params, uint32_t dpc) { @@ -1712,14 +1720,14 @@ _lookup_or_allocate_canon_prop(PTPParams *params, uint32_t dpc) if (dpd) return dpd; - unsigned j = params->canon_props_len; - params->canon_props = realloc(params->canon_props, sizeof(params->canon_props[0])*(j+1)); - memset (¶ms->canon_props[j],0,sizeof(params->canon_props[j])); - params->canon_props[j].DevicePropCode = dpc; - params->canon_props[j].GetSet = 1; - params->canon_props[j].FormFlag = PTP_DPFF_None; - params->canon_props_len = j+1; - return ¶ms->canon_props[j]; + PTPDevicePropDesc new = {0}; + new.DevicePropCode = dpc; + new.GetSet = 1; + + if (_swallow_error_push_back_dpd(¶ms->canon_props, new)) + return NULL; + else + return ¶ms->canon_props.val[params->canon_props.len-1]; } #define PTP_CANON_SET_INFO( ENTRY, MSG, ...) \ @@ -2331,8 +2339,7 @@ static unsigned int olcsizes[0x15][13] = { * EOS R also 7 bytes * 7 bytes: 01 01 a0 0c 00 0c 00 */ - uint16_t dpc = PTP_DPC_CANON_EOS_ShutterSpeed; - dpd = _lookup_or_allocate_canon_prop(params, dpc); + dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_ShutterSpeed); if (olcver >= 0x14) { /* taken from northofyou branch */ dpd->CurrentValue.u16 = curdata[curoff+7]; } else { @@ -2340,7 +2347,7 @@ static unsigned int olcsizes[0x15][13] = { } e[i].type = PTP_EOSEvent_PropertyChanged; - e[i].u.propid = dpc; + e[i].u.propid = dpd->DevicePropCode; break; } case 0x0004: { /* Aperture */ @@ -2351,8 +2358,7 @@ static unsigned int olcsizes[0x15][13] = { * EOS M6 Mark 2: * 9 bytes: 01 03 00 58 00 2d 00 30 00 */ - uint16_t dpc = PTP_DPC_CANON_EOS_Aperture; - dpd = _lookup_or_allocate_canon_prop(params, dpc); + dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_Aperture); if (olcver >= 0x12) { dpd->CurrentValue.u16 = curdata[curoff+7]; /* RP, R5, etc */ } else { @@ -2360,19 +2366,18 @@ static unsigned int olcsizes[0x15][13] = { } e[i].type = PTP_EOSEvent_PropertyChanged; - e[i].u.propid = dpc; + e[i].u.propid = dpd->DevicePropCode; break; } case 0x0008: { /* ISO */ /* 4 bytes: 01 01 00 78 */ /* EOS M6 Mark2: 01 01 00 6b 68 28 */ /* this seem to be the ISO record */ - uint16_t dpc = PTP_DPC_CANON_EOS_ISOSpeed; - dpd = _lookup_or_allocate_canon_prop(params, dpc); + dpd = _lookup_or_allocate_canon_prop(params, PTP_DPC_CANON_EOS_ISOSpeed); dpd->CurrentValue.u16 = curdata[curoff+3]; /* just use last byte */ e[i].type = PTP_EOSEvent_PropertyChanged; - e[i].u.propid = dpc; + e[i].u.propid = dpd->DevicePropCode; break; } case 0x0040: { /* Exposure Indicator */ diff --git a/camlibs/ptp2/ptp-private.h b/camlibs/ptp2/ptp-private.h index 5eb404891..ca0f4a99a 100644 --- a/camlibs/ptp2/ptp-private.h +++ b/camlibs/ptp2/ptp-private.h @@ -141,8 +141,8 @@ have_eos_prop(PTPParams *params, uint16_t vendor, uint16_t prop) { /* The special Canon EOS property set gets special treatment. */ if ((params->deviceinfo.VendorExtensionID != PTP_VENDOR_CANON) || (vendor != PTP_VENDOR_CANON)) return 0; - for (i=0;icanon_props_len;i++) - if (params->canon_props[i].DevicePropCode == prop) + for (i=0;icanon_props.len;i++) + if (params->canon_props.val[i].DevicePropCode == prop) return 1; return 0; } diff --git a/camlibs/ptp2/ptp.c b/camlibs/ptp2/ptp.c index 254fd914f..69ff03fa0 100644 --- a/camlibs/ptp2/ptp.c +++ b/camlibs/ptp2/ptp.c @@ -2087,11 +2087,8 @@ ptp_free_params (PTPParams *params) free (params->objects); free_array (¶ms->storageids); free (params->events); - for (i=0;icanon_props_len;i++) { - ptp_free_devicepropdesc (¶ms->canon_props[i]); - } - free (params->canon_props); + free_array_recusive (¶ms->canon_props, ptp_free_devicepropdesc); free_array_recusive (¶ms->eos_events, ptp_free_eos_event); for (i=0;idpd_cache_len;i++) diff --git a/camlibs/ptp2/ptp.h b/camlibs/ptp2/ptp.h index 1a6b6421f..4ff314748 100644 --- a/camlibs/ptp2/ptp.h +++ b/camlibs/ptp2/ptp.h @@ -122,6 +122,7 @@ static inline uint32_t _post_inc(uint32_t* o, int n) GP_LOG_E ("Out of memory: 'realloc' of %ld bytes failed.", ((ARRAY)->len + (LEN)) * sizeof((ARRAY)->val[0])); \ return GP_ERROR_NO_MEMORY; \ } \ + memset((ARRAY)->val + (ARRAY)->len, 0, LEN); \ } while(0) #define array_push_back(ARRAY, VAL) do { \ @@ -3865,7 +3866,6 @@ typedef void (* PTPDebugFunc) (void *data, const char *format, va_list args) ; typedef ARRAY_OF(MTPObjectProp) MTPObjectProps; -typedef ARRAY_OF(PTPCanonEOSEvent) PTPCanonEOSEvents; struct _PTPObject { uint32_t oid; @@ -3913,6 +3913,9 @@ typedef struct _PanasonicLiveViewSize PanasonicLiveViewSize; #define PTP_DP_GETDATA 0x0002 /* receiving data */ #define PTP_DP_DATA_MASK 0x00ff /* data phase mask */ +typedef ARRAY_OF(PTPCanonEOSEvent) PTPCanonEOSEvents; +typedef ARRAY_OF(PTPDevicePropDesc) PTPDevicePropDescs; + struct _PTPParams { /* device flags */ uint32_t device_flags; @@ -3985,8 +3988,7 @@ struct _PTPParams { unsigned int dpd_cache_len; /* PTP: Canon specific flags list */ - PTPDevicePropDesc *canon_props; - unsigned int canon_props_len; + PTPDevicePropDescs canon_props; int canon_viewfinder_on; int canon_event_mode;