/** * Add an additional search directory for the protocol decoders. * * The specified directory is prepended (not appended!) to Python's sys.path, * in order to search for sigrok protocol decoders in the specified * directories first, and in the generic Python module directories (and in * the current working directory) last. This avoids conflicts if there are * Python modules which have the same name as a sigrok protocol decoder in * sys.path or in the current working directory. * * @param path Path to the directory containing protocol decoders which shall * be added to the Python sys.path, or NULL. * * @return SRD_OK upon success, a (negative) error code otherwise. */ SRD_PRIV int srd_decoder_searchpath_add(const char *path) { PyObject *py_cur_path, *py_item; GString *new_path; int wc_len, i; wchar_t *wc_new_path; char *item; srd_dbg("Adding '%s' to module path.", path); new_path = g_string_sized_new(256); g_string_assign(new_path, g_strdup(path)); py_cur_path = PySys_GetObject("path"); for (i = 0; i < PyList_Size(py_cur_path); i++) { g_string_append(new_path, g_strdup(G_SEARCHPATH_SEPARATOR_S)); py_item = PyList_GetItem(py_cur_path, i); if (!PyUnicode_Check(py_item)) /* Shouldn't happen. */ continue; if (py_str_as_str(py_item, &item) != SRD_OK) continue; g_string_append(new_path, item); } /* Convert to wide chars. */ wc_len = sizeof(wchar_t) * (new_path->len + 1); if (!(wc_new_path = g_try_malloc(wc_len))) { srd_dbg("malloc failed"); return SRD_ERR_MALLOC; } mbstowcs(wc_new_path, new_path->str, wc_len); PySys_SetPath(wc_new_path); g_string_free(new_path, TRUE); g_free(wc_new_path); //#ifdef _WIN32 // gchar **splitted; // // /* // * On Windows/MinGW, Python's sys.path needs entries of the form // * 'C:\\foo\\bar' instead of '/foo/bar'. // */ // // splitted = g_strsplit(DECODERS_DIR, "/", 0); // path = g_build_pathv("\\\\", splitted); // g_strfreev(splitted); //#else // path = g_strdup(DECODERS_DIR); //#endif return SRD_OK; }
static MsnSlpMessage * init_first_msg(MsnSlpLink *slplink, MsnP2PInfo *info) { MsnSlpMessage *slpmsg; guint32 session_id; slpmsg = msn_slpmsg_new(slplink, NULL); slpmsg->id = msn_p2p_info_get_id(info); session_id = msn_p2p_info_get_session_id(info); slpmsg->size = msn_p2p_info_get_total_size(info); msn_p2p_info_init_first(slpmsg->p2p_info, info); if (session_id) { slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, session_id); if (slpmsg->slpcall != NULL) { if (msn_p2p_msg_is_data(info)) { PurpleXfer *xfer = slpmsg->slpcall->xfer; if (xfer != NULL) { slpmsg->ft = TRUE; slpmsg->slpcall->xfer_msg = slpmsg; purple_xfer_ref(xfer); purple_xfer_start(xfer, -1, NULL, 0); if (xfer->data == NULL) { purple_xfer_unref(xfer); msn_slpmsg_destroy(slpmsg); g_return_val_if_reached(NULL); } else { purple_xfer_unref(xfer); } } } } } if (!slpmsg->ft && slpmsg->size) { slpmsg->buffer = g_try_malloc(slpmsg->size); if (slpmsg->buffer == NULL) { purple_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); msn_slpmsg_destroy(slpmsg); return NULL; } } return slpmsg; }
// The caller must free the return value with g_free. gchar* ConvToUtf8CStringL(const TDesC& name16) { HBufC8* des = ConvToUtf8ZL(name16); int strLen = des->Length() + 1; char* str = (char*)(g_try_malloc(strLen)); if (!str) { delete des; User::LeaveNoMemory(); } memcpy(str, des->Ptr(), strLen); delete des; return str; }
/** *Instanciate a #CRTerm. *@return the newly build instance *of #CRTerm. */ CRTerm * cr_term_new (void) { CRTerm *result = NULL; result = g_try_malloc (sizeof (CRTerm)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRTerm)); return result; }
/** * cr_doc_handler_new: *Constructor of #CRDocHandler. * *Returns the newly built instance of *#CRDocHandler * */ CRDocHandler * cr_doc_handler_new (void) { CRDocHandler *result = NULL; result = g_try_malloc (sizeof (CRDocHandler)); g_return_val_if_fail (result, NULL); memset (result, 0, sizeof (CRDocHandler)); result->priv = g_try_malloc (sizeof (CRDocHandlerPriv)); if (!result->priv) { cr_utils_trace_info ("Out of memory exception"); g_free (result); return NULL; } cr_doc_handler_set_default_sac_handler (result); return result; }
static CRInput * cr_input_new_real (void) { CRInput *result = NULL; result = g_try_malloc (sizeof (CRInput)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRInput)); PRIVATE (result) = g_try_malloc (sizeof (CRInputPriv)); if (!PRIVATE (result)) { cr_utils_trace_info ("Out of memory"); g_free (result); return NULL; } memset (PRIVATE (result), 0, sizeof (CRInputPriv)); PRIVATE (result)->free_in_buf = TRUE; return result; }
CRFontSizeAdjust * cr_font_size_adjust_new (void) { CRFontSizeAdjust *result = (CRFontSizeAdjust *)g_try_malloc (sizeof (CRFontSizeAdjust)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRFontSizeAdjust)); return result; }
static ParsingContext * new_parsing_context (void) { ParsingContext *result = NULL; result = g_try_malloc (sizeof (ParsingContext)); if (!result) { cr_utils_trace_info ("Out of Memory"); return NULL; } memset (result, 0, sizeof (ParsingContext)); return result; }
/** * cr_parsing_location_new: *Instanciates a new parsing location. * *Returns the newly instanciated #CRParsingLocation. *Must be freed by cr_parsing_location_destroy() */ CRParsingLocation * cr_parsing_location_new (void) { CRParsingLocation * result = NULL ; result = g_try_malloc (sizeof (CRParsingLocation)) ; if (!result) { cr_utils_trace_info ("Out of memory error") ; return NULL ; } cr_parsing_location_init (result) ; return result ; }
GthBufferData * gth_buffer_data_new (void) { GthBufferData *buffer_data; buffer_data = g_new (GthBufferData, 1); buffer_data->buffer = g_try_malloc (INITIAL_ALLOCATED_SIZE); buffer_data->buffer_size = 0; buffer_data->allocated_size = INITIAL_ALLOCATED_SIZE; buffer_data->current_pos = 0; return buffer_data; }
static void send_chunk(struct sr_dev_inst *sdi, unsigned char *buf, int num_samples) { struct sr_datafeed_packet packet; struct sr_datafeed_analog analog; struct dev_context *devc; float ch1, ch2, range; int num_probes, data_offset, i; devc = sdi->priv; num_probes = (devc->ch1_enabled && devc->ch2_enabled) ? 2 : 1; packet.type = SR_DF_ANALOG; packet.payload = &analog; /* TODO: support for 5xxx series 9-bit samples */ analog.probes = devc->enabled_probes; analog.num_samples = num_samples; analog.mq = SR_MQ_VOLTAGE; analog.unit = SR_UNIT_VOLT; /* TODO: Check malloc return value. */ analog.data = g_try_malloc(analog.num_samples * sizeof(float) * num_probes); data_offset = 0; for (i = 0; i < analog.num_samples; i++) { /* * The device always sends data for both channels. If a channel * is disabled, it contains a copy of the enabled channel's * data. However, we only send the requested channels to * the bus. * * Voltage values are encoded as a value 0-255 (0-512 on the * DSO-5200*), where the value is a point in the range * represented by the vdiv setting. There are 8 vertical divs, * so e.g. 500mV/div represents 4V peak-to-peak where 0 = -2V * and 255 = +2V. */ /* TODO: Support for DSO-5xxx series 9-bit samples. */ if (devc->ch1_enabled) { range = ((float)vdivs[devc->voltage_ch1][0] / vdivs[devc->voltage_ch1][1]) * 8; ch1 = range / 255 * *(buf + i * 2 + 1); /* Value is centered around 0V. */ ch1 -= range / 2; analog.data[data_offset++] = ch1; } if (devc->ch2_enabled) { range = ((float)vdivs[devc->voltage_ch2][0] / vdivs[devc->voltage_ch2][1]) * 8; ch2 = range / 255 * *(buf + i * 2); ch2 -= range / 2; analog.data[data_offset++] = ch2; } } sr_session_send(devc->cb_data, &packet); }
static void s390_storage_keys_save(QEMUFile *f, void *opaque) { S390SKeysState *ss = S390_SKEYS(opaque); S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss); uint64_t pages_left = ram_size / TARGET_PAGE_SIZE; uint64_t read_count, eos = S390_SKEYS_SAVE_FLAG_EOS; vaddr cur_gfn = 0; int error = 0; uint8_t *buf; if (!skeyclass->skeys_enabled(ss)) { goto end_stream; } buf = g_try_malloc(S390_SKEYS_BUFFER_SIZE); if (!buf) { error_report("storage key save could not allocate memory\n"); goto end_stream; } /* We only support initial memory. Standby memory is not handled yet. */ qemu_put_be64(f, (cur_gfn * TARGET_PAGE_SIZE) | S390_SKEYS_SAVE_FLAG_SKEYS); qemu_put_be64(f, pages_left); while (pages_left) { read_count = MIN(pages_left, S390_SKEYS_BUFFER_SIZE); if (!error) { error = skeyclass->get_skeys(ss, cur_gfn, read_count, buf); if (error) { /* * If error: we want to fill the stream with valid data instead * of stopping early so we pad the stream with 0x00 values and * use S390_SKEYS_SAVE_FLAG_ERROR to indicate failure to the * reading side. */ error_report("S390_GET_KEYS error %d\n", error); memset(buf, 0, S390_SKEYS_BUFFER_SIZE); eos = S390_SKEYS_SAVE_FLAG_ERROR; } } qemu_put_buffer(f, buf, read_count); cur_gfn += read_count; pages_left -= read_count; } g_free(buf); end_stream: qemu_put_be64(f, eos); }
/** * cr_simple_sel_new: * *The constructor of #CRSimpleSel. * *Returns the new instance of #CRSimpleSel. */ CRSimpleSel * cr_simple_sel_new (void) { CRSimpleSel *result = NULL; result = g_try_malloc (sizeof (CRSimpleSel)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRSimpleSel)); return result; }
/** *Default constructor of *the #CRToken class. *@return the newly built instance of #CRToken. */ CRToken * cr_token_new (void) { CRToken *result = (CRToken *)g_try_malloc (sizeof (CRToken)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRToken)); return result; }
/** *The default constructor of *#CRNum. *@return the newly built instance of *#CRNum. */ CRNum * cr_num_new (void) { CRNum *result = (CRNum *)g_try_malloc (sizeof (CRNum)); if (result == NULL) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRNum)); return result; }
/** * cr_font_size_new: * * Returns the newly created font size. */ CRFontSize * cr_font_size_new (void) { CRFontSize *result = NULL; result = g_try_malloc (sizeof (CRFontSize)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRFontSize)); return result; }
/** * cr_selector_new: * *@a_simple_sel: the initial simple selector list *of the current instance of #CRSelector. * *Creates a new instance of #CRSelector. * *Returns the newly built instance of #CRSelector, or *NULL in case of failure. */ CRSelector * cr_selector_new (CRSimpleSel * a_simple_sel) { CRSelector *result = NULL; result = g_try_malloc (sizeof (CRSelector)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRSelector)); result->simple_sel = a_simple_sel; return result; }
/** *Instanciates a #CRString *@return the newly instanciated #CRString *Must be freed with cr_string_destroy(). */ CRString * cr_string_new (void) { CRString *result = NULL ; result = (CRString *) g_try_malloc (sizeof (CRString)) ; if (!result) { cr_utils_trace_info ("Out of memory") ; return NULL ; } memset (result, 0, sizeof (CRString)) ; result->stryng = g_string_new (NULL) ; return result ; }
mongo_packet * test_mongo_wire_generate_reply (gboolean valid, gint32 nreturn, gboolean with_docs) { mongo_reply_packet_header rh; mongo_packet_header h; mongo_packet *p; guint8 *data; gint data_size = sizeof (mongo_reply_packet_header); bson *b1 = NULL, *b2 = NULL; p = mongo_wire_packet_new (); h.opcode = (valid) ? GINT32_TO_LE (1) : GINT32_TO_LE (42); h.id = GINT32_TO_LE (1984); h.resp_to = GINT32_TO_LE (42); if (with_docs) { b1 = test_bson_generate_full (); b2 = test_bson_generate_full (); data_size += bson_size (b1) + bson_size (b2); } h.length = GINT32_TO_LE (sizeof (mongo_packet_header) + data_size); mongo_wire_packet_set_header (p, &h); data = g_try_malloc (data_size); rh.flags = 0; rh.cursor_id = GINT64_TO_LE ((gint64)12345); rh.start = 0; rh.returned = GINT32_TO_LE (nreturn); memcpy (data, &rh, sizeof (mongo_reply_packet_header)); if (with_docs) { memcpy (data + sizeof (mongo_reply_packet_header), bson_data (b1), bson_size (b1)); memcpy (data + sizeof (mongo_reply_packet_header) + bson_size (b1), bson_data (b2), bson_size (b2)); } mongo_wire_packet_set_data (p, data, data_size); g_free (data); bson_free (b1); bson_free (b2); return p; }
GIsiPEP *g_isi_pep_create(GIsiModem *modem, GIsiPEPCallback cb, void *opaque) { unsigned ifi = g_isi_modem_index(modem); GIsiPEP *pep = NULL; GIOChannel *channel; int fd; char buf[IF_NAMESIZE]; fd = socket(PF_PHONET, SOCK_SEQPACKET, 0); if (fd == -1) return NULL; fcntl(fd, F_SETFD, FD_CLOEXEC); fcntl(fd, F_SETFL, O_NONBLOCK|fcntl(fd, F_GETFL)); if (if_indextoname(ifi, buf) == NULL) goto error; if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, buf, IF_NAMESIZE) != 0) goto error; pep = g_try_malloc(sizeof(GIsiPEP)); if (pep == NULL) goto error; pep->ready = cb; pep->opaque = opaque; pep->gprs_fd = -1; pep->handle = 0; if (listen(fd, 1) || ioctl(fd, SIOCPNGETOBJECT, &pep->handle)) goto error; channel = g_io_channel_unix_new(fd); g_io_channel_set_close_on_unref(channel, TRUE); g_io_channel_set_encoding(channel, NULL, NULL); g_io_channel_set_buffered(channel, FALSE); pep->source = g_io_add_watch(channel, G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL, g_isi_pep_callback, pep); g_io_channel_unref(channel); return pep; error: close(fd); g_free(pep); return NULL; }
SR_PRIV struct sr_serial_dev_inst *sr_serial_dev_inst_new(const char *port, int fd) { struct sr_serial_dev_inst *serial; if (!(serial = g_try_malloc(sizeof(struct sr_serial_dev_inst)))) { sr_err("hwdriver: %s: serial malloc failed", __func__); return NULL; } serial->port = g_strdup(port); serial->fd = fd; return serial; }
gboolean gst_imx_vpu_alloc_virt_mem_block(unsigned char **mem_block, int size) { setup_debug_category(); *mem_block = (unsigned char *)g_try_malloc(size); if ((*mem_block) == NULL) { GST_ERROR("could not request %d bytes of heap memory", size); return FALSE; } else GST_INFO("allocated %d bytes of heap memory at virt addr %p", size, *mem_block); return TRUE; }
static gboolean parse_uuid(const char *key, const char *value, gpointer user_data, GError **error) { if (!value) return FALSE; opt_uuid = g_try_malloc(sizeof(bt_uuid_t)); if (opt_uuid == NULL) return FALSE; if (bt_string_to_uuid(opt_uuid, value) < 0) return FALSE; return TRUE; }
static int init(struct sr_output *o) { struct context *ctx; if (!(ctx = g_try_malloc(sizeof(struct context)))) { sr_err("%s: ctx malloc failed", __func__); return SR_ERR_MALLOC; } o->internal = ctx; ctx->samplerate = 0; ctx->num_samples = 0; return SR_OK; }
static char *_stripSuffix(const char* from, char delimiter) { // taken from DocBook exporter char * fremove_s = (char *)g_try_malloc(strlen(from)+1); strcpy(fremove_s, from); char * p = fremove_s + strlen(fremove_s); while ((p >= fremove_s) && (*p != delimiter)) p--; if (p >= fremove_s) *p = '\0'; return fremove_s; }
/** * cr_rgb_new: * *The default constructor of #CRRgb. * *Returns the newly built instance of #CRRgb */ CRRgb * cr_rgb_new (void) { CRRgb *result = NULL; result = g_try_malloc (sizeof (CRRgb)); if (result == NULL) { cr_utils_trace_info ("No more memory"); return NULL; } memset (result, 0, sizeof (CRRgb)); return result; }
/** @private */ SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus, uint8_t address, struct libusb_device_handle *hdl) { struct sr_usb_dev_inst *udi; if (!(udi = g_try_malloc(sizeof(struct sr_usb_dev_inst)))) { sr_err("USB device instance malloc failed."); return NULL; } udi->bus = bus; udi->address = address; udi->devhdl = hdl; return udi; }
SR_PRIV struct sr_usb_dev_inst *sr_usb_dev_inst_new(uint8_t bus, uint8_t address, struct libusb_device_handle *hdl) { struct sr_usb_dev_inst *udi; if (!(udi = g_try_malloc(sizeof(struct sr_usb_dev_inst)))) { sr_err("hwdriver: %s: udi malloc failed", __func__); return NULL; } udi->bus = bus; udi->address = address; udi->devhdl = hdl; return udi; }
static GSList *scan(GSList *options) { struct sr_dev_inst *sdi; struct sr_probe *probe; struct drv_context *drvc; struct dev_context *devc; GSList *devices; int i; (void)options; drvc = di->priv; devices = NULL; sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, DEMONAME, NULL, NULL); if (!sdi) { sr_err("Device instance creation failed."); return NULL; } sdi->driver = di; for (i = 0; probe_names[i]; i++) { if (!(probe = sr_probe_new(i, SR_PROBE_LOGIC, TRUE, probe_names[i]))) return NULL; sdi->probes = g_slist_append(sdi->probes, probe); } devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); if (!(devc = g_try_malloc(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; } devc->sdi = sdi; devc->cur_samplerate = SR_KHZ(200); devc->limit_samples = 0; devc->limit_msec = 0; devc->sample_generator = PATTERN_SIGROK; sdi->priv = devc; return devices; }
CRFontFamily * cr_font_family_new (enum CRFontFamilyType a_type, guchar * a_name) { CRFontFamily *result = (CRFontFamily *)g_try_malloc (sizeof (CRFontFamily)); if (!result) { cr_utils_trace_info ("Out of memory"); return NULL; } memset (result, 0, sizeof (CRFontFamily)); result->type = a_type; cr_font_family_set_name (result, a_name); return result; }