From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: struct-copy func Date: Fri, 17 Aug 2007 10:46:06 +1000 Message-ID: <87d4xnf0oh.fsf@zip.com.au> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1187311666 28581 80.91.229.12 (17 Aug 2007 00:47:46 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 17 Aug 2007 00:47:46 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Aug 17 02:47:43 2007 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1ILq06-0002MR-QB for guile-devel@m.gmane.org; Fri, 17 Aug 2007 02:47:43 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ILq06-00084m-46 for guile-devel@m.gmane.org; Thu, 16 Aug 2007 20:47:42 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ILpzV-0007vA-9C for guile-devel@gnu.org; Thu, 16 Aug 2007 20:47:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ILpzT-0007ur-Ug for guile-devel@gnu.org; Thu, 16 Aug 2007 20:47:04 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ILpzT-0007ue-P2 for guile-devel@gnu.org; Thu, 16 Aug 2007 20:47:03 -0400 Original-Received: from mailout2-7.pacific.net.au ([61.8.2.230] helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1ILpzT-0007NA-8m for guile-devel@gnu.org; Thu, 16 Aug 2007 20:47:03 -0400 Original-Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.2.162]) by mailout2.pacific.net.au (Postfix) with ESMTP id ED20AC06A2 for ; Fri, 17 Aug 2007 10:46:45 +1000 (EST) Original-Received: from localhost (ppp2FC8.dyn.pacific.net.au [61.8.47.200]) by mailproxy1.pacific.net.au (Postfix) with ESMTP id 2E1FC8C15 for ; Fri, 17 Aug 2007 10:46:51 +1000 (EST) Original-Received: from gg by localhost with local (Exim 4.67) (envelope-from ) id 1ILpyY-0001Ja-BR for guile-devel@gnu.org; Fri, 17 Aug 2007 10:46:06 +1000 User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux) X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6700 Archived-At: This is an idea I had for copying structures, mainly to make a `record-copy' function (just an alias of struct-copy). I've found it pretty useful. You can do a record copy with `record-constructor' and a map over `record-accessor' for each field, but of course a block copy is heaps more efficient. SCM_DEFINE_PUBLIC (struct_copy, "struct-copy", 1, 0, 0, (SCM st), "Return a copy of structure @var{st}. This is a shallow copy,\n" "there's no recursive copying of the objects in the fields.") #define FUNC_NAME s_struct_copy { scm_t_bits *vtable_data, *st_data, *new_st_data; size_t n_words; SCM_VALIDATE_STRUCT (SCM_ARG1, st); vtable_data = SCM_STRUCT_VTABLE_DATA (st); /* Only standard structs handled here, not goops entity or light forms. Believe that's enough for ordinary public uses of structures as created from `make-struct', `make-vtable', `make-vtable-vtable'. */ if (vtable_data[scm_struct_i_flags] & (SCM_STRUCTF_ENTITY | SCM_STRUCTF_LIGHT)) SCM_WRONG_TYPE_ARG (SCM_ARG1, st); st_data = SCM_STRUCT_DATA (st); n_words = st_data[scm_struct_i_n_words]; new_st_data = scm_alloc_struct (n_words, scm_struct_n_extra_words, "struct"); memcpy (new_st_data, st_data, n_words * sizeof(scm_t_bits)); scm_remember_upto_here_1 (st); return scm_double_cell ((scm_t_bits) vtable_data + scm_tc3_struct, (scm_t_bits) new_st_data, 0, 0); } #undef FUNC_NAME _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel