From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 2 19:07:24 2014 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 66578A62; Sun, 2 Mar 2014 19:07:24 +0000 (UTC) Received: from mail-wg0-x231.google.com (mail-wg0-x231.google.com [IPv6:2a00:1450:400c:c00::231]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id C275E1D81; Sun, 2 Mar 2014 19:07:23 +0000 (UTC) Received: by mail-wg0-f49.google.com with SMTP id b13so436077wgh.8 for ; Sun, 02 Mar 2014 11:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:from:date:message-id:subject:to:cc :content-type; bh=mRPtxAsKV94f/5WZ/bpDCs2rAxDcCJtHBJSKjriSXVA=; b=wnCYF2MrVdsWxhPPl97EEmX4acWnjBz2xVtO+3Gjg+lr8F8ULAtN+tdBURLrtrFlUO w1J3yRaql58+S4XSx2YYiEmC4bO83LJS4nwJQubgjYfPQ3YaD/eLY7scFrkant01A9sG VV/WL/ost2kSakwXHvmRbqX7fY5J/Ls1oA8nv7PhkJd3S8LwFN2Kmjq5n/2Wmfw/bhGX VbHA4F2WU4+pTNbVdBebCOBxzrL2WYq0Zow7agdpfaAweZeKXcZXL9SRyp8VqN3AfXxW jDQMMGKpUE0jkk8n00XZ/d9DW8es4k1k88neRJ6cv+7TyOPZKzBmQgsfxtheJa6MDNnP ySoA== X-Received: by 10.194.91.232 with SMTP id ch8mr11806730wjb.13.1393787242179; Sun, 02 Mar 2014 11:07:22 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.206.68 with HTTP; Sun, 2 Mar 2014 11:07:02 -0800 (PST) From: Dmitry Selyutin Date: Sun, 2 Mar 2014 23:07:02 +0400 Message-ID: Subject: Re: GSoC proposal: Quirinus C library (qc) To: =?UTF-8?Q?Edward_Tomasz_Napiera=C5=82a?= Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.17 Cc: Jordan Hubbard , =?UTF-8?B?Pz91a2FzeiBXw7NqY2lr?= , John-Mark Gurney , hackers@freebsd.org, =?UTF-8?Q?Fernando_Apestegu=C3=ADa?= X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: ghostmansd@gmail.com List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Mar 2014 19:07:24 -0000 Hello everyone! In order to meet both GSoC requirements and to realize the most necessary features first, I thought that it may be a good idea to start qc library with core and i18n modules, since it seems to be a part where Open Source suffers at most. But first I'd like to start with some general changes inside the entire library. Then I'd like to send a letter (or may be two, I guess) to describe both *core* and *i18n* modules. 1. The types that may be found in *core* module are unprefixed; the names for the other types begin with module name followed by type name (e.g. *qc_bytes*, but *qc_i18n_calendar*). 2. Each new type will receive a new macro that is used to initialize variable on the stack. Such macro will be the uppercase form of the type name, e.g.: qc_bytes encbuf = QC_BYTES; /* initialize new object */ I want to do it since I've realized that users sometimes need to allocate type on the stack, not on the heap. qc_TYPE_release may be used to free memory after object initialization or modification. So we will have actually four general functions: void * qc_TYPE_construct(void); /* allocate new TYPE on the stack */ void * qc_TYPE_replicate(void const*); /* allocate new TYPE and copy data from the old one */ void qc_TYPE_destruct(void*); /* deallocate TYPE and all its data */ void qc_TYPE_release(void*); /* free memory occupied by data of TYPE */ One may argue that it may be overkill to have qc_TYPE_construct while we have qc_alloc and it is even worse to have both qc_TYPE_destruct and qc_TYPE_release. The main reason why I do it is to provide general-type array which will provide C++-like vectors. I'd like to discuss it; probably qc_TYPE_replicate and qc_TYPE_release are enough to go. 3. Allocations and reallocations store size of allocated memory before returned pointer (i.e. allocate `size` of bytes plus `sizeof(size_t)` before). This was done to allow `qc_realloc` and `qc_crealloc` functions to copy data immediately (plain `realloc` function doesn't copy data, just allocates bigger buffer if necessary). Neither `qc_dealloc` nor `qc_TYPE_dealloc` nor `qc_TYPE_release` shall set qc_errno variable. 4. Old null-terminated char and wchar_t strings shall be deprecated where it is possible. I'd rather avoid them at all, since: 1) character may have sign which seems to be absurd to me, at least on modern systems; 2) wchar_t may have different size and doesn't imply neither UCS-4 nor UCS-2 nor UTF-16. I see two solutions: A). Since it may be more habitual for some programmers and APIs to work with null-terminated char strings, I've decided to leave some functions for it, such as strcmp, stricmp, strlen, strdup, strchr, strrchr. There is convention to distinct between different char types, so strcmp comes in four flavours: qc_strcmp, qc_wstrcmp, qc_mbstrcmp, qc_ucstrcmp, where the first works with char, the second with wchar_t and the last two work with qc_byte and qc_ucs respectively. B). The only places where they may be actually in use are qc_TYPE_import functions, where qc library implies that all data given is either ASCII-encoded character sequence or properly formed Unicode. Strings in qc library are only qc_bytes and qc_unicode. I'd like to discuss this question too. I know that it may be convenient to use old null-style strings; however, I rather think that it is the first common mistake in string handling (the second is to use UTF-16 in APIs extensively as it do Microsoft and a lot of libraries and languages like ICU, Java, Python (until Py3K), etc.). See e.g. this discussion: http://stackoverflow.com/questions/4418708/whats-the-rationale-for-null-terminated-strings. To me it seems better to avoid null-terminated strings at all. No, seriously. This is what I wanted to write about some general thoughts about the future of the library. What do you think about it? If some of you thinks about this as mentor may think about project, I'd probably want to formulate my proposal in some wiki or something similar where it is easier to edit and review. It may be difficult to look though letters sometimes. Thank you for your attention, and I'm looking forward to your letters. -- With best regards, Dmitry Selyutin