File: rvalue_fix_example.patch

package info (click to toggle)
mysql%2B%2B 3.2.5-2.1
  • links: PTS
  • area: main
  • in suites:
  • size: 18,360 kB
  • sloc: cpp: 35,788; sh: 3,693; perl: 789; makefile: 730
file content (57 lines) | stat: -rw-r--r-- 2,495 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From df890798c8017dee79d5e4ee0867e2dae44ca5b5 Mon Sep 17 00:00:00 2001
From: tangent <mysqlpp@tangentsoft.com>
Date: Sat, 19 Sep 2020 17:24:45 +0000
Subject: [PATCH] Exchanged the "file slurp" idiom used in
 examples/load_jpeg.cpp for one that also works in C++11, which complains of
 "address to rvalue" with the original formulation.

FossilOrigin-Name: b062e656cc2ed9356c6f757837580a2145251c5294e382f8e2c1ad3e74a91cdd
---
 examples/load_jpeg.cpp | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

--- a/examples/load_jpeg.cpp
+++ b/examples/load_jpeg.cpp
@@ -2,9 +2,9 @@
  load_jpeg.cpp - Example showing how to insert BLOB data into the
 	database from a file.
 
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2009 by Educational Technology Resources, Inc.  Others may
- also hold copyrights on code in this file.  See the CREDITS.txt file
+ Copyright © 1998 by Kevin Atkinson, © 1999-2001 by MySQL AB, and
+ © 2004-2009 by Educational Technology Resources, Inc.  Others may
+ also hold copyrights on code in this file.  See the CREDITS.md file
  in the top directory of the distribution for details.
 
  This file is part of MySQL++.
@@ -80,14 +80,16 @@
 	img_name = cmdline.extra_args()[0];
 	ifstream img_file(img_name.c_str(), ios::binary);
 	if (img_file) {
-		// Slurp file contents into RAM with minimum copying.  (Idiom
-		// explained here: http://stackoverflow.com/questions/116038/)
+		// Slurp file contents into RAM with only a single copy, per
+		// https://stackoverflow.com/a/116220  It also explains why
+        // there is no concise zero-copy option here.
 		//
 		// By loading the file into a C++ string (stringstream::str())
 		// and assigning that directly to a mysqlpp::sql_blob, we avoid
 		// truncating the binary data at the first null character.
-		img.data.data = static_cast<const stringstream*>(
-				&(stringstream() << img_file.rdbuf()))->str();
+        stringstream ss;
+        ss << img_file.rdbuf();
+		img.data.data = ss.str();
 
 		// Check JPEG data for sanity.
 		const char* error;
@@ -130,7 +132,7 @@
 			// as C strings, thus causing null-truncation.  The fact
 			// that we're using SSQLS here is a side issue, simply
 			// demonstrating that mysqlpp::Null<mysqlpp::sql_blob> is
-			// now legal in SSQLS, as of MySQL++ 3.0.7.
+            // now legal in SSQLS, as of MySQL++ 3.0.7.
 			Query query = con.query();
 			query.insert(img);
 			SimpleResult res = query.execute();