Cut, Paste and Crash 剪切、粘贴和崩溃

作者: 安迪·赫茨菲尔德 日期: 1983年9月 人物: 拉里·凯尼恩、苏珊·凯尔、安迪·赫茨菲尔德 主题: 技术、软件设计、错误 概要: 关于苹果第一代Macintosh的开发以及制造它的人的轶事: ROM 冻结后不久我们发现了一个特别严重的错误 , 剪切、粘贴和崩溃 Cut, Paste and Crash

One of the last things to be finished on the Macintosh computer system was the part that helps you copy and paste things between different programs. This part of the system is called the “clipboard manager”. It gives other programs simple ways to use and change the “clipboard”, which is a special piece of memory that stores the last thing you copied or cut. The tricky part of the clipboard manager was how it handled memory when you closed a program.

Macintosh 计算机系统上最后完成的事情之一是帮助您在不同程序之间复制和粘贴内容的部分。系统的这一部分称为“剪贴板管理器”。它为其他程序提供了使用和更改“剪贴板”的简单方法,“剪贴板”是一块特殊的内存,用于存储您最后复制或剪切的内容。
剪贴板管理器的棘手部分是当您关闭程序时它如何处理内存。

The clipboard remembers what was copied and pasted. It usually stays in the same place in the computer’s memory (like a notebook) where the application that did the copying or pasting can use it. But when an application ends, its notebook is cleared, and a new notebook is prepared for the next application to use. The clipboard needs special help to remember what was copied and pasted during this short time when there is no notebook to put it in.

剪贴板会记住复制和粘贴的内容。它通常保留在计算机内存中的同一位置(如笔记本),进行复制或粘贴的应用程序可以使用它。但是当一个应用程序结束时,它的笔记本会被清除,并准备一个新的笔记本供下一个应用程序使用。当没有笔记本可以放入时,剪贴板需要特殊的帮助来记住在这么短的时间内复制和粘贴的内容。

Initially, we thought of saving the clipboard to a disk while switching between applications. This worked, but it was tricky because the old Mac computers didn’t have a permanent disk, so there might not be a floppy disk in the drive, or it might be write-protected. We also tried copying the clipboard to the system’s memory, where it would stay between applications. However, the clipboard was often too large to fit in this memory space. In the end, we found a better solution. We copied the clipboard to a section of memory called the stack, where it would stay until the new application was launched. The stack is a big area of memory that holds important information like where the application should return to after doing something.

最初,我们考虑在应用程序之间切换时将剪贴板保存到磁盘。这可行,但很棘手,因为旧的 Mac 电脑没有永久磁盘,因此驱动器中可能没有软盘,或者可能被写保护。
我们还尝试将剪贴板复制到系统内存中,以便在应用程序之间保留该内存。然而,剪贴板通常太大,无法容纳该内存空间。
最终,我们找到了更好的解决方案。我们将剪贴板复制到称为堆栈的内存部分,它将一直保留在那里,直到新应用程序启动为止。堆栈是一个很大的内存区域,它保存重要信息,例如应用程序在执行某些操作后应返回到的位置。

A few weeks after the Macintosh computer was finished, Apple showed its sales team a presentation to teach them about the machine. The purpose was to prepare them to start selling it a few months later. The presentation had the usual sales talk, but the most exciting part was when each salesperson got to try out a Macintosh for the first time. A teacher helped them learn to use the mouse and then try three main programs: MacWrite (for writing), MacPaint (for drawing), and Finder (for organizing files).

Macintosh 电脑完成几周后,苹果公司向其销售团队展示了一个演示文稿,向他们介绍该机器。目的是让他们为几个月后开始销售做好准备。演示中进行了常见的销售谈话,但最令人兴奋的部分是每个销售人员第一次尝试 Macintosh 时。老师帮助他们学习使用鼠标,然后尝试三个主要程序:MacWrite(用于书写)、MacPaint(用于绘图)和 Finder(用于组织文件)。

The most exciting part of the demo was when they opened a document made with MacPaint, chose a part of it, and copied it to the computer’s memory. Then, they opened MacWrite and pasted the image into a new document, combining text and pictures. This was very impressive at the time. Susan Kare created a detailed picture of a sneaker for the Macintosh brochure, which was used in the demo. The idea was to copy the sneaker picture from MacPaint and then paste it into MacWrite.

