Mayor Martin J. Walsh signed two ordinances Friday that will impact the city’s residency requirement for municipal employees and establish a half-mile buffer zone between marijuana dispensaries, according to his staff.

Walsh has said the amendments to the residency law will significantly strengthen the requirement that city employees live in Boston. For years the law has been openly flouted, unevenly applied, and weakly enforced.

The buffer zone between marijuana dispensaries is intended to protect neighborhoods from being overrun with pot shops, in the event voters approve a likely November ballot initiative that would legalize recreational use of marijuana.

City Councilor Michael F. Flaherty Jr. has said he introduced the buffer zone last year, after hearing from residents and local business owners who were nervous about the prospect of recreational marijuana use. He said he studied the experiences of cities and states that enacted buffer zones after legalizing recreational marijuana use, and found those governments were playing “catch up” because they didn’t act in advance.

“I don’t want to have another Combat Zone. I don’t want to have a pot zone, a marijuana zone,” Flaherty said earlier this month. “I don’t think one neighborhood should bear the burden of all of that.”

For the residency ordinance, Walsh adopted the recommendations of a City Council-led commission to force all new top municipal officials to live in Boston regardless of how long they have worked for the city. The changes will also create a waiver system for difficult-to-fill positions that demand special skills, increase penalties for scofflaws, and add more investigators for stepped-up enforcement.

The proposal, which was approved by the City Council, also includes a substantial caveat: A number of Walsh’s hires who live in the suburbs would be exempt because of a grandfather clause. Current city law compels officials to live in Boston, but the requirement has been selectively ignored by Walsh and the administration of his predecessor, Thomas M. Menino.

One section of the proposal would create an exemption for a single employee: Milton resident Michael Dennehy, the commissioner of public works who for two years remained an interim department head.

Another provision would have a significant impact on the Boston Police Department. Much of the police leadership lives in the suburbs and would be exempt, including the second-in-command, Superintendent-in-Chief William G. Gross of Milton. All future appointees to the command staff, however, would be required to move to Boston.

At a January press conference, Walsh said he was “grandfathering in a whole host of city employees” because it would be “too complicated” to force them to move to the city. Walsh said he would not jeopardize public safety by removing half of the Police Department’s top brass because of the residency rule.

The mayor was adamant the proposal would strengthen a residency policy that had been in disarray. Almost all of the city’s collective bargaining contracts allow union members to move out of the city after 10 years of service. For the first time it would be clear, Walsh said, that longtime employees will be required to move back to Boston to serve as department heads or Cabinet chiefs.