From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id E52AD7030F; Fri, 22 Jan 2021 16:21:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E52AD7030F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1611321703; bh=2m54a7vK0ol1N/MgXJJyoHiAroK8OiuwQyb1DGdixY8=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=EFvNbZnV5naR1P+W0KD+M15KG9P29t+8bbzzUOXc+AnZgpdR1ncuNDzv3AIrW+JZs bPk715byYqwJyAUgVGLZg7Ef8bs30KuVt+diPnP9Rg7pRLKi9tOYIx9JES2S1eCkZd zOc+Y9emTlq749TAu/s35fc0vjw4LyM/BeKNpxYU= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id ACF217030F for ; Fri, 22 Jan 2021 16:21:41 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org ACF217030F Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1l2wNg-0000LA-Rz; Fri, 22 Jan 2021 16:21:41 +0300 To: v.shpilevoy@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Fri, 22 Jan 2021 16:21:40 +0300 Message-Id: <686c0812f3c05ff15fb077735146bd256005ab38.1611321574.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD950F8E4A8A2CDB1CD3FBD06983BDAB376D3253FEA0A98384C182A05F53808504009D5C01C846C7928BCAF2D457774D39F2E4F663DF8FCD25288AE119CE521ECBA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE71BF69A9C8C5AF260EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377F497DA9C8A5F4D48638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC0FABBF4F5C6A453F5AD11EFB41D5A00BBB3B63D2C33FFC29389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B68424CA1AAF98A6958941B15DA834481F9449624AB7ADAF3735872C767BF85DA29E625A9149C048EE0A3850AC1BE2E7351CE60B8040019C364AD6D5ED66289B524E70A05D1297E1BB35872C767BF85DA227C277FBC8AE2E8B38B2F2E9F2BEE38D75ECD9A6C639B01B4E70A05D1297E1BBC6867C52282FAC85D9B7C4F32B44FF57D4B828FA1BC0F1ACBD9CCCA9EDD067B1EDA766A37F9254B7 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C2549B6A8B600A67A38DBD2FDC7DD0D469D3418A311C1FCF19C2B6934AE262D3EE7EAB7254005DCEDCCF148B411F834B11E0A4E2319210D9B64D260DF9561598F01A9E91200F654B0BDBC62CB1440F3B18E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3473457D764E1CDE77F780CDA0F741B620B0DFF67BBCD12FDCDE2B9A481E18CCA18798D5296F00F57B1D7E09C32AA3244C2F55734AD241BC332D0904AD86A487868580396430872480729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojWIZ7ZfNFVxAL5BVN4RznyQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822436DC68612D9B80C8E48EB2FD745861983D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v1 1/1] sql: remove unused serialization functions X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mergen Imeev via Tarantool-patches Reply-To: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" This patch removes serialization functions that are not used in Tarantool. Part of #4470 --- https://github.com/tarantool/tarantool/issues/4470 https://github.com/tarantool/tarantool/tree/imeevma/gh-4470-remove-unused-serialization-functions src/box/sql/vdbe.c | 5 +- src/box/sql/vdbeInt.h | 4 - src/box/sql/vdbeaux.c | 407 ------------------------------------------ 3 files changed, 2 insertions(+), 414 deletions(-) diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 1707c216e..3b3b1f01d 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -2922,9 +2922,8 @@ case OP_MakeRecord: { * and so forth. * * Each type field is a varint representing the serial type of the - * corresponding data element (see sqlVdbeSerialType()). The - * hdr-size field is also a varint which is the offset from the beginning - * of the record to data0. + * corresponding data element. The hdr-size field is also a varint which + * is the offset from the beginning of the record to data0. */ nField = pOp->p1; enum field_type *types = pOp->p4.types; diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h index ad46ab129..7205f1af3 100644 --- a/src/box/sql/vdbeInt.h +++ b/src/box/sql/vdbeInt.h @@ -472,10 +472,6 @@ int sqlVdbeCursorRestore(VdbeCursor *); #if defined(SQL_DEBUG) || defined(VDBE_PROFILE) void sqlVdbePrintOp(FILE *, int, Op *); #endif -u32 sqlVdbeSerialTypeLen(u32); -u32 sqlVdbeSerialType(Mem *, int, u32 *); -u32 sqlVdbeSerialPut(unsigned char *, Mem *, u32); -u32 sqlVdbeSerialGet(const unsigned char *, u32, Mem *); int sqlVdbeExec(Vdbe *); int sqlVdbeList(Vdbe *); diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index bae1a5352..91b64316e 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -2303,413 +2303,6 @@ sqlVdbeDelete(Vdbe * p) sqlDbFree(db, p); } -/* - * The following functions: - * - * sqlVdbeSerialType() - * sqlVdbeSerialTypeLen() - * sqlVdbeSerialLen() - * sqlVdbeSerialPut() - * sqlVdbeSerialGet() - * - * encapsulate the code that serializes values for storage in sql - * data and index records. Each serialized value consists of a - * 'serial-type' and a blob of data. The serial type is an 8-byte unsigned - * integer, stored as a varint. - * - * In an sql index record, the serial type is stored directly before - * the blob of data that it corresponds to. In a table record, all serial - * types are stored at the start of the record, and the blobs of data at - * the end. Hence these functions allow the caller to handle the - * serial-type and data blob separately. - * - * The following table describes the various storage classes for data: - * - * serial type bytes of data type - * -------------- --------------- --------------- - * 0 0 NULL - * 1 1 signed integer - * 2 2 signed integer - * 3 3 signed integer - * 4 4 signed integer - * 5 6 signed integer - * 6 8 signed integer - * 7 8 IEEE float - * 8 0 Integer constant 0 - * 9 0 Integer constant 1 - * 10,11 reserved for expansion - * N>=12 and even (N-12)/2 BLOB - * N>=13 and odd (N-13)/2 text - * - * The 8 and 9 types were added in 3.3.0, file format 4. Prior versions - * of sql will not understand those serial types. - */ - -/* - * Return the serial-type for the value stored in pMem. - */ -u32 -sqlVdbeSerialType(Mem * pMem, int file_format, u32 * pLen) -{ - int flags = pMem->flags; - u32 n; - - assert(pLen != 0); - if (flags & MEM_Null) { - *pLen = 0; - return 0; - } - if (flags & MEM_Int) { - /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */ -#define MAX_6BYTE ((((i64)0x00008000)<<32)-1) - i64 i = pMem->u.i; - u64 u; - if (i < 0) { - u = ~i; - } else { - u = i; - } - if (u <= 127) { - if ((i & 1) == i && file_format >= 4) { - *pLen = 0; - return 8 + (u32) u; - } else { - *pLen = 1; - return 1; - } - } - if (u <= 32767) { - *pLen = 2; - return 2; - } - if (u <= 8388607) { - *pLen = 3; - return 3; - } - if (u <= 2147483647) { - *pLen = 4; - return 4; - } - if (u <= MAX_6BYTE) { - *pLen = 6; - return 5; - } - *pLen = 8; - return 6; - } - if (flags & MEM_Real) { - *pLen = 8; - return 7; - } - assert(pMem->db->mallocFailed || flags & (MEM_Str | MEM_Blob)); - assert(pMem->n >= 0); - n = (u32) pMem->n; - if (flags & MEM_Zero) { - n += pMem->u.nZero; - } - *pLen = n; - return ((n * 2) + 12 + ((flags & MEM_Str) != 0)); -} - -/* - * The sizes for serial types less than 128 - */ -static const u8 sqlSmallTypeSizes[] = { - /* 0 1 2 3 4 5 6 7 8 9 */ -/* 0 */ 0, 1, 2, 3, 4, 6, 8, 8, 0, 0, -/* 10 */ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, -/* 20 */ 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, -/* 30 */ 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, -/* 40 */ 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, -/* 50 */ 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, -/* 60 */ 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, -/* 70 */ 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, -/* 80 */ 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, -/* 90 */ 39, 39, 40, 40, 41, 41, 42, 42, 43, 43, -/* 100 */ 44, 44, 45, 45, 46, 46, 47, 47, 48, 48, -/* 110 */ 49, 49, 50, 50, 51, 51, 52, 52, 53, 53, -/* 120 */ 54, 54, 55, 55, 56, 56, 57, 57 -}; - -/* - * Return the length of the data corresponding to the supplied serial-type. - */ -u32 -sqlVdbeSerialTypeLen(u32 serial_type) -{ - if (serial_type >= 128) { - return (serial_type - 12) / 2; - } else { - assert(serial_type < 12 - || sqlSmallTypeSizes[serial_type] == - (serial_type - 12) / 2); - return sqlSmallTypeSizes[serial_type]; - } -} - -/* - * If we are on an architecture with mixed-endian floating - * points (ex: ARM7) then swap the lower 4 bytes with the - * upper 4 bytes. Return the result. - * - * For most architectures, this is a no-op. - * - * (later): It is reported to me that the mixed-endian problem - * on ARM7 is an issue with GCC, not with the ARM7 chip. It seems - * that early versions of GCC stored the two words of a 64-bit - * float in the wrong order. And that error has been propagated - * ever since. The blame is not necessarily with GCC, though. - * GCC might have just copying the problem from a prior compiler. - * I am also told that newer versions of GCC that follow a different - * ABI get the byte order right. - * - * Developers using sql on an ARM7 should compile and run their - * application using -DSQL_DEBUG=1 at least once. With DEBUG - * enabled, some asserts below will ensure that the byte order of - * floating point values is correct. - * - * (2007-08-30) Frank van Vugt has studied this problem closely - * and has send his findings to the sql developers. Frank - * writes that some Linux kernels offer floating point hardware - * emulation that uses only 32-bit mantissas instead of a full - * 48-bits as required by the IEEE standard. (This is the - * CONFIG_FPE_FASTFPE option.) On such systems, floating point - * byte swapping becomes very complicated. To avoid problems, - * the necessary byte swapping is carried out using a 64-bit integer - * rather than a 64-bit float. Frank assures us that the code here - * works for him. We, the developers, have no way to independently - * verify this, but Frank seems to know what he is talking about - * so we trust him. - */ -#ifdef SQL_MIXED_ENDIAN_64BIT_FLOAT -static u64 -floatSwap(u64 in) -{ - union { - u64 r; - u32 i[2]; - } u; - u32 t; - - u.r = in; - t = u.i[0]; - u.i[0] = u.i[1]; - u.i[1] = t; - return u.r; -} - -#define swapMixedEndianFloat(X) X = floatSwap(X) -#else -#define swapMixedEndianFloat(X) -#endif - -/* - * Write the serialized data blob for the value stored in pMem into - * buf. It is assumed that the caller has allocated sufficient space. - * Return the number of bytes written. - * - * nBuf is the amount of space left in buf[]. The caller is responsible - * for allocating enough space to buf[] to hold the entire field, exclusive - * of the pMem->u.nZero bytes for a MEM_Zero value. - * - * Return the number of bytes actually written into buf[]. The number - * of bytes in the zero-filled tail is included in the return value only - * if those bytes were zeroed in buf[]. - */ -u32 -sqlVdbeSerialPut(u8 * buf, Mem * pMem, u32 serial_type) -{ - u32 len; - - /* Integer and Real */ - if (serial_type <= 7 && serial_type > 0) { - u64 v; - u32 i; - if (serial_type == 7) { - assert(sizeof(v) == sizeof(pMem->u.r)); - memcpy(&v, &pMem->u.r, sizeof(v)); - swapMixedEndianFloat(v); - } else { - v = pMem->u.i; - } - len = i = sqlSmallTypeSizes[serial_type]; - assert(i > 0); - do { - buf[--i] = (u8) (v & 0xFF); - v >>= 8; - } while (i); - return len; - } - - /* String or blob */ - if (serial_type >= 12) { - assert(pMem->n + ((pMem->flags & MEM_Zero) ? pMem->u.nZero : 0) - == (int)sqlVdbeSerialTypeLen(serial_type)); - len = pMem->n; - if (len > 0) - memcpy(buf, pMem->z, len); - return len; - } - - /* NULL or constants 0 or 1 */ - return 0; -} - -/* Input "x" is a sequence of unsigned characters that represent a - * big-endian integer. Return the equivalent native integer - */ -#define ONE_BYTE_INT(x) ((i8)(x)[0]) -#define TWO_BYTE_INT(x) (256*(i8)((x)[0])|(x)[1]) -#define THREE_BYTE_INT(x) (65536*(i8)((x)[0])|((x)[1]<<8)|(x)[2]) -#define FOUR_BYTE_UINT(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) -#define FOUR_BYTE_INT(x) (16777216*(i8)((x)[0])|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) - -/* - * Deserialize the data blob pointed to by buf as serial type serial_type - * and store the result in pMem. Return the number of bytes read. - * - * This function is implemented as two separate routines for performance. - * The few cases that require local variables are broken out into a separate - * routine so that in most cases the overhead of moving the stack pointer - * is avoided. - */ -static u32 SQL_NOINLINE -serialGet(const unsigned char *buf, /* Buffer to deserialize from */ - u32 serial_type, /* Serial type to deserialize */ - Mem * pMem) /* Memory cell to write value into */ -{ - u64 x = FOUR_BYTE_UINT(buf); - u32 y = FOUR_BYTE_UINT(buf + 4); - x = (x << 32) + y; - if (serial_type == 6) { - /* EVIDENCE-OF: R-29851-52272 Value is a big-endian 64-bit - * twos-complement integer. - */ - pMem->u.i = *(i64 *) & x; - pMem->flags = MEM_Int; - testcase(pMem->u.i < 0); - } else { - /* EVIDENCE-OF: R-57343-49114 Value is a big-endian IEEE 754-2008 64-bit - * floating point number. - */ -#if !defined(NDEBUG) - /* Verify that integers and floating point values use the same - * byte order. Or, that if SQL_MIXED_ENDIAN_64BIT_FLOAT is - * defined that 64-bit floating point values really are mixed - * endian. - */ - static const u64 t1 = ((u64) 0x3ff00000) << 32; - static const double r1 = 1.0; - u64 t2 = t1; - swapMixedEndianFloat(t2); - assert(sizeof(r1) == sizeof(t2) - && memcmp(&r1, &t2, sizeof(r1)) == 0); -#endif - assert(sizeof(x) == 8 && sizeof(pMem->u.r) == 8); - swapMixedEndianFloat(x); - memcpy(&pMem->u.r, &x, sizeof(x)); - pMem->flags = sqlIsNaN(pMem->u.r) ? MEM_Null : MEM_Real; - } - return 8; -} - -u32 -sqlVdbeSerialGet(const unsigned char *buf, /* Buffer to deserialize from */ - u32 serial_type, /* Serial type to deserialize */ - Mem * pMem) /* Memory cell to write value into */ -{ - switch (serial_type) { - case 10: /* Reserved for future use */ - case 11: /* Reserved for future use */ - case 0:{ /* Null */ - /* EVIDENCE-OF: R-24078-09375 Value is a NULL. */ - pMem->flags = MEM_Null; - break; - } - case 1:{ - /* EVIDENCE-OF: R-44885-25196 Value is an 8-bit twos-complement - * integer. - */ - pMem->u.i = ONE_BYTE_INT(buf); - pMem->flags = MEM_Int; - testcase(pMem->u.i < 0); - return 1; - } - case 2:{ /* 2-byte signed integer */ - /* EVIDENCE-OF: R-49794-35026 Value is a big-endian 16-bit - * twos-complement integer. - */ - pMem->u.i = TWO_BYTE_INT(buf); - pMem->flags = MEM_Int; - testcase(pMem->u.i < 0); - return 2; - } - case 3:{ /* 3-byte signed integer */ - /* EVIDENCE-OF: R-37839-54301 Value is a big-endian 24-bit - * twos-complement integer. - */ - pMem->u.i = THREE_BYTE_INT(buf); - pMem->flags = MEM_Int; - testcase(pMem->u.i < 0); - return 3; - } - case 4:{ /* 4-byte signed integer */ - /* EVIDENCE-OF: R-01849-26079 Value is a big-endian 32-bit - * twos-complement integer. - */ - pMem->u.i = FOUR_BYTE_INT(buf); -#ifdef __HP_cc - /* Work around a sign-extension bug in the HP compiler for HP/UX */ - if (buf[0] & 0x80) - pMem->u.i |= 0xffffffff80000000LL; -#endif - pMem->flags = MEM_Int; - testcase(pMem->u.i < 0); - return 4; - } - case 5:{ /* 6-byte signed integer */ - /* EVIDENCE-OF: R-50385-09674 Value is a big-endian 48-bit - * twos-complement integer. - */ - pMem->u.i = - FOUR_BYTE_UINT(buf + 2) + - (((i64) 1) << 32) * TWO_BYTE_INT(buf); - pMem->flags = MEM_Int; - testcase(pMem->u.i < 0); - return 6; - } - case 6: /* 8-byte signed integer */ - case 7:{ /* IEEE floating point */ - /* These use local variables, so do them in a separate routine - * to avoid having to move the frame pointer in the common case - */ - return serialGet(buf, serial_type, pMem); - } - case 8: /* Integer 0 */ - case 9:{ /* Integer 1 */ - /* EVIDENCE-OF: R-12976-22893 Value is the integer 0. */ - /* EVIDENCE-OF: R-18143-12121 Value is the integer 1. */ - pMem->u.i = serial_type - 8; - pMem->flags = MEM_Int; - return 0; - } - default:{ - /* EVIDENCE-OF: R-14606-31564 Value is a BLOB that is (N-12)/2 bytes in - * length. - * EVIDENCE-OF: R-28401-00140 Value is a string in the text encoding and - * (N-13)/2 bytes in length. - */ - static const u16 aFlag[] = - { MEM_Blob | MEM_Ephem, MEM_Str | MEM_Ephem }; - pMem->z = (char *)buf; - pMem->n = (serial_type - 12) / 2; - pMem->flags = aFlag[serial_type & 1]; - return pMem->n; - } - } - return 0; -} - /* * This routine is used to allocate sufficient space for an UnpackedRecord * structure large enough to be used with sqlVdbeRecordUnpack() if -- 2.25.1