演示中最令人兴奋的部分是当他们打开用 MacPaint 制作的文档,选择其中的一部分,并将其复制到计算机内存中时。然后,他们打开 MacWrite 并将图像粘贴到新文档中,合并文本和图片。这在当时是非常令人印象深刻的。 Susan Kare 为 Macintosh 宣传册制作了一张运动鞋的详细图片,并在演示中使用。我们的想法是从 MacPaint 复制运动鞋图片,然后将其粘贴到 MacWrite 中。

I was asked to attend a sales meeting, but I couldn’t go because I was too busy working with my team to finish a software project on time. We needed to ship it in January and it was already a lot of work. I was busy in the afternoon when one of the sales team members called me in a hurry, worried about the meeting.

我被要求参加一个销售会议,但我没能去,因为我太忙于与团队合作,无法按时完成软件项目。我们需要在一月份发货,这已经是一项繁重的工作了。下午我正忙着,一位销售团队成员急忙打电话给我,担心会议的事。

“There’s a big issue!” he said to me. “The sneaker demo is having trouble. It doesn’t always work. Sometimes it does, and sometimes it doesn’t. We can’t know when it will work or not. But when it doesn’t work, it gets really bad. When you stop using MacPaint, the screen gets all mixed up and then the computer restarts itself. We can’t keep doing the part of the demo where we copy and paste until you can fix the problem soon.”

“有大问题了!”他对我说。 “运动鞋演示遇到了麻烦。它并不总是有效。有时有效,有时无效。我们不知道它何时有效。但当它不起作用时,情况就会变得非常糟糕当您停止使用 MacPaint 时,屏幕会变得混乱,然后计算机会自行重新启动,除非您能尽快解决问题,否则我们无法继续进行复制和粘贴的演示部分。”

I had been talking on the phone and explaining a problem when I suddenly stopped talking. I had an idea about what was causing the problem. I had been working with a program that manages the things you copy to the clipboard. When the program stops running, it takes what is on the clipboard and moves it to a special memory area called the stack. The program subtracts the size of the clipboard from a special pointer to the stack, then moves the information to its new location. I realized that sometimes the size of the clipboard would be an odd number, which would set the stack pointer to an odd number. This was bad because the computer’s processor could not read memory from an odd address. It would get confused and make an error. The stack is used by the processor to handle errors, so an odd stack pointer would cause the processor to get confused and crash. This would happen about half of the time because the size of the clipboard is often even, but it would happen in the other half of the time.

我一直在打电话并解释一个问题,突然就不说话了。我知道是什么导致了这个问题。我一直在使用一个程序来管理复制到剪贴板的内容。当程序停止运行时,它会取出剪贴板上的内容并将其移动到称为堆栈的特殊内存区域。程序从指向堆栈的特殊指针中减去剪贴板的大小,然后将信息移动到新位置。我意识到有时剪贴板的大小会是奇数,这会将堆栈指针设置为奇数。这很糟糕,因为计算机的处理器无法从奇数地址读取内存。它会感到困惑并出错。处理器使用堆栈来处理错误,因此奇怪的堆栈指针会导致处理器混乱并崩溃。大约一半的时间会发生这种情况,因为剪贴板的大小通常是偶数,但另一半的时间也会发生这种情况。

After I understood what was wrong, fixing it was easy. I just needed to make the clipboard size a whole number. But the problem was in a part of the computer that cannot be changed, called ROM. This was the first big mistake we knew of in ROM, and we wondered if we would have to make a new version. However, Larry had a clever way to fix ROM problems. He found a way to patch system traps. This means we can stop the system from crashing and add code to fix the problem. I used Larry’s idea to make a fix for the stack problem, and then he helped me add it to the System file so it would work when the computer started up.

当我明白出了什么问题后,修复它就很容易了。我只需要将剪贴板大小设为整数即可。但问题出在计算机中无法更改的部分,称为 ROM。这是我们所知道的 ROM 中的第一个重大错误,我们想知道是否必须制作一个新版本。然而,Larry 有一个聪明的方法来解决 ROM 问题。他找到了一种修补系统陷阱的方法。这意味着我们可以阻止系统崩溃并添加代码来解决问题。我利用 Larry 的想法修复了堆栈问题,然后他帮我将其添加到系统文件中,以便在计算机启动时它可以工作。

We put a floppy disk with an updated file on it in a package and sent it to a sales meeting with a sales manager who was going to leave the next day. But it took some time for everyone to get the updated file, so for a few weeks, I had to be careful every time I saw someone copying data between programs.

我们将一张装有更新文件的软盘放在一个包裹中,并将其发送给第二天要离开的销售经理参加的销售会议。但每个人都需要一些时间才能获得更新的文件,因此几周以来,每次看到有人在程序之间复制数据时我都必须小心。
目录